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.
-
#each_hash(result) ⇒ Object
:nodoc:.
- #error_number(exception) ⇒ Object
-
#initialize(connection, logger, 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_set_server_option? ⇒ 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
#delete, #exec_insert, #exec_query, #exec_update, #execute, #insert, #select_all, #update
Methods included from ArJdbc::Abstract::ConnectionManagement
#active?, #disconnect!, #reconnect!
Methods included from Jdbc::ConnectionPoolCallbacks
Constructor Details
#initialize(connection, logger, config) ⇒ Mysql2Adapter
Returns a new instance of Mysql2Adapter.
34 35 36 37 38 |
# File 'lib/arjdbc/mysql/adapter.rb', line 34 def initialize(connection, logger, config) super(connection, logger, nil, config) @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
67 68 69 70 |
# File 'lib/arjdbc/mysql/adapter.rb', line 67 def clear_cache! reload_type_map super end |
#each_hash(result) ⇒ Object
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/arjdbc/mysql/adapter.rb', line 72 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
85 86 87 |
# File 'lib/arjdbc/mysql/adapter.rb', line 85 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.
96 97 98 |
# File 'lib/arjdbc/mysql/adapter.rb', line 96 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)
103 104 105 106 107 108 109 |
# File 'lib/arjdbc/mysql/adapter.rb', line 103 def quoted_date(value) if supports_datetime_with_precision? super else super.sub(/\.\d{6}\z/, '') end end |
#supports_comments? ⇒ Boolean
44 45 46 |
# File 'lib/arjdbc/mysql/adapter.rb', line 44 def supports_comments? true end |
#supports_comments_in_create? ⇒ Boolean
48 49 50 |
# File 'lib/arjdbc/mysql/adapter.rb', line 48 def supports_comments_in_create? true end |
#supports_json? ⇒ Boolean
40 41 42 |
# File 'lib/arjdbc/mysql/adapter.rb', line 40 def supports_json? !mariadb? && version >= '5.7.8' end |
#supports_savepoints? ⇒ Boolean
52 53 54 |
# File 'lib/arjdbc/mysql/adapter.rb', line 52 def supports_savepoints? true end |
#supports_set_server_option? ⇒ Boolean
60 61 62 |
# File 'lib/arjdbc/mysql/adapter.rb', line 60 def supports_set_server_option? false end |
#supports_transaction_isolation? ⇒ Boolean
56 57 58 |
# File 'lib/arjdbc/mysql/adapter.rb', line 56 def supports_transaction_isolation? true end |