class Sequel::Postgres::AutoParameterize::QueryString
SQL query string that also holds an array of parameters
Attributes
The array of parameters used by this query.
Public Instance Methods
Return a new QueryString with the given string appended to the receiver, and the same arguments.
# 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 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
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 the stored arguments when freezing the query string.
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 149 def freeze if @args @args.freeze @arg_map.freeze end super end
# 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
Show args when the query string is inspected
# File lib/sequel/extensions/pg_auto_parameterize.rb, line 158 def inspect @args ? "#{self}; #{@args.inspect}".inspect : super end
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