class Sequel::Dataset::PlaceholderLiteralizer::Recorder
Records the offsets at which the placeholder arguments are used in the SQL
query.
Public Instance Methods
arg(v=(no_arg_given = true; @argn+=1))
click to toggle source
Return an Argument
with the specified position, or the next position. In general you shouldn't mix calls with an argument and calls without an argument for the same receiver.
# File lib/sequel/dataset/placeholder_literalizer.rb 102 def arg(v=(no_arg_given = true; @argn+=1)) 103 unless no_arg_given 104 @argn = v if @argn < v 105 end 106 Argument.new(self, v) 107 end
loader(dataset) { |self, dataset| ... }
click to toggle source
Yields the receiver and the dataset to the block, which should call arg
on the receiver for each placeholder argument, and return the dataset that you want to load.
# File lib/sequel/dataset/placeholder_literalizer.rb 80 def loader(dataset) 81 @argn = -1 82 @args = [] 83 ds = yield self, dataset 84 sql = ds.clone(:placeholder_literalizer=>self).sql 85 86 last_offset = 0 87 fragments = @args.map do |used_sql, offset, arg, t| 88 raise Error, "placeholder literalizer argument literalized into different string than dataset returned" unless used_sql.equal?(sql) 89 a = [sql[last_offset...offset], arg, t] 90 last_offset = offset 91 a 92 end 93 final_sql = sql[last_offset..-1] 94 95 arity = @argn+1 96 PlaceholderLiteralizer.new(ds.clone, fragments, final_sql, arity) 97 end
use(sql, arg, transformer)
click to toggle source
Record the offset at which the argument is used in the SQL
query, and any transforming block.
# File lib/sequel/dataset/placeholder_literalizer.rb 111 def use(sql, arg, transformer) 112 @args << [sql, sql.length, arg, transformer] 113 end