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 288 def run(&block) 289 if @opts[:prepared_sql_frags] 290 sql = literal(Sequel::SQL::PlaceholderLiteralString.new(@opts[:prepared_sql_frags], @opts[:bind_arguments], false)) 291 clone(:prepared_sql_frags=>nil, :sql=>sql, :prepared_sql=>sql).run(&block) 292 else 293 super 294 end 295 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 301 def emulate_prepared_statements? 302 true 303 end
emulated_prepared_statement(type, name, values)
click to toggle source
# File lib/sequel/dataset/prepared_statements.rb 305 def emulated_prepared_statement(type, name, values) 306 prepared_sql, frags = Sequel::Dataset::PlaceholderLiteralizer::Recorder.new.send(:prepared_sql_and_frags, self, prepared_args) do |pl, ds| 307 ds = ds.clone(:recorder=>pl) 308 309 sql_type = prepared_sql_type || type 310 case sql_type 311 when :first, :single_value 312 ds.limit(1) 313 when :update, :insert, :insert_select, :delete 314 ds.with_sql(:"#{sql_type}_sql", *values) 315 when :insert_pk 316 ds.with_sql(:insert_sql, *values) 317 else 318 ds 319 end 320 end 321 322 prepared_args.freeze 323 clone(:prepared_sql_frags=>frags, :prepared_sql=>prepared_sql, :sql=>prepared_sql) 324 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 328 def prepared_arg(k) 329 prepared_args << k 330 @opts[:recorder].arg 331 end
subselect_sql_dataset(sql, ds)
click to toggle source
Calls superclass method
# File lib/sequel/dataset/prepared_statements.rb 333 def subselect_sql_dataset(sql, ds) 334 super.clone(:recorder=>@opts[:recorder]). 335 with_extend(EmulatePreparedStatementMethods) 336 end