Class Update
In: lib/update.rb
Parent: SqlStatement

Methods

[]   []   set  

Public Class methods

Returns an Update instance with the SQL initialized to ‘update [table] ‘

   Update[:table1].to_sql       #=> "update table1"

[Source]

    # File lib/update.rb, line 8
 8:     def [](table)
 9:       update = self.new("update #{table.to_sql}")
10:       update.tables = [table]
11:       update
12:     end

Public Instance methods

Returns an Update instance with the set values appended to the SQL statement.

   update = Update[:table1].set[:column1=>'book', :column2=>10]
   update.to_sql       #=> "update table1 set column1 = 'book, column2 = 10"

[Source]

    # File lib/update.rb, line 30
30:   def [](hash)
31:     @to_sql += " set "
32:     set_args = []
33:     hash.each_pair do |col, val|
34:       set_args << "#{col.to_sql}=#{val.to_sql}"
35:     end
36:     @to_sql += set_args.sort.join(', ')
37:     self
38:   end

Returns self. Unnecessary and only available to mimic SQL statements.

   Update[:table1].set.to_sql       #=> "update table1"

[Source]

    # File lib/update.rb, line 20
20:   def set
21:     self
22:   end

[Validate]