lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb in knjrbfw-0.0.23 vs lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb in knjrbfw-0.0.24

- old
+ new

@@ -1,12 +1,11 @@ class KnjDB_mysql::Columns - attr_reader :db, :driver + attr_reader :db def initialize(args) @args = args @db = @args[:db] - @driver = @args[:driver] end def data_sql(data) raise "No type given." if !data["type"] @@ -37,16 +36,21 @@ def initialize(args) @args = args end + #Used to validate in Knj::Wrap_map. + def __object_unique_id__ + return @args[:data][:Field] + end + def name return @args[:data][:Field] end def table - return @args[:db].tables[@args[:table_name]] + return @db.tables[@args[:table_name]] end def data return { "type" => self.type, @@ -110,25 +114,24 @@ def comment return @args[:data][:Comment] end def drop - @args[:db].query("ALTER TABLE `#{@args[:table_name]}` DROP COLUMN `#{self.name}`") + @db.query("ALTER TABLE `#{@args[:table_name]}` DROP COLUMN `#{self.name}`") end def change(data) - esc_col = @args[:driver].escape_col - col_escaped = "#{esc_col}#{@args[:db].esc_col(self.name)}#{esc_col}" - table_escape = "#{@args[:driver].escape_table}#{@args[:driver].esc_table(self.table.name)}#{@args[:driver].escape_table}" + col_escaped = "#{@db.enc_col}#{@db.esc_col(self.name)}#{@db.enc_col}" + table_escape = "#{@db.enc_table}#{@db.esc_table(self.table.name)}#{@db.enc_table}" newdata = data.clone newdata["name"] = self.name if !newdata.key?("name") newdata["type"] = self.type if !newdata.key?("type") newdata["maxlength"] = self.maxlength if !newdata.key?("maxlength") and self.maxlength newdata["null"] = self.null? if !newdata.key?("null") newdata["default"] = self.default if !newdata.key?("default") and self.default newdata.delete("primarykey") if newdata.key?("primarykey") type_s = newdata["type"].to_s - @args[:db].query("ALTER TABLE #{table_escape} CHANGE #{col_escaped} #{@args[:db].cols.data_sql(newdata)}") + @db.query("ALTER TABLE #{table_escape} CHANGE #{col_escaped} #{@db.cols.data_sql(newdata)}") end end \ No newline at end of file