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