Database class for Sequel's mock adapter.
Methods
Public Class
Public Instance
Constants
| SHARED_ADAPTERS | = | { 'access'=>'Access', 'db2'=>'DB2', 'firebird'=>'Firebird', 'informix'=>'Informix', 'mssql'=>'MSSQL', 'mysql'=>'MySQL', 'oracle'=>'Oracle', 'postgres'=>'Postgres', 'sqlite'=>'SQLite' } |
Map of database type names to module names, used for handling mock adapters for specific database types. |
|
| SHARED_ADAPTER_SETUP | = | { 'postgres' => lambda do |db| db.instance_eval do @server_version = 90103 initialize_postgres_adapter end db.extend(Module.new do def bound_variable_arg(arg, conn) arg end def primary_key(table) :id end end) end, 'oracle' => lambda do |db| db.instance_eval do @primary_key_sequences = {} end end, 'mssql' => lambda do |db| db.instance_eval do @server_version = 10000000 end end } |
Procs to run for specific database types to get the mock adapter to work with the shared adapter |
Public Instance Aliases
| execute_ddl | -> | execute |
Attributes
| autoid | [W] |
Set the autogenerated primary key integer to be returned when running an insert query. Argument types supported:
|
| columns | [W] |
Set the columns to set in the dataset when the dataset fetches rows. Argument types supported:
Array of Symbols: Used for all datasets Array (otherwise): First retrieval gets the first value in the array, second gets the second value, etc.
|
| fetch | [W] |
Set the hashes to yield by execute when retrieving rows. Argument types supported:
|
| numrows | [W] |
Set the number of rows to return from update or delete. Argument types supported:
|
| server_version | [RW] |
Mock the server version, useful when using the shared adapters |
Public Class methods
Additional options supported:
# File lib/sequel/adapters/mock.rb, line 142 def initialize(opts={}) super opts = @opts @sqls = opts[:sqls] || [] if mod_name = SHARED_ADAPTERS[opts[:host]] @shared_adapter = true require "sequel/adapters/shared/#{opts[:host]}" extend Sequel.const_get(mod_name)::DatabaseMethods extend_datasets Sequel.const_get(mod_name)::DatasetMethods if pr = SHARED_ADAPTER_SETUP[opts[:host]] pr.call(self) end else @shared_adapter = false end self.autoid = opts[:autoid] self.columns = opts[:columns] self.fetch = opts[:fetch] self.numrows = opts[:numrows] extend(opts[:extend]) if opts[:extend] sqls end
Public Instance methods
Return a related Connection option connecting to the given shard.
# File lib/sequel/adapters/mock.rb, line 166 def connect(server) Connection.new(self, server, server_opts(server)) end
# File lib/sequel/adapters/mock.rb, line 170 def disconnect_connection(c) end
Store the sql used for later retrieval with sqls, and return the appropriate value using either the autoid, fetch, or numrows methods.
# File lib/sequel/adapters/mock.rb, line 176 def execute(sql, opts={}, &block) synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} end
Store the sql used, and return the value of the numrows method.
# File lib/sequel/adapters/mock.rb, line 182 def execute_dui(sql, opts={}) execute(sql, opts.merge(:meth=>:numrows)) end
Store the sql used, and return the value of the autoid method.
# File lib/sequel/adapters/mock.rb, line 187 def execute_insert(sql, opts={}) execute(sql, opts.merge(:meth=>:autoid)) end
Return all stored SQL queries, and clear the cache of SQL queries.
# File lib/sequel/adapters/mock.rb, line 193 def sqls s = @sqls.dup @sqls.clear s end
Enable use of savepoints.
# File lib/sequel/adapters/mock.rb, line 200 def supports_savepoints? shared_adapter? ? super : true end