Class: ActiveRecord::ConnectionAdapters::DbslayerAdapter
- Inherits:
-
MysqlAdapter
- Object
- MysqlAdapter
- ActiveRecord::ConnectionAdapters::DbslayerAdapter
- Defined in:
- lib/active_record/connection_adapters/dbslayer_adapter.rb,
lib/activerecord-dbslayer-adapter.rb
Overview
The DbslayerAdapter is an adapter to use Rails with the DBSlayer
Options:
-
:host– Defaults to localhost -
:port– Defaults to 3306
Like the MySQL adapter: by default, the MysqlAdapter will consider all columns of type tinyint(1) as boolean. If you wish to disable this emulation (which was the default behavior in versions 0.13.1 and earlier) you can add the following line to your environment.rb file:
ActiveRecord::ConnectionAdapters::DbslayerAdapter.emulate_booleans = false
MAJOR WARNING: The MySQL adapter in Rails sets the
Constant Summary collapse
- VERSION =
'0.3.0'
Instance Method Summary collapse
-
#active? ⇒ Boolean
CONNECTION MANAGEMENT ====================================.
-
#adapter_name ⇒ Object
:nodoc:.
-
#begin_db_transaction ⇒ Object
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc: super sql, name id_value || @connection.insert_id end.
-
#columns(table_name, name = nil) ⇒ Object
:nodoc:.
-
#commit_db_transaction ⇒ Object
:nodoc:.
-
#disable_referential_integrity(&block) ⇒ Object
REFERENTIAL INTEGRITY ====================================.
- #disconnect! ⇒ Object
-
#execute(sql, name = nil) ⇒ Object
:nodoc:.
-
#indexes(table_name, name = nil) ⇒ Object
def drop_table(table_name, options = {}) super(table_name, options) end.
-
#initialize(connection, logger, connection_options, config) ⇒ DbslayerAdapter
constructor
A new instance of DbslayerAdapter.
-
#pk_and_sequence_for(table) ⇒ Object
Returns a table’s primary key and belonging sequence.
- #reconnect! ⇒ Object
-
#rollback_db_transaction ⇒ Object
:nodoc:.
-
#select_rows(sql, name = nil) ⇒ Object
DATABASE STATEMENTS ======================================.
-
#show_variable(name) ⇒ Object
SHOW VARIABLES LIKE ‘name’.
-
#tables(name = nil) ⇒ Object
Returns the database character set.
Constructor Details
#initialize(connection, logger, connection_options, config) ⇒ DbslayerAdapter
Returns a new instance of DbslayerAdapter.
46 47 48 49 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 46 def initialize(connection, logger, , config) super(connection, logger, , config) ActiveRecord::Base.allow_concurrency = true end |
Instance Method Details
#active? ⇒ Boolean
CONNECTION MANAGEMENT ====================================
126 127 128 129 130 131 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 126 def active? stats = @connection.mysql_stats !stats.nil? && !stats.empty? rescue false end |
#adapter_name ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 51 def adapter_name #:nodoc: 'DBSlayer (MySQL)' end |
#begin_db_transaction ⇒ Object
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
super sql, name
id_value || @connection.insert_id
end
def update_sql(sql, name = nil) #:nodoc:
super
@connection.affected_rows
end
165 166 167 168 169 170 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 165 def begin_db_transaction #:nodoc: # FIXME: raise exception? # execute "BEGIN" # rescue Exception # Transactions aren't supported end |
#columns(table_name, name = nil) ⇒ Object
:nodoc:
273 274 275 276 277 278 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 273 def columns(table_name, name = nil)#:nodoc: sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}" columns = [] execute(sql, name).rows.each { |row| columns << DbslayerColumn.new(row[0], row[4], row[1], row[2] == "YES") } columns end |
#commit_db_transaction ⇒ Object
:nodoc:
172 173 174 175 176 177 178 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 172 def commit_db_transaction #:nodoc: # FIXME: raise exception? # execute "COMMIT" # rescue Exception # Transactions aren't supported end |
#disable_referential_integrity(&block) ⇒ Object
REFERENTIAL INTEGRITY ====================================
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 112 def disable_referential_integrity(&block) #:nodoc: #FIXME: I CAN'T LET YOU DO THIS # old = select_value("SELECT @@FOREIGN_KEY_CHECKS") # # begin # update("SET FOREIGN_KEY_CHECKS = 0") # yield # ensure # update("SET FOREIGN_KEY_CHECKS = #{old}") # end end |
#disconnect! ⇒ Object
137 138 139 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 137 def disconnect! # DO NOTHING, we connect on the request end |
#execute(sql, name = nil) ⇒ Object
:nodoc:
149 150 151 152 153 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 149 def execute(sql, name = nil) #:nodoc: log(sql, name) { @connection.execute(sql) } end |
#indexes(table_name, name = nil) ⇒ Object
def drop_table(table_name, options = {})
super(table_name, )
end
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 258 def indexes(table_name, name = nil)#:nodoc: indexes = [] current_index = nil execute("SHOW KEYS FROM #{quote_table_name(table_name)}", name).rows.each do |row| if current_index != row[2] next if row[2] == "PRIMARY" # skip the primary key current_index = row[2] indexes << IndexDefinition.new(row[0], row[2], row[1] == "0", []) end indexes.last.columns << row[4] end indexes end |
#pk_and_sequence_for(table) ⇒ Object
Returns a table’s primary key and belonging sequence.
320 321 322 323 324 325 326 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 320 def pk_and_sequence_for(table) #:nodoc: keys = [] execute("describe #{quote_table_name(table)}").each_hash do |h| keys << h["Field"]if h["Key"] == "PRI" end keys.length == 1 ? [keys.first, nil] : nil end |
#reconnect! ⇒ Object
133 134 135 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 133 def reconnect! # DO NOTHING, we connect on the request end |
#rollback_db_transaction ⇒ Object
:nodoc:
180 181 182 183 184 185 186 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 180 def rollback_db_transaction #:nodoc: # FIXME: raise exception? # execute "ROLLBACK" # rescue Exception # Transactions aren't supported end |
#select_rows(sql, name = nil) ⇒ Object
DATABASE STATEMENTS ======================================
144 145 146 147 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 144 def select_rows(sql, name = nil) result = execute(sql, name) result.rows end |
#show_variable(name) ⇒ Object
SHOW VARIABLES LIKE ‘name’
314 315 316 317 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 314 def show_variable(name) variables = select_all("SHOW VARIABLES LIKE '#{name}'") variables.first['Value'] unless variables.empty? end |
#tables(name = nil) ⇒ Object
Returns the database character set. def charset
if @charset.nil?
@charset = show_variable 'character_set_database'
end
@charset
end
# Returns the database collation strategy. def collation
if @collation.nil?
@collation = show_variable 'collation_database'
end
@collation
end
248 249 250 251 252 |
# File 'lib/active_record/connection_adapters/dbslayer_adapter.rb', line 248 def tables(name = nil) #:nodoc: tables = [] execute("SHOW TABLES", name).rows.each { |row| tables << row[0] } tables end |