lib/baza/driver/mysql/table.rb in baza-0.0.35 vs lib/baza/driver/mysql/table.rb in baza-0.0.36
- old
+ new
@@ -28,11 +28,11 @@
def drop
raise "Cant drop native table: '#{name}'" if native?
@db.with_database(database_name) do
- @db.query("DROP TABLE `#{@db.escape_table(name)}`")
+ @db.query("DROP TABLE #{@db.quote_table(name)}")
end
@tables.__send__(:remove_from_list, self)
nil
end
@@ -43,11 +43,11 @@
return true if data.fetch(:db) == "mysql"
false
end
def optimize
- @db.query("OPTIMIZE TABLE `#{@db.escape_table(name)}`")
+ @db.query("OPTIMIZE TABLE #{@db.quote_table(name)}")
self
end
def column(name)
name = name.to_s
@@ -63,11 +63,11 @@
end
def columns(args = nil)
@db.columns
ret = []
- sql = "SHOW FULL COLUMNS FROM `#{@db.escape_table(name)}`"
+ sql = "SHOW FULL COLUMNS FROM #{@db.quote_table(name)}"
sql << " WHERE `Field` = '#{@db.esc(args.fetch(:name))}'" if args && args.key?(:name)
@db.q(sql) do |d_cols|
column_name = d_cols.fetch(:Field)
obj = @list.get(name)
@@ -106,15 +106,15 @@
FROM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
- REFERENCED_TABLE_SCHEMA = '#{@db.escape_database(@db.current_database_name)}' AND
- TABLE_NAME = '#{@db.escape_table(name)}'
+ REFERENCED_TABLE_SCHEMA = #{@db.quote_value(@db.current_database_name)} AND
+ TABLE_NAME = #{@db.quote_value(name)}
"
- sql << " AND CONSTRAINT_NAME = '#{@db.escape(args.fetch(:name))}'" if args[:name]
+ sql << " AND CONSTRAINT_NAME = #{@db.quote_value(args.fetch(:name))}" if args[:name]
result = [] unless block_given?
@db.query(sql) do |data|
foreign_key = Baza::Driver::Mysql::ForeignKey.new(
@@ -141,12 +141,12 @@
end
def indexes(args = nil, &blk)
ret = {}
- sql = "SHOW INDEX FROM `#{@db.escape_table(name)}`"
- sql << " WHERE `Key_name` = '#{@db.esc(args.fetch(:name))}'" if args && args.key?(:name)
+ sql = "SHOW INDEX FROM #{@db.quote_table(name)}"
+ sql << " WHERE #{@db.quote_column("Key_name")} = #{@db.quote_value(args.fetch(:name))}" if args && args.key?(:name)
@db.query(sql) do |d_indexes|
next if d_indexes[:Key_name] == "PRIMARY"
index_name = d_indexes.fetch(:Key_name)
@@ -216,24 +216,24 @@
sql << ", "
end
end
sql << " UNIQUE" if index_data[:unique]
- sql << " INDEX #{db.sep_index}#{db.escape_index(index_data.fetch(:name))}#{db.sep_index}"
+ sql << " INDEX #{db.quote_index(index_data.fetch(:name))}"
if args[:on_table] || !args.key?(:on_table)
- sql << " ON #{db.sep_table}#{db.escape_table(args.fetch(:table_name))}#{db.sep_table}"
+ sql << " ON #{db.quote_table(args.fetch(:table_name))}"
end
sql << " ("
first = true
index_data[:columns].each do |col_name|
sql << ", " unless first
first = false if first
- sql << "#{db.sep_col}#{db.escape_column(col_name)}#{db.sep_col}"
+ sql << db.quote_column(col_name)
end
sql << ")"
db.query(sql) unless args[:return_sql]
@@ -245,11 +245,11 @@
def rename(newname)
newname = newname.to_s
oldname = name
@tables.__send__(:remove_from_list, self)
- @db.query("ALTER TABLE `#{@db.escape_table(oldname)}` RENAME TO `#{@db.escape_table(newname)}`")
+ @db.query("ALTER TABLE #{@db.quote_table(oldname)} RENAME TO #{@db.quote_table(newname)}")
@data[:name] = newname
@name = newname
@tables.__send__(:add_to_list, self)
@@ -281,11 +281,11 @@
end
def clone(newname, args = {})
raise "Invalid name." if newname.to_s.strip.empty?
- sql = "CREATE TABLE #{@db.sep_table}#{@db.escape_table(newname)}#{@db.sep_table} ("
+ sql = "CREATE TABLE #{@db.quote_table(newname)} ("
first = true
pkey_found = false
pkeys = []
columns do |col|
@@ -314,11 +314,11 @@
first = true
pkeys.each do |pkey|
sql << ", " unless first
first = false if first
- sql << "#{@db.sep_col}#{@db.escape_column(pkey)}#{@db.sep_col}"
+ sql << @db.quote_column(pkey)
end
sql << ")"
end
@@ -330,11 +330,11 @@
# Create table.
@db.query(sql)
# Insert data of previous data in a single query.
- @db.query("INSERT INTO #{@db.sep_table}#{@db.escape_table(newname)}#{@db.sep_table} SELECT * FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}")
+ @db.query("INSERT INTO #{@db.quote_table(newname)} SELECT * FROM #{@db.quote_table(name)}")
# Create indexes.
new_table = @db.tables[newname]
indexes_list = []
@@ -355,10 +355,10 @@
end
# Changes the engine for a table.
def engine=(newengine)
raise "Invalid engine: '#{newengine}'." unless newengine.to_s =~ /^[A-z]+$/
- @db.query("ALTER TABLE `#{@db.escape_table(name)}` ENGINE = #{newengine}") if engine.to_s != newengine.to_s
+ @db.query("ALTER TABLE #{@db.quote_table(name)} ENGINE = #{newengine}") if engine.to_s != newengine.to_s
@data[:ENGINE] = newengine
end
private