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
273 def run(&block)
274   if @opts[:prepared_sql_frags]
275     sql = literal(Sequel::SQL::PlaceholderLiteralString.new(@opts[:prepared_sql_frags], @opts[:bind_arguments], false))
276     clone(:prepared_sql_frags=>nil, :sql=>sql, :prepared_sql=>sql).run(&block)
277   else
278     super
279   end
280 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
286 def emulate_prepared_statements?
287   true
288 end
emulated_prepared_statement(type, name, values) click to toggle source
    # File lib/sequel/dataset/prepared_statements.rb
290 def emulated_prepared_statement(type, name, values)
291   prepared_sql, frags = Sequel::Dataset::PlaceholderLiteralizer::Recorder.new.send(:prepared_sql_and_frags, self, prepared_args) do |pl, ds|
292     ds = ds.clone(:recorder=>pl)
293 
294     case type
295     when :first, :single_value
296       ds.limit(1)
297     when :update, :insert, :insert_select, :delete
298       ds.with_sql(:"#{type}_sql", *values)
299     when :insert_pk
300       ds.with_sql(:insert_sql, *values)
301     else
302       ds
303     end
304   end
305 
306   prepared_args.freeze
307   clone(:prepared_sql_frags=>frags, :prepared_sql=>prepared_sql, :sql=>prepared_sql)
308 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
312 def prepared_arg(k)
313   prepared_args << k
314   @opts[:recorder].arg
315 end
subselect_sql_dataset(sql, ds) click to toggle source
Calls superclass method
    # File lib/sequel/dataset/prepared_statements.rb
317 def subselect_sql_dataset(sql, ds)
318   super.clone(:recorder=>@opts[:recorder]).
319     with_extend(EmulatePreparedStatementMethods)
320 end