Module: Sequel::Dataset::ArgumentMapper

Overview

Default implementation of the argument mapper to allow native database support for bind variables and prepared statements (as opposed to the emulated ones used by default).

Instance Method Summary collapse

Instance Method Details

#bind_argumentsObject

The bind arguments to use for running this prepared statement


50
51
52
# File 'lib/sequel/dataset/prepared_statements.rb', line 50

def bind_arguments
  @opts[:bind_arguments]
end

#call(bind_vars = {}, &block) ⇒ Object

Set the bind arguments based on the hash and call super.


55
56
57
58
59
60
# File 'lib/sequel/dataset/prepared_statements.rb', line 55

def call(bind_vars={}, &block)
  sql = prepared_sql
  prepared_args.freeze
  ps = bind(bind_vars)
  ps.clone(:bind_arguments=>ps.map_to_prepared_args(ps.opts[:bind_vars]), :sql=>sql, :prepared_sql=>sql).run(&block)
end

#prepared_sqlObject

Override the given *_sql method based on the type, and cache the result of the sql.


64
65
66
67
68
69
# File 'lib/sequel/dataset/prepared_statements.rb', line 64

def prepared_sql
  if sql = @opts[:prepared_sql] || cache_get(:_prepared_sql)
    return sql
  end
  cache_set(:_prepared_sql, super)
end

#prepared_statement_nameObject

The name of the prepared statement, if any.


45
46
47
# File 'lib/sequel/dataset/prepared_statements.rb', line 45

def prepared_statement_name
  @opts[:prepared_statement_name]
end