Class: Sequel::SQL::PlaceholderLiteralString

Inherits:
GenericExpression show all
Defined in:
lib/sequel/sql.rb

Overview

Represents a literal string with placeholders and arguments. This is necessary to ensure delayed literalization of the arguments required for the prepared statement support and for database-specific literalization.

Direct Known Subclasses

Postgres::PGRowOp

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Postgres::HStoreOpMethods

#hstore

Methods included from Postgres::RangeOpMethods

#pg_range

Methods included from Postgres::ArrayOpMethods

#pg_array

Methods included from Postgres::JSONOpMethods

#pg_json, #pg_jsonb

Methods included from Postgres::InetOpMethods

#pg_inet

Methods included from Postgres::PGRowOp::ExpressionMethods

#pg_row

Methods included from SubscriptMethods

#sql_subscript

Methods included from StringMethods

#ilike, #like

Methods included from PatternMatchMethods

#!~, #=~

Methods included from OrderMethods

#asc, #desc

Methods included from NumericMethods

#+, #coerce

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from BooleanMethods

#~

Methods included from AliasMethods

#as

Methods inherited from Expression

#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect

Constructor Details

#initialize(str, args, parens = false) ⇒ PlaceholderLiteralString

Create an object with the given string, placeholder arguments, and parens flag.


1558
1559
1560
1561
1562
1563
# File 'lib/sequel/sql.rb', line 1558

def initialize(str, args, parens=false)
  @str = str
  @args = args.is_a?(Array) && args.length == 1 && (v = args[0]).is_a?(Hash) ? v : args
  @parens = parens
  freeze
end

Instance Attribute Details

#argsObject (readonly)

The arguments that will be subsituted into the placeholders. Either an array of unnamed placeholders (which will be substituted in order for ? characters), or a hash of named placeholders (which will be substituted for :key phrases).


1552
1553
1554
# File 'lib/sequel/sql.rb', line 1552

def args
  @args
end

#parensObject (readonly)

Whether to surround the expression with parantheses


1555
1556
1557
# File 'lib/sequel/sql.rb', line 1555

def parens
  @parens
end

#strObject (readonly)

The literal string containing placeholders. This can also be an array of strings, where each arg in args goes between the string elements.


1546
1547
1548
# File 'lib/sequel/sql.rb', line 1546

def str
  @str
end

Instance Method Details

#with_parensObject

Return a copy of the that will be surrounded by parantheses.


1566
1567
1568
# File 'lib/sequel/sql.rb', line 1566

def with_parens
  @parens ? self : self.class.new(@str, @args, true)
end