activerecord-jdbc-alt-adapter 70.1.0-java → 71.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +135 -21
  3. data/.github/workflows/ruby.yml +10 -10
  4. data/.gitignore +1 -0
  5. data/.solargraph.yml +15 -0
  6. data/Gemfile +17 -4
  7. data/README.md +7 -3
  8. data/RUNNING_TESTS.md +36 -0
  9. data/activerecord-jdbc-adapter.gemspec +2 -2
  10. data/activerecord-jdbc-alt-adapter.gemspec +1 -1
  11. data/lib/arel/visitors/sqlserver.rb +10 -0
  12. data/lib/arjdbc/abstract/connection_management.rb +23 -10
  13. data/lib/arjdbc/abstract/core.rb +5 -6
  14. data/lib/arjdbc/abstract/database_statements.rb +35 -25
  15. data/lib/arjdbc/abstract/statement_cache.rb +1 -6
  16. data/lib/arjdbc/abstract/transaction_support.rb +37 -9
  17. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  18. data/lib/arjdbc/jdbc/column.rb +0 -34
  19. data/lib/arjdbc/jdbc/connection_methods.rb +1 -1
  20. data/lib/arjdbc/mssql/adapter.rb +93 -80
  21. data/lib/arjdbc/mssql/column.rb +1 -0
  22. data/lib/arjdbc/mssql/connection_methods.rb +7 -55
  23. data/lib/arjdbc/mssql/database_statements.rb +182 -71
  24. data/lib/arjdbc/mssql/explain_support.rb +8 -5
  25. data/lib/arjdbc/mssql/schema_creation.rb +1 -1
  26. data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
  27. data/lib/arjdbc/mssql/schema_statements.rb +19 -11
  28. data/lib/arjdbc/mssql/server_version.rb +56 -0
  29. data/lib/arjdbc/mssql/utils.rb +23 -9
  30. data/lib/arjdbc/mysql/adapter.rb +64 -22
  31. data/lib/arjdbc/mysql/connection_methods.rb +43 -42
  32. data/lib/arjdbc/sqlite3/adapter.rb +218 -135
  33. data/lib/arjdbc/sqlite3/column.rb +103 -0
  34. data/lib/arjdbc/sqlite3/connection_methods.rb +7 -2
  35. data/lib/arjdbc/tasks/mssql_database_tasks.rb +9 -5
  36. data/lib/arjdbc/version.rb +1 -1
  37. data/rakelib/02-test.rake +1 -1
  38. data/rakelib/rails.rake +2 -0
  39. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -2
  40. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +2 -1
  41. metadata +11 -14
  42. data/lib/arel/visitors/sql_server/ng42.rb +0 -294
  43. data/lib/arel/visitors/sql_server.rb +0 -124
  44. data/lib/arjdbc/mssql/limit_helpers.rb +0 -231
  45. data/lib/arjdbc/mssql/lock_methods.rb +0 -77
  46. data/lib/arjdbc/mssql/old_adapter.rb +0 -804
  47. data/lib/arjdbc/mssql/old_column.rb +0 -200
@@ -33,11 +33,19 @@ module ActiveRecord
33
33
 
34
34
  include ArJdbc::MySQL
35
35
 
36
- def initialize(connection, logger, connection_options, config)
37
- superclass_config = config.reverse_merge(prepared_statements: false)
38
- super(connection, logger, connection_options, superclass_config)
36
+ def initialize(...)
37
+ super
38
+
39
+ @config[:flags] ||= 0
39
40
 
40
- # configure_connection taken care of at ArJdbc::Abstract::Core
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 = "EXPLAIN #{to_sql(arel, binds)}"
101
- start = Concurrent.monotonic_time
102
- result = exec_query(sql, "EXPLAIN", binds)
103
- elapsed = Concurrent.monotonic_time - start
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
- # Reloading the type map in abstract/statement_cache.rb blows up postgres
109
- def clear_cache!
110
- # FIXME: This seems to have disappeared in Rails 7?
111
- # reload_type_map
112
- super
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 ||= @connection.full_version
221
+ @full_version ||= any_raw_connection.full_version
180
222
  end
