Class: SqlStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_statement.rb

Direct Known Subclasses

Delete, Insert, Select, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sql) ⇒ SqlStatement

:nodoc:



5
6
7
# File 'lib/sql_statement.rb', line 5

def initialize(sql)  #:nodoc:
  @to_sql = sql
end

Instance Attribute Details

#tablesObject

Returns the value of attribute tables.



2
3
4
# File 'lib/sql_statement.rb', line 2

def tables
  @tables
end

#to_sqlObject (readonly)

Returns the value of attribute to_sql.



3
4
5
# File 'lib/sql_statement.rb', line 3

def to_sql
  @to_sql
end

Instance Method Details

#and(&block) ⇒ Object

call-seq: sql_statement.and { block } -> a_sql_statement

Creates a new AndWhereBuilder instance, passing the block as a parameter, then executes to_sql on the AndWhereBuilder instance. The resulting string from the AndWhereBuilder instance is appended to the SQL statement. Returns self.

Select[1].where { equal :column1, 1 }.and { equal :column2, 100 }.to_sql       #=> "select 1 where column1 = 1 and (column2 = 100)"


40
41
42
43
# File 'lib/sql_statement.rb', line 40

def and(&block)
  @to_sql += AndWhereBuilder.new(self.tables, &block).to_sql
  self
end

#and_with_or_conditions(&block) ⇒ Object

call-seq: sql_statement.and_with_or_conditions { block } -> a_sql_statement

Creates a new AndWithOrConditionsWhereBuilder instance, passing the block as a parameter, then executes to_sql on the AndWithOrConditionsWhereBuilder instance. The resulting string from the AndWithOrConditionsWhereBuilder instance is appended to the SQL statement. Returns self.

Select[1].where { equal :column1, 1 }.and_with_or_conditions { equal :column2, 100 }.to_sql       
  #=> "select 1 where column1 = 1 and (column2 = 100)"


54
55
56
57
# File 'lib/sql_statement.rb', line 54

def and_with_or_conditions(&block)
  @to_sql += AndWithOrConditionsWhereBuilder.new(self.tables, &block).to_sql
  self
end

#or(&block) ⇒ Object

call-seq: sql_statement.or { block } -> a_sql_statement

Creates a new OrWhereBuilder instance, passing the block as a parameter, then executes to_sql on the OrWhereBuilder instance. The resulting string from the OrWhereBuilder instance is appended to the SQL statement. Returns self.

Select[1].where { equal :column1, 1 }.or { equal :column1, 100 }.to_sql       #=> "select 1 where column1 = 1 or (column1 = 100)"


28
29
30
31
# File 'lib/sql_statement.rb', line 28

def or(&block)
  @to_sql += OrWhereBuilder.new(self.tables, &block).to_sql
  self
end

#where(&block) ⇒ Object

call-seq: sql_statement.where { block } -> a_sql_statement

Creates a new WhereBuilder instance, passing the block as a parameter, then executes to_sql on the WhereBuilder instance. The resulting string from the WhereBuilder instance is appended to the SQL statement. Returns self.

Select[1].where { equal :column1, 1 }.to_sql       #=> "select 1 where column1 = 1"


16
17
18
19
# File 'lib/sql_statement.rb', line 16

def where(&block)
  @to_sql += WhereBuilder.new(self.tables, &block).to_sql
  self
end