Class: ActiveRecord::ConnectionAdapters::Mysql2Adapter
- Inherits:
-
AbstractMysqlAdapter
- Object
- AbstractMysqlAdapter
- ActiveRecord::ConnectionAdapters::Mysql2Adapter
- Includes:
- Jdbc::ConnectionPoolCallbacks, ArJdbc::Abstract::ConnectionManagement, ArJdbc::Abstract::DatabaseStatements, ArJdbc::Abstract::StatementCache, ArJdbc::Abstract::TransactionSupport, ArJdbc::MySQL
- Defined in:
- lib/arjdbc/mysql/adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
'Mysql2'.freeze
Constants included from ArJdbc::Abstract::DatabaseStatements
ArJdbc::Abstract::DatabaseStatements::NO_BINDS
Instance Method Summary collapse
-
#clear_cache! ⇒ Object
Reloading the type map in abstract/statement_cache.rb blows up postgres.
-
#create_table(table_name, **options) ⇒ Object
:nodoc:.
-
#each_hash(result) ⇒ Object
:nodoc:.
- #error_number(exception) ⇒ Object
-
#initialize(connection, logger, connection_parameters, config) ⇒ Mysql2Adapter
constructor
A new instance of Mysql2Adapter.
-
#quote(value, comment = nil) ⇒ Object
FIXME: 5.1 crashes without this.
-
#quoted_date(value) ⇒ Object
NOTE: quote_string(string) provided by ArJdbc::MySQL (native code), this piece is also native (mysql2) under MRI:
@connection.escape(string)
. - #supports_comments? ⇒ Boolean
- #supports_comments_in_create? ⇒ Boolean
- #supports_json? ⇒ Boolean
- #supports_savepoints? ⇒ Boolean
- #supports_transaction_isolation? ⇒ Boolean
Methods included from ArJdbc::Abstract::TransactionSupport
#begin_db_transaction, #begin_isolated_db_transaction, #commit_db_transaction, #create_savepoint, #exec_rollback_db_transaction, #exec_rollback_to_savepoint, #release_savepoint
Methods included from ArJdbc::Abstract::StatementCache
#delete_cached_statement, #fetch_cached_statement, #supports_statement_cache?
Methods included from ArJdbc::Abstract::DatabaseStatements
#exec_insert, #exec_query, #exec_update, #execute, #select_all
Methods included from ArJdbc::Abstract::ConnectionManagement
#active?, #disconnect!, #reconnect!
Methods included from Jdbc::ConnectionPoolCallbacks
Constructor Details
#initialize(connection, logger, connection_parameters, config) ⇒ Mysql2Adapter
Returns a new instance of Mysql2Adapter.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/arjdbc/mysql/adapter.rb', line 34 def initialize(connection, logger, connection_parameters, config) # workaround to skip version check on JNDI to be lazy, dummy version is high enough for Rails 5.0 - 6.0 is_jndi = ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config) @version = '8.1.5' if is_jndi super # set to nil to have it lazy-load the real value when required @version = nil if is_jndi @prepared_statements = false unless config.key?(:prepared_statements) # configure_connection taken care of at ArJdbc::Abstract::Core end |
Instance Method Details
#clear_cache! ⇒ Object
Reloading the type map in abstract/statement_cache.rb blows up postgres
71 72 73 74 |
# File 'lib/arjdbc/mysql/adapter.rb', line 71 def clear_cache! reload_type_map super end |
#create_table(table_name, **options) ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/arjdbc/mysql/adapter.rb', line 93 def create_table(table_name, **) #:nodoc: super(table_name, options: "ENGINE=InnoDB", **) end |
#each_hash(result) ⇒ Object
:nodoc:
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/arjdbc/mysql/adapter.rb', line 76 def each_hash(result) # :nodoc: if block_given? # FIXME: This is C in mysql2 gem and I just made simplest Ruby result.each do |row| new_hash = {} row.each { |k, v| new_hash[k.to_sym] = v } yield new_hash end else to_enum(:each_hash, result) end end |
#error_number(exception) ⇒ Object
89 90 91 |
# File 'lib/arjdbc/mysql/adapter.rb', line 89 def error_number(exception) exception.error_code if exception.is_a?(JDBCError) end |
#quote(value, comment = nil) ⇒ Object
FIXME: 5.1 crashes without this. I think this is Arel hitting a fallback path in to_sql.rb. So maybe an untested code path in their source. Still means we are doing something wrong to even hit it.
104 105 106 |
# File 'lib/arjdbc/mysql/adapter.rb', line 104 def quote(value, comment=nil) super(value) end |
#quoted_date(value) ⇒ Object
NOTE: quote_string(string) provided by ArJdbc::MySQL (native code),
this piece is also native (mysql2) under MRI: @connection.escape(string)
111 112 113 114 115 116 117 |
# File 'lib/arjdbc/mysql/adapter.rb', line 111 def quoted_date(value) if supports_datetime_with_precision? super else super.sub(/\.\d{6}\z/, '') end end |
#supports_comments? ⇒ Boolean
52 53 54 |
# File 'lib/arjdbc/mysql/adapter.rb', line 52 def supports_comments? true end |
#supports_comments_in_create? ⇒ Boolean
56 57 58 |
# File 'lib/arjdbc/mysql/adapter.rb', line 56 def supports_comments_in_create? true end |
#supports_json? ⇒ Boolean
48 49 50 |
# File 'lib/arjdbc/mysql/adapter.rb', line 48 def supports_json? !mariadb? && version >= '5.7.8' end |
#supports_savepoints? ⇒ Boolean
60 61 62 |
# File 'lib/arjdbc/mysql/adapter.rb', line 60 def supports_savepoints? true end |
#supports_transaction_isolation? ⇒ Boolean
64 65 66 |
# File 'lib/arjdbc/mysql/adapter.rb', line 64 def supports_transaction_isolation? true end |