181
223
 
182
224
  def jdbc_connection_class(spec)
@@ -126,51 +126,52 @@ ArJdbc::ConnectionMethods.module_eval do
126
126
 
127
127
  private
128
128
 
129
- @@mysql_encodings = nil
129
+ MYSQL_ENCODINGS = {
130
+ "big5" => "Big5",
131
+ "dec8" => nil,
132
+ #"cp850" => "Cp850",
133
+ "hp8" => nil,
134
+ #"koi8r" => "KOI8-R",
135
+ "latin1" => "Cp1252",
136
+ "latin2" => "ISO8859_2",
137
+ "swe7" => nil,
138
+ "ascii" => "US-ASCII",
139
+ "ujis" => "EUC_JP",
140
+ "sjis" => "SJIS",
141
+ "hebrew" => "ISO8859_8",
142
+ "tis620" => "TIS620",
143
+ "euckr" => "EUC_KR",
144
+ #"koi8u" => "KOI8-R",
145
+ "gb2312" => "EUC_CN",
146
+ "greek" => "ISO8859_7",
147
+ "cp1250" => "Cp1250",
148
+ "gbk" => "GBK",
149
+ #"latin5" => "ISO-8859-9",
150
+ "armscii8" => nil,
151
+ "ucs2" => "UnicodeBig",
152
+ "cp866" => "Cp866",
153
+ "keybcs2" => nil,
154
+ "macce" => "MacCentralEurope",
155
+ "macroman" => "MacRoman",
156
+ #"cp852" => "CP852",
157
+ #"latin7" => "ISO-8859-13",
158
+ "cp1251" => "Cp1251",
159
+ "cp1256" => "Cp1256",
160
+ "cp1257" => "Cp1257",
161
+ "binary" => false,
162
+ "geostd8" => nil,
163
+ "cp932" => "Cp932",
164
+ #"eucjpms" => "eucJP-ms"
165
+ "utf8" => "UTF-8",
166
+ "utf8mb4" => false,
167
+ "utf16" => false,
168
+ "utf32" => false,
169
+ }
170
+
130
171
 
131
172
  # @see https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html
132
173
  def convert_mysql_encoding(encoding) # to charset-name (characterEncoding=...)
133
- ( @@mysql_encodings ||= {
134
- "big5" => "Big5",
135
- "dec8" => nil,
136
- #"cp850" => "Cp850",
137
- "hp8" => nil,
138
- #"koi8r" => "KOI8-R",
139
- "latin1" => "Cp1252",
140
- "latin2" => "ISO8859_2",
141
- "swe7" => nil,
142
- "ascii" => "US-ASCII",
143
- "ujis" => "EUC_JP",
144
- "sjis" => "SJIS",
145
- "hebrew" => "ISO8859_8",
146
- "tis620" => "TIS620",
147
- "euckr" => "EUC_KR",
148
- #"koi8u" => "KOI8-R",
149
- "gb2312" => "EUC_CN",
150
- "greek" => "ISO8859_7",
151
- "cp1250" => "Cp1250",
152
- "gbk" => "GBK",
153
- #"latin5" => "ISO-8859-9",
154
- "armscii8" => nil,
155
- "ucs2" => "UnicodeBig",
156
- "cp866" => "Cp866",
157
- "keybcs2" => nil,
158
- "macce" => "MacCentralEurope",
159
- "macroman" => "MacRoman",
160
- #"cp852" => "CP852",
161
- #"latin7" => "ISO-8859-13",
162
- "cp1251" => "Cp1251",
163
- "cp1256" => "Cp1256",
164
- "cp1257" => "Cp1257",
165
- "binary" => false,
166
- "geostd8" => nil,
167
- "cp932" => "Cp932",
168
- #"eucjpms" => "eucJP-ms"
169
- "utf8" => "UTF-8",
170
- "utf8mb4" => false,
171
- "utf16" => false,
172
- "utf32" => false,
173
- } )[ encoding ]
174
+ MYSQL_ENCODINGS[ encoding ]
174
175
  end
175
176
 
176
177
  end