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'
Constants included from ArJdbc::Abstract::DatabaseStatements
ArJdbc::Abstract::DatabaseStatements::NO_BINDS
Class Method Summary collapse
Instance Method Summary collapse
- #check_version ⇒ Object
-
#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, 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_lazy_transactions? ⇒ Boolean
- #supports_savepoints? ⇒ Boolean
- #supports_set_server_option? ⇒ Boolean
- #supports_transaction_isolation? ⇒ Boolean
-
#write_query?(sql) ⇒ Boolean
:nodoc:.
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
Methods included from ArJdbc::Abstract::DatabaseStatements
#exec_insert, #exec_query, #exec_update, #execute, #select_all
Methods included from ArJdbc::Abstract::ConnectionManagement
#active?, #disconnect!, #really_valid?, #reconnect!
Methods included from Jdbc::ConnectionPoolCallbacks
Constructor Details
#initialize(connection, logger, connection_parameters, config) ⇒ Mysql2Adapter
Returns a new instance of Mysql2Adapter.
36 37 38 39 40 41 |
# File 'lib/arjdbc/mysql/adapter.rb', line 36 def initialize(connection, logger, connection_parameters, config) super @prepared_statements = false unless config.key?(:prepared_statements) # configure_connection taken care of at ArJdbc::Abstract::Core end |
Class Method Details
.database_exists?(config) ⇒ Boolean
43 44 45 46 47 48 49 50 |
# File 'lib/arjdbc/mysql/adapter.rb', line 43 def self.database_exists?(config) conn = ActiveRecord::Base.mysql2_connection(config) conn && conn.really_valid? rescue ActiveRecord::NoDatabaseError false ensure conn.disconnect! if conn end |
Instance Method Details
#check_version ⇒ Object
52 53 54 55 56 57 |
# File 'lib/arjdbc/mysql/adapter.rb', line 52 def check_version # for JNDI, don't check version as the whole connection should be lazy return if ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config) super end |
#clear_cache! ⇒ Object
Reloading the type map in abstract/statement_cache.rb blows up postgres
100 101 102 103 |
# File 'lib/arjdbc/mysql/adapter.rb', line 100 def clear_cache! reload_type_map super end |
#each_hash(result) ⇒ Object
:nodoc:
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/arjdbc/mysql/adapter.rb', line 105 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
118 119 120 |
# File 'lib/arjdbc/mysql/adapter.rb', line 118 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.
129 130 131 |
# File 'lib/arjdbc/mysql/adapter.rb', line 129 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)
136 137 138 139 140 141 142 |
# File 'lib/arjdbc/mysql/adapter.rb', line 136 def quoted_date(value) if supports_datetime_with_precision? super else super.sub(/\.\d{6}\z/, '') end end |
#supports_comments? ⇒ Boolean
63 64 65 |
# File 'lib/arjdbc/mysql/adapter.rb', line 63 def supports_comments? true end |
#supports_comments_in_create? ⇒ Boolean
67 68 69 |
# File 'lib/arjdbc/mysql/adapter.rb', line 67 def supports_comments_in_create? true end |
#supports_json? ⇒ Boolean
59 60 61 |
# File 'lib/arjdbc/mysql/adapter.rb', line 59 def supports_json? !mariadb? && database_version >= '5.7.8' end |
#supports_lazy_transactions? ⇒ Boolean
75 76 77 |
# File 'lib/arjdbc/mysql/adapter.rb', line 75 def supports_lazy_transactions? true end |
#supports_savepoints? ⇒ Boolean
71 72 73 |
# File 'lib/arjdbc/mysql/adapter.rb', line 71 def supports_savepoints? true end |
#supports_set_server_option? ⇒ Boolean
83 84 85 |
# File 'lib/arjdbc/mysql/adapter.rb', line 83 def supports_set_server_option? false end |
#supports_transaction_isolation? ⇒ Boolean
79 80 81 |
# File 'lib/arjdbc/mysql/adapter.rb', line 79 def supports_transaction_isolation? true end |
#write_query?(sql) ⇒ Boolean
:nodoc:
95 96 97 |
# File 'lib/arjdbc/mysql/adapter.rb', line 95 def write_query?(sql) # :nodoc: !READ_QUERY.match?(sql) end |