module Sequel::Dataset::EmulatePreparedStatementMethods

Prepared statements emulation support for adapters that don't support native prepared statements. Uses a placeholder literalizer to hold the prepared sql with the ability to interpolate arguments to prepare the final SQL string.

Public Instance Methods

run(&block) click to toggle source
Calls superclass method
# File lib/sequel/dataset/prepared_statements.rb, line 274
def run(&block)
  if @opts[:prepared_sql_frags]
    sql = literal(Sequel::SQL::PlaceholderLiteralString.new(@opts[:prepared_sql_frags], @opts[:bind_arguments], false))
    clone(:prepared_sql_frags=>nil, :sql=>sql, :prepared_sql=>sql).run(&block)
  else
    super
  end
end

Private Instance Methods

emulate_prepared_statements?() click to toggle source

Turn emulation of prepared statements back on, since ArgumentMapper turns it off.

# File lib/sequel/dataset/prepared_statements.rb, line 287
def emulate_prepared_statements?
  true
end
emulated_prepared_statement(type, name, values) click to toggle source
# File lib/sequel/dataset/prepared_statements.rb, line 291
def emulated_prepared_statement(type, name, values)
  prepared_sql, frags = Sequel::Dataset::PlaceholderLiteralizer::Recorder.new.send(:prepared_sql_and_frags, self, prepared_args) do |pl, ds|
    ds = ds.clone(:recorder=>pl)

    case type
    when :first, :single_value
      ds.limit(1)
    when :update, :insert, :insert_select, :delete
      ds.with_sql(:"#{type}_sql", *values)
    when :insert_pk
      ds.with_sql(:insert_sql, *values)
    else
      ds
    end
  end

  prepared_args.freeze
  clone(:prepared_sql_frags=>frags, :prepared_sql=>prepared_sql, :sql=>prepared_sql)
end
prepared_arg(k) click to toggle source

Associates the argument with name k with the next position in the output array.

# File lib/sequel/dataset/prepared_statements.rb, line 313
def prepared_arg(k)
  prepared_args << k
  @opts[:recorder].arg
end
subselect_sql_dataset(sql, ds) click to toggle source
Calls superclass method
# File lib/sequel/dataset/prepared_statements.rb, line 318
def subselect_sql_dataset(sql, ds)
  super.clone(:recorder=>@opts[:recorder]).
    with_extend(EmulatePreparedStatementMethods)
end