activerecord-jdbc-alt-adapter 70.2.0-java → 71.0.0.alpha1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +135 -21
- data/.github/workflows/ruby.yml +10 -10
- data/.gitignore +1 -0
- data/.solargraph.yml +15 -0
- data/Gemfile +17 -4
- data/README.md +7 -3
- data/RUNNING_TESTS.md +36 -0
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/activerecord-jdbc-alt-adapter.gemspec +1 -1
- data/lib/arjdbc/abstract/connection_management.rb +23 -10
- data/lib/arjdbc/abstract/core.rb +5 -6
- data/lib/arjdbc/abstract/database_statements.rb +35 -25
- data/lib/arjdbc/abstract/statement_cache.rb +1 -6
- data/lib/arjdbc/abstract/transaction_support.rb +37 -9
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +0 -34
- data/lib/arjdbc/jdbc/connection_methods.rb +1 -1
- data/lib/arjdbc/mssql/adapter.rb +93 -80
- data/lib/arjdbc/mssql/column.rb +1 -0
- data/lib/arjdbc/mssql/connection_methods.rb +7 -55
- data/lib/arjdbc/mssql/database_statements.rb +182 -71
- data/lib/arjdbc/mssql/explain_support.rb +8 -5
- data/lib/arjdbc/mssql/schema_creation.rb +1 -1
- data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
- data/lib/arjdbc/mssql/schema_statements.rb +19 -11
- data/lib/arjdbc/mssql/server_version.rb +56 -0
- data/lib/arjdbc/mssql/utils.rb +23 -9
- data/lib/arjdbc/mysql/adapter.rb +64 -22
- data/lib/arjdbc/sqlite3/adapter.rb +218 -135
- data/lib/arjdbc/sqlite3/column.rb +103 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +7 -2
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +9 -5
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/02-test.rake +1 -1
- data/rakelib/rails.rake +2 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -2
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +2 -1
- metadata +9 -12
- data/lib/arel/visitors/sql_server/ng42.rb +0 -294
- data/lib/arel/visitors/sql_server.rb +0 -124
- data/lib/arjdbc/mssql/limit_helpers.rb +0 -231
- data/lib/arjdbc/mssql/lock_methods.rb +0 -77
- data/lib/arjdbc/mssql/old_adapter.rb +0 -804
- data/lib/arjdbc/mssql/old_column.rb +0 -200
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -33,11 +33,19 @@ module ActiveRecord
|
|
33
33
|
|
34
34
|
include ArJdbc::MySQL
|
35
35
|
|
36
|
-
def initialize(
|
37
|
-
|
38
|
-
|
36
|
+
def initialize(...)
|
37
|
+
super
|
38
|
+
|
39
|
+
@config[:flags] ||= 0
|
39
40
|
|
40
|
-
#
|
41
|
+
# JDBC mysql appears to use found rows by default: https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-connection.html
|
42
|
+
# if @config[:flags].kind_of? Array
|
43
|
+
# @config[:flags].push "FOUND_ROWS"
|
44
|
+
# else
|
45
|
+
# @config[:flags] |= ::Mysql2::Client::FOUND_ROWS
|
46
|
+
# end
|
47
|
+
|
48
|
+
@connection_parameters ||= @config
|
41
49
|
end
|
42
50
|
|
43
51
|
def self.database_exists?(config)
|
@@ -49,13 +57,6 @@ module ActiveRecord
|
|
49
57
|
conn.disconnect! if conn
|
50
58
|
end
|
51
59
|
|
52
|
-
def check_version
|
53
|
-
# for JNDI, don't check version as the whole connection should be lazy
|
54
|
-
return if ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
|
55
|
-
|
56
|
-
super
|
57
|
-
end
|
58
|
-
|
59
60
|
def supports_json?
|
60
61
|
!mariadb? && database_version >= '5.7.8'
|
61
62
|
end
|
@@ -96,20 +97,25 @@ module ActiveRecord
|
|
96
97
|
!READ_QUERY.match?(sql)
|
97
98
|
end
|
98
99
|
|
99
|
-
def explain(arel, binds = [])
|
100
|
-
sql = "
|
101
|
-
start =
|
102
|
-
result =
|
103
|
-
elapsed =
|
100
|
+
def explain(arel, binds = [], options = [])
|
101
|
+
sql = build_explain_clause(options) + " " + to_sql(arel, binds)
|
102
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
103
|
+
result = internal_exec_query(sql, "EXPLAIN", binds)
|
104
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
104
105
|
|
105
106
|
MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
|
106
107
|
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
|
109
|
+
def build_explain_clause(options = [])
|
110
|
+
return "EXPLAIN" if options.empty?
|
111
|
+
|
112
|
+
explain_clause = "EXPLAIN #{options.join(" ").upcase}"
|
113
|
+
|
114
|
+
if analyze_without_explain? && explain_clause.include?("ANALYZE")
|
115
|
+
explain_clause.sub("EXPLAIN ", "")
|
116
|
+
else
|
117
|
+
explain_clause
|
118
|
+
end
|
113
119
|
end
|
114
120
|
|
115
121
|
def each_hash(result) # :nodoc:
|
@@ -164,11 +170,47 @@ module ActiveRecord
|
|
164
170
|
# CONNECTION MANAGEMENT ====================================
|
165
171
|
#++
|
166
172
|
|
173
|
+
def active?
|
174
|
+
!(@raw_connection.nil? || @raw_connection.closed?) && @lock.synchronize { @raw_connection&.execute_query("/* ping */ SELECT 1") } || false
|
175
|
+
end
|
176
|
+
|
167
177
|
alias :reset! :reconnect!
|
168
178
|
|
179
|
+
# Disconnects from the database if already connected.
|
180
|
+
# Otherwise, this method does nothing.
|
181
|
+
def disconnect!
|
182
|
+
@lock.synchronize do
|
183
|
+
super
|
184
|
+
@raw_connection&.close
|
185
|
+
@raw_connection = nil
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def discard! # :nodoc:
|
190
|
+
@lock.synchronize do
|
191
|
+
super
|
192
|
+
@raw_connection&.automatic_close = false
|
193
|
+
@raw_connection = nil
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
169
197
|
#
|
170
198
|
|
171
199
|
private
|
200
|
+
# https://mariadb.com/kb/en/analyze-statement/
|
201
|
+
def analyze_without_explain?
|
202
|
+
mariadb? && database_version >= "10.1.0"
|
203
|
+
end
|
204
|
+
|
205
|
+
def text_type?(type)
|
206
|
+
TYPE_MAP.lookup(type).is_a?(Type::String) || TYPE_MAP.lookup(type).is_a?(Type::Text)
|
207
|
+
end
|
208
|
+
|
209
|
+
def configure_connection
|
210
|
+
# @raw_connection.query_options[:as] = :array
|
211
|
+
# @raw_connection.query_options[:database_timezone] = default_timezone
|
212
|
+
super
|
213
|
+
end
|
172
214
|
|
173
215
|
# e.g. "5.7.20-0ubuntu0.16.04.1"
|
174
216
|
def full_version
|
@@ -176,7 +218,7 @@ module ActiveRecord
|
|
176
218
|
end
|
177
219
|
|
178
220
|
def get_full_version
|
179
|
-
@full_version ||=
|
221
|
+
@full_version ||= any_raw_connection.full_version
|
180
222
|
end
|
181
223
|
|
182
224
|
def jdbc_connection_class(spec)
|