Class: DbDiff::Delta::AddRow

Inherits:
DbDiff::Delta show all
Defined in:
lib/dbdiff/delta.rb

Instance Attribute Summary

Attributes inherited from DbDiff::Delta

#element

Instance Method Summary collapse

Methods inherited from DbDiff::Delta

#initialize, #table, #to_a

Constructor Details

This class inherits a constructor from DbDiff::Delta

Instance Method Details

#process(database) ⇒ Object



124
125
126
127
128
# File 'lib/dbdiff/delta.rb', line 124

def process(database)
  table = table(database)
  table.rows.delete(element)
  table.rows << element # XXX test this to make sure modifys work
end

#sqlObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dbdiff/delta.rb', line 104

def sql
  sql = "INSERT INTO #{element.table_name}"
  data = element.data
  columns = data.keys

  sql += " (" + columns.join(",") + ")"

  values = columns.map do |c|
    if data[c]
      "'" + Mysql.escape_string(data[c]) + "'"
    else
      "NULL"
    end
  end

  sql += " VALUES (" + values.join(",") + ")"
  
  return sql
end