class Sequel::Postgres::AutoParameterize::QueryString

SQL query string that also holds an array of parameters

Attributes

args[R]

The array of parameters used by this query.

Public Instance Methods

+(other) click to toggle source

Return a new QueryString with the given string appended to the receiver, and the same arguments.

Calls superclass method
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 121
def +(other)
  v = self.class.new(super)
  v.instance_variable_set(:@args, @args) if @args
  v
end
add_arg(s) click to toggle source

Add a new parameter to this query, which adds the parameter to the array of parameters, and an SQL placeholder to the query itself.

# File lib/sequel/extensions/pg_auto_parameterize.rb, line 105
def add_arg(s)
  unless defined?(@args)
    @args = []
    @arg_map = {}
    @arg_map.compare_by_identity
  end

  unless pos = @arg_map[s]
    @args << s
    pos = @arg_map[s] = @args.length.to_s
  end
  self << '$' << pos
end
auto_param?() click to toggle source

Whether this query string currently supports automatic parameterization. Automatic parameterization is disabled at certain points during query building where PostgreSQL does not support it.

# File lib/sequel/extensions/pg_auto_parameterize.rb, line 131
def auto_param?
  !@skip_auto_param
end
freeze() click to toggle source

Freeze the stored arguments when freezing the query string.

Calls superclass method
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 149
def freeze
  if @args
    @args.freeze
    @arg_map.freeze
  end
  super
end
initialize_copy(other) click to toggle source
Calls superclass method
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 162
def initialize_copy(other)
  super
  if args = other.instance_variable_get(:@args)
    @args = args.dup
    @arg_map = other.instance_variable_get(:@arg_map).dup
  end
end
inspect() click to toggle source

Show args when the query string is inspected

Calls superclass method
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 158
def inspect
  @args ? "#{self}; #{@args.inspect}".inspect : super
end
skip_auto_param() { || ... } click to toggle source

Skip automatic parameterization inside the passed block. This is used during query generation to disable automatic parameterization for clauses not supporting it.

# File lib/sequel/extensions/pg_auto_parameterize.rb, line 138
def skip_auto_param
  skip_auto_param = @skip_auto_param
  begin
    @skip_auto_param = true
    yield
  ensure
    @skip_auto_param = skip_auto_param
  end
end