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

lib/arjdbc/jdbc/adapter.rb

Lines changed: 0 additions & 1 deletion
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'

lib/arjdbc/jdbc/base_ext.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/arjdbc/mysql/adapter.rb

Lines changed: 1 addition & 10 deletions
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

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 6 additions & 3 deletions
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:

src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java

Lines changed: 12 additions & 2 deletions
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"))));

test/db/mysql/statement_escaping_test.rb

Lines changed: 3 additions & 3 deletions
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
Lines changed: 1 addition & 1 deletion
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?
Lines changed: 1 addition & 1 deletion
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
Lines changed: 1 addition & 1 deletion
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

test/rails/excludes/mysql2/Mysql2ConnectionTest.rb

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)