class Sequel::Mock::Database

  1. lib/sequel/adapters/mock.rb
Parent: Mock

Database class for Sequel's mock adapter.

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:

nil

Return nil for all inserts

Integer

Starting integer for next insert, with futher inserts getting an incremented value

Array

First insert gets the first value in the array, second gets the second value, etc.

Proc

Called with the insert SQL query, uses the value returned

Class

Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError.

columns [W]

Set the columns to set in the dataset when the dataset fetches rows. Argument types supported:

nil

Set no columns

Array of Symbols: Used for all datasets Array (otherwise): First retrieval gets the first value in the

array, second gets the second value, etc.
Proc

Called with the select SQL query, uses the value returned, which should be an array of symbols

fetch [W]

Set the hashes to yield by execute when retrieving rows. Argument types supported:

nil

Yield no rows

Hash

Always yield a single row with this hash

Array of Hashes

Yield separately for each hash in this array

Array (otherwise)

First retrieval gets the first value in the array, second gets the second value, etc.

Proc

Called with the select SQL query, uses the value returned, which should be a hash or array of hashes.

Class

Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError.

numrows [W]

Set the number of rows to return from update or delete. Argument types supported:

nil

Return 0 for all updates and deletes

Integer

Used for all updates and deletes

Array

First update/delete gets the first value in the array, second gets the second value, etc.

Proc

Called with the update/delete SQL query, uses the value returned.

Class

Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError.

server_version [RW]

Mock the server version, useful when using the shared adapters

Public Instance methods

connect (server)

Return a related Connection option connecting to the given shard.

[show source]
# File lib/sequel/adapters/mock.rb, line 135
def connect(server)
  Connection.new(self, server, server_opts(server))
end
disconnect_connection (c)
[show source]
# File lib/sequel/adapters/mock.rb, line 139
def disconnect_connection(c)
end
execute (sql, opts=OPTS, &block)

Store the sql used for later retrieval with sqls, and return the appropriate value using either the autoid, fetch, or numrows methods.

[show source]
# File lib/sequel/adapters/mock.rb, line 145
def execute(sql, opts=OPTS, &block)
  synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} 
end
execute_dui (sql, opts=OPTS)

Store the sql used, and return the value of the numrows method.

[show source]
# File lib/sequel/adapters/mock.rb, line 151
def execute_dui(sql, opts=OPTS)
  execute(sql, opts.merge(:meth=>:numrows))
end
execute_insert (sql, opts=OPTS)

Store the sql used, and return the value of the autoid method.

[show source]
# File lib/sequel/adapters/mock.rb, line 156
def execute_insert(sql, opts=OPTS)
  execute(sql, opts.merge(:meth=>:autoid))
end
sqls ()

Return all stored SQL queries, and clear the cache of SQL queries.

[show source]
# File lib/sequel/adapters/mock.rb, line 162
def sqls
  s = @sqls.dup
  @sqls.clear
  s
end
supports_savepoints? ()

Enable use of savepoints.

[show source]
# File lib/sequel/adapters/mock.rb, line 169
def supports_savepoints?
  shared_adapter? ? super : true
end