Module: Predicate::In

Defined in:
lib/bmg/sql/ext/predicate/in.rb

Instance Method Summary collapse

Instance Method Details

#subqueryObject



8
9
10
# File 'lib/bmg/sql/ext/predicate/in.rb', line 8

def subquery
  subquery? ? last : nil
end

#subquery?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/bmg/sql/ext/predicate/in.rb', line 4

def subquery?
  Sql::Expr === last
end

#to_sql(buffer, dialect) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bmg/sql/ext/predicate/in.rb', line 12

def to_sql(buffer, dialect)
  identifier.to_sql(buffer, dialect)
  buffer << Sql::Expr::SPACE << Sql::Expr::IN << Sql::Expr::SPACE
  if subquery?
    values.to_sql(buffer, dialect)
  else
    buffer << Sql::Expr::LEFT_PARENTHESE
    values.each_with_index do |val,index|
      buffer << Sql::Expr::COMMA << Sql::Expr::SPACE unless index==0
      to_sql_literal(buffer, val)
    end
    buffer << Sql::Expr::RIGHT_PARENTHESE
  end
  buffer
end