Skip to content

Commit f81626b

Browse files
authored
Merge pull request #1168 from JesseChavez/rails_72_fixes_part1
Rails 7.2 fixes mostly SQLite and some for MySQL
2 parents 0944ef9 + 4ee9242 commit f81626b

File tree

12 files changed

+42
-53
lines changed

12 files changed

+42
-53
lines changed

Diff for: lib/arjdbc/jdbc/adapter.rb

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
require 'arjdbc/version'
77
require 'arjdbc/jdbc/java'
8-
require 'arjdbc/jdbc/base_ext'
98
require 'arjdbc/jdbc/error'
109
require 'arjdbc/jdbc/connection_methods'
1110
require 'arjdbc/jdbc/column'

Diff for: lib/arjdbc/jdbc/base_ext.rb

-17
This file was deleted.

Diff for: lib/arjdbc/mysql/adapter.rb

+1-10
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,6 @@ def initialize(...)
8484
@connection_parameters = conn_params
8585
end
8686

87-
def self.database_exists?(config)
88-
conn = ActiveRecord::Base.mysql2_connection(config)
89-
conn && conn.really_valid?
90-
rescue ActiveRecord::NoDatabaseError
91-
false
92-
ensure
93-
conn.disconnect! if conn
94-
end
95-
9687
def supports_json?
9788
!mariadb? && database_version >= '5.7.8'
9889
end
@@ -250,7 +241,7 @@ def configure_connection
250241

251242
# e.g. "5.7.20-0ubuntu0.16.04.1"
252243
def full_version
253-
schema_cache.database_version.full_version_string
244+
database_version.full_version_string
254245
end
255246

256247
def get_full_version

Diff for: lib/arjdbc/sqlite3/adapter.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,12 @@ def jdbc_connection_class
745745
end
746746
end
747747

748+
# NOTE: include these modules before all then override some methods with the
749+
# ones defined in ArJdbc::SQLite3 java part and ArJdbc::Abstract
750+
include ::ActiveRecord::ConnectionAdapters::SQLite3::Quoting
751+
include ::ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements
752+
include ::ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
753+
748754
include ArJdbc::Abstract::Core
749755
include ArJdbc::SQLite3
750756
include ArJdbc::SQLite3Config
@@ -754,9 +760,6 @@ def jdbc_connection_class
754760
include ArJdbc::Abstract::StatementCache
755761
include ArJdbc::Abstract::TransactionSupport
756762

757-
include ::ActiveRecord::ConnectionAdapters::SQLite3::Quoting
758-
include ::ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements
759-
include ::ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
760763

761764
##
762765
# :singleton-method:

