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