@@ -33,11 +33,19 @@ class Mysql2Adapter < AbstractMysqlAdapter
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
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
39
47
40
- # configure_connection taken care of at ArJdbc::Abstract::Core
48
+ @connection_parameters ||= @config
41
49
end
42
50
43
51
def self . database_exists? ( config )
@@ -49,13 +57,6 @@ def self.database_exists?(config)
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
@@ -105,13 +106,6 @@ def explain(arel, binds = [])
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
113
- end
114
-
115
109
def each_hash ( result ) # :nodoc:
116
110
if block_given?
117
111
# FIXME: This is C in mysql2 gem and I just made simplest Ruby
@@ -164,19 +158,50 @@ def _quote(value)
164
158
# CONNECTION MANAGEMENT ====================================
165
159
#++
166
160
161
+ def active?
162
+ !( @raw_connection . nil? || @raw_connection . closed? ) && @lock . synchronize { @raw_connection &.execute_query ( "/* ping */ SELECT 1" ) } || false
163
+ end
164
+
167
165
alias :reset! :reconnect!
168
166
167
+ # Disconnects from the database if already connected.
168
+ # Otherwise, this method does nothing.
169
+ def disconnect!
170
+ @lock . synchronize do
171
+ super
172
+ @raw_connection &.close
173
+ @raw_connection = nil
174
+ end
175
+ end
176
+
177
+ def discard! # :nodoc:
178
+ @lock . synchronize do
179
+ super
180
+ @raw_connection &.automatic_close = false
181
+ @raw_connection = nil
182
+ end
183
+ end
184
+
169
185
#
170
186
171
187
private
188
+ def text_type? ( type )
189
+ TYPE_MAP . lookup ( type ) . is_a? ( Type ::String ) || TYPE_MAP . lookup ( type ) . is_a? ( Type ::Text )
190
+ end
191
+
192
+ def configure_connection
193
+ # @raw_connection.query_options[:as] = :array
194
+ # @raw_connection.query_options[:database_timezone] = default_timezone
195
+ super
196
+ end
172
197
173
198
# e.g. "5.7.20-0ubuntu0.16.04.1"
174
199
def full_version
175
200
schema_cache . database_version . full_version_string
176
201
end
177
202
178
203
def get_full_version
179
- @full_version ||= @connection . full_version
204
+ @full_version ||= any_raw_connection . full_version
180
205
end
181
206
182
207
def jdbc_connection_class ( spec )
0 commit comments