Diff for: src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,26 @@ public IRubyObject execute_batch2(ThreadContext context, IRubyObject statementsA
473473
// Assume we will only call this with an array.
474474
final RubyArray statements = (RubyArray) statementsArg;
475475
return withConnection(context, connection -> {
476+
final Ruby runtime = context.runtime;
477+
476478
Statement statement = null;
479+
477480
try {
478481
statement = createStatement(context, connection);
479482

480483
int length = statements.getLength();
481484
for (int i = 0; i < length; i++) {
482485
statement.addBatch(sqlString(statements.eltOk(i)));
483486
}
484-
statement.executeBatch();
485-
return context.nil;
487+
488+
int[] rows = statement.executeBatch();
489+
490+
RubyArray rowsAffected = runtime.newArray();
491+
492+
for (int i = 0; i < rows.length; i++) {
493+
rowsAffected.append(runtime.newFixnum(rows[i]));
494+
}
495+
return rowsAffected;
486496
} catch (final SQLException e) {
487497
// Generate list semicolon list of statements which should match AR error formatting more.
488498
debugErrorSQL(context, sqlString(statements.join(context, context.runtime.newString(";\n"))));

Diff for: test/db/mysql/statement_escaping_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class StatementEscapingTest < Test::Unit::TestCase
66

77
def setup
88
super
9-
ActiveRecord::Base.clear_active_connections!
9+
ActiveRecord::Base.connection_handler.clear_active_connections!
1010
@config = current_connection_config.dup
1111
end
1212

1313
def teardown
14-
ActiveRecord::Base.clear_active_connections!
14+
ActiveRecord::Base.connection_handler.clear_active_connections!
1515
ActiveRecord::Base.establish_connection @config
1616
super
1717
end
@@ -53,4 +53,4 @@ def verify_escaped
5353
assert_equal 'abcxyz', rs.first['title']
5454
end
5555

56-
end
56+
end
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_check_constraints_should_raise_not_implemented, 'test expects newer MySQL version' unless ActiveRecord::Base.connection.supports_check_constraints?
1+
exclude :test_check_constraints_should_raise_not_implemented, 'test expects newer MySQL version' unless ActiveRecord::Base.lease_connection.supports_check_constraints?
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_prepared_statement_status_is_thread_and_instance_specific, 'test expects prepared_statements to be off for mysql' if ActiveRecord::Base.connection.prepared_statements
1+
exclude :test_prepared_statement_status_is_thread_and_instance_specific, 'test expects prepared_statements to be off for mysql' if ActiveRecord::Base.lease_connection.prepared_statements
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_preloading_too_many_ids, "works only with PS, fails in plain AR with MRI too" unless ActiveRecord::Base.connection.prepared_statements
1+
exclude :test_preloading_too_many_ids, "works only with PS, fails in plain AR with MRI too" unless ActiveRecord::Base.lease_connection.prepared_statements

Diff for: test/rails/excludes/mysql2/Mysql2ConnectionTest.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
exclude :test_mysql_connection_collation_is_configured, "Issue #884"
66
exclude :test_wait_timeout_as_url, 'uses URL format unknown to JDBC driver (i.e. "mysql2:///")'
77

8-
if ActiveRecord::Base.connection.jdbc_connection(true).java_class.name.start_with?('org.mariadb.jdbc')
9-
exclude :test_mysql_strict_mode_specified_default, 'MariaDB driver reports more options'
10-
end
8+
# if ActiveRecord::Base.connection.jdbc_connection(true).java_class.name.start_with?('org.mariadb.jdbc')
9+
# exclude :test_mysql_strict_mode_specified_default, 'MariaDB driver reports more options'
10+
# end

Diff for: test/serialize.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def teardown
3636
MyObject = Struct.new :attribute1, :attribute2
3737

3838
def test_serialized_attribute
39-
Topic.serialize("content", MyObject)
39+
Topic.serialize("content", type: MyObject)
4040

4141
myobj = MyObject.new('value1', 'value2')
4242
topic = Topic.create("content" => myobj)
@@ -47,7 +47,7 @@ def test_serialized_attribute
4747
end
4848

4949
def test_serialized_attribute_in_base_class
50-
Topic.serialize("content", Hash)
50+
Topic.serialize("content", type: Hash)
5151

5252
hash = { 'content1' => 'value1', 'content2' => 'value2' }
5353
important_topic = ImportantTopic.create("content" => hash)
@@ -81,7 +81,7 @@ def test_serialized_attribute_in_base_class
8181
# end
8282

8383
def test_serialized_ostruct
84-
Topic.serialize :content, OpenStruct
84+
Topic.serialize(:content, type: OpenStruct)
8585

8686
t = Topic.new
8787
t.content.foo = 'bar'
@@ -142,28 +142,28 @@ def test_nil_not_serialized_with_class_constraint
142142
end
143143

144144
def test_serialized_attribute_should_raise_exception_on_new_with_wrong_type
145-
Topic.serialize(:content, Hash)
145+
Topic.serialize(:content, type: Hash)
146146
assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.new(:content => "string") }
147147
end
148148

149149
def test_should_raise_exception_on_serialized_attribute_with_type_mismatch
150150
myobj = MyObject.new('value1', 'value2')
151151
topic = Topic.new(:content => myobj)
152152
assert topic.save
153-
Topic.serialize(:content, Hash)
153+
Topic.serialize(:content, type: Hash)
154154
assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content }
155155
end
156156

157157
def test_serialized_attribute_with_class_constraint
158158
settings = { "color" => "blue" }
159-
Topic.serialize(:content, Hash)
159+
Topic.serialize(:content, type: Hash)
160160
topic = Topic.new(:content => settings)
161161
assert topic.save
162162
assert_equal(settings, Topic.find(topic.id).content)
163163
end
164164

165165
def test_serialized_default_class
166-
Topic.serialize(:content, Hash)
166+
Topic.serialize(:content, type: Hash)
167167
topic = Topic.new
168168
assert_equal Hash, topic.content.class
169169
assert_equal Hash, topic.read_attribute(:content).class
@@ -206,7 +206,7 @@ def self.load(value)
206206
end
207207
end
208208

209-
Topic.serialize(:content, some_class)
209+
Topic.serialize(:content, coder: some_class)
210210
topic = Topic.new(:content => some_class.new('my value'))
211211
topic.save!
212212
topic.reload
@@ -216,7 +216,7 @@ def self.load(value)
216216

217217
def test_serialize_attribute_via_select_method_when_time_zone_available
218218
ActiveRecord::Base.time_zone_aware_attributes = true
219-
Topic.serialize(:content, MyObject)
219+
Topic.serialize(:content, type: MyObject)
220220

221221
myobj = MyObject.new('value1', 'value2')
222222
topic = Topic.create(:content => myobj)

Diff for: test/test_helper.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def connection
8484
end
8585

8686
def schema_dump
87+
pool = ActiveRecord::Base.connection_pool
8788
strio = StringIO.new
88-
ActiveRecord::SchemaDumper::dump(connection, strio)
89+
ActiveRecord::SchemaDumper.dump(pool, strio)
8990
strio.string
9091
end
9192

@@ -165,7 +166,9 @@ def self.current_connection_config
165166
ActiveRecord::Base.connection.pool.db_config.configuration_hash
166167
end
167168

168-
def current_connection_config; self.class.current_connection_config; end
169+
def current_connection_config
170+
self.class.current_connection_config
171+
end
169172

170173
def deprecation_silence(&block)
171174
ActiveSupport::Deprecation.silence(&block)

0 commit comments

Comments
 (0)