module Sequel::Postgres::AutoParameterize::DatasetMethods

Public Instance Methods

cast_sql_append(sql, expr, type) click to toggle source

Do not add implicit typecasts for directly typecasted values, since the user is presumably doing so to set the type, not convert from the implicitly typecasted type.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
258 def cast_sql_append(sql, expr, type)
259   if auto_param?(sql) && auto_param_type(expr)
260     sql << 'CAST('
261     sql.add_arg(expr)
262     sql << ' AS ' << db.cast_type_literal(type).to_s << ')'
263   else
264     super
265   end
266 end
complex_expression_sql_append(sql, op, args) click to toggle source

Transform column IN (int, …) expressions into column = ANY($) and column NOT IN (int, …) expressions into column != ALL($) using an integer array bound variable for the ANY/ALL argument. This is the same optimization PostgreSQL performs internally, but this reduces the number of bound variables.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
273 def complex_expression_sql_append(sql, op, args)
274   case op
275   when :IN, :"NOT IN"
276     l, r = args
277     if auto_param?(sql) && !l.is_a?(Array) && _integer_array?(r) && r.size > 1
278       if op == :IN 
279         op = :"="
280         func = :ANY
281       else
282         op = :!=
283         func = :ALL
284       end
285       args = [l, Sequel.function(func, Sequel.cast(_integer_array_auto_param(r), 'int8[]'))]
286     end
287   end
288 
289   super
290 end
literal_append(sql, v) click to toggle source

For strings, numeric arguments, and date/time arguments, add them as parameters to the query instead of literalizing them into the SQL.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
304 def literal_append(sql, v)
305   if auto_param?(sql) && (type = auto_param_type(v))
306     sql.add_arg(v) << type
307   else
308     super
309   end
310 end
multi_insert_sql(columns, values) click to toggle source

Parameterize insertion of multiple values

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
293 def multi_insert_sql(columns, values)
294   if @opts[:no_auto_parameterize]
295     super
296   else
297     [clone(:multi_insert_values=>values.map{|r| Array(r)}).insert_sql(columns, LiteralString.new('VALUES '))]
298   end
299 end
no_auto_parameterize() click to toggle source

Return a clone of the dataset that will not do automatic parameterization.

    # File lib/sequel/extensions/pg_auto_parameterize.rb
249 def no_auto_parameterize
250   cached_dataset(:_no_auto_parameterize_ds) do
251     @opts[:no_auto_parameterize] ? self : clone(:no_auto_parameterize=>true)
252   end
253 end
placeholder_literalizer_class() click to toggle source

The class to use for placeholder literalizers.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
313 def placeholder_literalizer_class
314   if @opts[:no_auto_parameterize]
315     super
316   else
317     PlaceholderLiteralizer
318   end
319 end
use_cursor(*) click to toggle source

Disable automatic parameterization when using a cursor.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
322 def use_cursor(*)
323   super.no_auto_parameterize
324 end
with_sql(*a) click to toggle source

Store receiving dataset and args when with_sql is used with a method name symbol, so sql can be parameterized correctly if used as a subselect.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
328 def with_sql(*a)
329   ds = super 
330   if Symbol === a[0]
331     ds = ds.clone(:with_sql_dataset=>self, :with_sql_args=>a.freeze)
332   end
333   ds
334 end

Protected Instance Methods

to_prepared_statement(*a) click to toggle source

Disable automatic parameterization for prepared statements, since they will use manual parameterization.

Calls superclass method
    # File lib/sequel/extensions/pg_auto_parameterize.rb
340 def to_prepared_statement(*a)
341   @opts[:no_auto_parameterize] ? super : no_auto_parameterize.to_prepared_statement(*a)
342 end