Class: DbDiff::Delta::ModifyRow
Instance Attribute Summary
#element
Instance Method Summary
collapse
#initialize, #table, #to_a
Constructor Details
This class inherits a constructor from DbDiff::Delta
Instance Method Details
#process(database) ⇒ Object
93
94
95
96
97
98
|
# File 'lib/dbdiff/delta.rb', line 93
def process(database)
table = table(database)
old_row = table.rows.find{|r| r.name == element.name}
table.rows.delete(old_row)
table.rows << element
end
|
#sql ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/dbdiff/delta.rb', line 75
def sql
data = element.data
where = element.primary_key.map {|k| "#{k}=" + Mysql.escape_string(data[k]) }.join(" AND ")
sql = "UPDATE #{element.table_name} SET "
updates = data.keys.map do |c|
if data[c]
" #{c}='" + Mysql.escape_string(data[c]) + "'"
else
" #{c}= NULL"
end
end
sql += updates.join(",") + " WHERE #{where}"
return sql
end
|