baza 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +14 -17
  4. data/VERSION +1 -1
  5. data/baza.gemspec +8 -7
  6. data/lib/baza/base_sql_driver.rb +38 -8
  7. data/lib/baza/cloner.rb +10 -0
  8. data/lib/baza/commands/select.rb +15 -8
  9. data/lib/baza/db.rb +8 -4
  10. data/lib/baza/driver/active_record.rb +7 -0
  11. data/lib/baza/driver/mysql/column.rb +4 -6
  12. data/lib/baza/driver/mysql/columns.rb +4 -4
  13. data/lib/baza/driver/mysql/database.rb +4 -4
  14. data/lib/baza/driver/mysql/databases.rb +3 -3
  15. data/lib/baza/driver/mysql/foreign_key.rb +2 -2
  16. data/lib/baza/driver/mysql/index.rb +1 -1
  17. data/lib/baza/driver/mysql/sql/column.rb +4 -4
  18. data/lib/baza/driver/mysql/sql/create_indexes.rb +3 -3
  19. data/lib/baza/driver/mysql/sql/create_table.rb +1 -1
  20. data/lib/baza/driver/mysql/table.rb +16 -16
  21. data/lib/baza/driver/mysql_java.rb +3 -3
  22. data/lib/baza/driver/pg/column.rb +5 -13
  23. data/lib/baza/driver/pg/columns.rb +4 -4
  24. data/lib/baza/driver/pg/create_index_sql_creator.rb +3 -3
  25. data/lib/baza/driver/pg/database.rb +4 -4
  26. data/lib/baza/driver/pg/databases.rb +1 -1
  27. data/lib/baza/driver/pg/foreign_key.rb +2 -2
  28. data/lib/baza/driver/pg/index.rb +1 -1
  29. data/lib/baza/driver/pg/table.rb +9 -9
  30. data/lib/baza/driver/pg/tables.rb +1 -1
  31. data/lib/baza/driver/sqlite3/column.rb +1 -1
  32. data/lib/baza/driver/sqlite3/columns.rb +1 -1
  33. data/lib/baza/driver/sqlite3/index.rb +1 -1
  34. data/lib/baza/driver/sqlite3/table.rb +4 -4
  35. data/lib/baza/driver/tiny.rb +83 -8
  36. data/lib/baza/driver/tiny/result.rb +18 -2
  37. data/lib/baza/idquery.rb +3 -3
  38. data/lib/baza/mysql_base_driver.rb +3 -3
  39. data/lib/baza/sql_queries/generic_insert.rb +3 -3
  40. data/lib/baza/sql_queries/generic_update.rb +2 -2
  41. data/lib/baza/sql_queries/mysql_upsert.rb +5 -5
  42. data/lib/baza/sql_queries/mysql_upsert_duplicate_key.rb +3 -3
  43. data/lib/baza/sql_queries/postgres_upsert_duplicate_key.rb +7 -7
  44. data/lib/baza/sql_queries/select.rb +8 -8
  45. data/lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb +6 -6
  46. data/lib/baza/table.rb +3 -3
  47. data/spec/baza/cloner_spec.rb +2 -2
  48. data/spec/drivers/tiny_spec.rb +27 -0
  49. data/spec/info_active_record_pg_peak_flow.rb +2 -2
  50. data/spec/info_active_record_sqlite3.rb +6 -13
  51. data/spec/info_sqlite3.rb +3 -12
  52. metadata +8 -7
@@ -5,7 +5,7 @@ class Baza::Driver::Mysql::Database < Baza::Database
5
5
  end
6
6
 
7
7
  def drop
8
- sql = "DROP DATABASE `#{@db.escape_database(name)}`"
8
+ sql = "DROP DATABASE #{@db.quote_database(name)}"
9
9
  @db.query(sql)
10
10
  self
11
11
  end
@@ -17,7 +17,7 @@ class Baza::Driver::Mysql::Database < Baza::Database
17
17
 
18
18
  sql = "CREATE"
19
19
  sql << " TEMPORARY" if data[:temp]
20
- sql << " TABLE #{db.sep_table}#{@db.escape_table(name)}#{db.sep_table} ("
20
+ sql << " TABLE #{@db.quote_table(name)} ("
21
21
 
22
22
  first = true
23
23
  data[:columns].each do |col_data|
@@ -66,10 +66,10 @@ private
66
66
  @db.databases.create(name: new_name)
67
67
 
68
68
  tables.each do |table|
69
- @db.query("ALTER TABLE `#{@db.escape_database(name_was)}`.`#{@db.escape_table(table.name)}` RENAME `#{@db.escape_database(name)}`.`#{@db.escape_table(table.name)}`")
69
+ @db.query("ALTER TABLE #{@db.quote_database(name_was)}.#{@db.quote_table(table.name)} RENAME #{@db.quote_database(name)}.#{@db.quote_table(table.name)}")
70
70
  end
71
71
 
72
- @db.query("DROP DATABASE `#{@db.escape_database(name_was)}`")
72
+ @db.query("DROP DATABASE #{@db.quote_database(name_was)}")
73
73
 
74
74
  @name = new_name
75
75
  @name_was = new_name
@@ -6,7 +6,7 @@ class Baza::Driver::Mysql::Databases
6
6
  def create(args)
7
7
  sql = "CREATE DATABASE"
8
8
  sql << " IF NOT EXISTS" if args[:if_not_exists]
9
- sql << " #{@db.sep_database}#{@db.escape_table(args.fetch(:name))}#{@db.sep_database}"
9
+ sql << " #{@db.quote_table(args.fetch(:name))}"
10
10
 
11
11
  @db.query(sql)
12
12
  true
@@ -40,13 +40,13 @@ class Baza::Driver::Mysql::Databases
40
40
  end
41
41
 
42
42
  previous_db_name = @db.current_database_name
43
- @db.query("USE #{@db.sep_database}#{@db.escape_database(name)}#{@db.sep_database}")
43
+ @db.query("USE #{@db.quote_database(name)}")
44
44
 
45
45
  if block_given?
46
46
  begin
47
47
  yield
48
48
  ensure
49
- @db.query("USE #{@db.sep_database}#{@db.escape_database(previous_db_name)}#{@db.sep_database}")
49
+ @db.query("USE #{@db.quote_database(previous_db_name)}")
50
50
  end
51
51
  end
52
52
 
@@ -11,8 +11,8 @@ class Baza::Driver::Mysql::ForeignKey < Baza::ForeignKey
11
11
 
12
12
  def drop
13
13
  @db.query("
14
- ALTER TABLE `#{@db.escape_table(table_name)}`
15
- DROP FOREIGN KEY `#{@db.escape_table(name)}`
14
+ ALTER TABLE #{@db.quote_table(table_name)}
15
+ DROP FOREIGN KEY #{@db.quote_table(name)}
16
16
  ")
17
17
  true
18
18
  end
@@ -70,7 +70,7 @@ class Baza::Driver::Mysql::Index < Baza::Index
70
70
  end
71
71
 
72
72
  def reload
73
- data = @db.query("SHOW INDEX FROM `#{@db.escape_table(@table_name)}` WHERE `Key_name` = '#{@db.esc(name)}'").fetch
73
+ data = @db.query("SHOW INDEX FROM #{@db.quote_table(@table_name)} WHERE #{@db.quote_column("Key_name")} = #{@db.quote_value(name)}").fetch
74
74
  raise Baza::Errors::IndexNotFound unless data
75
75
  @data = data
76
76
  self
@@ -17,7 +17,7 @@ class Baza::Driver::Mysql::Sql::Column
17
17
 
18
18
  data[:maxlength] = 255 if type == :varchar && data[:maxlength].to_s.strip.empty?
19
19
 
20
- sql = "#{Baza::Driver::Mysql::SEPARATOR_COLUMN}#{Baza::Driver::Mysql.escape_column(data.fetch(:name))}#{Baza::Driver::Mysql::SEPARATOR_COLUMN} #{type}"
20
+ sql = "#{Baza::Driver::Mysql.quote_column(data.fetch(:name))} #{type}"
21
21
  sql << "(#{data[:maxlength]})" if data[:maxlength]
22
22
  sql << " PRIMARY KEY" if data[:primarykey]
23
23
  sql << " AUTO_INCREMENT" if data[:autoincr]
@@ -26,11 +26,11 @@ class Baza::Driver::Mysql::Sql::Column
26
26
  if data.key?(:default_func)
27
27
  sql << " DEFAULT #{data[:default_func]}"
28
28
  elsif data.key?(:default) && !data[:default].nil?
29
- sql << " DEFAULT #{Baza::Driver::Mysql.sqlval(data.fetch(:default))}"
29
+ sql << " DEFAULT #{Baza::Driver::Mysql.quote_value(data.fetch(:default))}"
30
30
  end
31
31
 
32
- sql << " COMMENT '#{Baza::Driver::Mysql.escape(data.fetch(:comment))}'" if data.key?(:comment)
33
- sql << " AFTER #{Baza::Driver::Mysql::SEPARATOR_COLUMN}#{Baza::Driver::Mysql.escape_column(data.fetch(:after))}#{Baza::Driver::Mysql::SEPARATOR_COLUMN}" if data[:after] && !data[:first]
32
+ sql << " COMMENT #{Baza::Driver::Mysql.quote_value(data.fetch(:comment))}" if data.key?(:comment)
33
+ sql << " AFTER #{Baza::Driver::Mysql.quote_column(data.fetch(:after))}" if data[:after] && !data[:first]
34
34
  sql << " FIRST" if data[:first]
35
35
  sql << " STORAGE #{data[:storage].to_s.upcase}" if data[:storage]
36
36
 
@@ -27,10 +27,10 @@ class Baza::Driver::Mysql::Sql::CreateIndexes
27
27
  end
28
28
 
29
29
  sql << " UNIQUE" if index_data[:unique]
30
- sql << " INDEX #{Baza::Driver::Mysql::SEPARATOR_INDEX}#{Baza::Driver::Mysql.escape_index(index_data.fetch(:name))}#{Baza::Driver::Mysql::SEPARATOR_INDEX}"
30
+ sql << " INDEX #{Baza::Driver::Mysql.quote_index(index_data.fetch(:name))}"
31
31
 
32
32
  if @on_table || @on_table.nil?
33
- sql << " ON #{Baza::Driver::Mysql::SEPARATOR_TABLE}#{Baza::Driver::Mysql.escape_table(@table_name)}#{Baza::Driver::Mysql::SEPARATOR_TABLE}"
33
+ sql << " ON #{Baza::Driver::Mysql.quote_table(@table_name)}"
34
34
  end
35
35
 
36
36
  sql << " ("
@@ -40,7 +40,7 @@ class Baza::Driver::Mysql::Sql::CreateIndexes
40
40
  sql << ", " unless first
41
41
  first = false if first
42
42
 
43
- sql << "#{Baza::Driver::Mysql::SEPARATOR_COLUMN}#{Baza::Driver::Mysql.escape_column(col_name)}#{Baza::Driver::Mysql::SEPARATOR_COLUMN}"
43
+ sql << Baza::Driver::Mysql.quote_column(col_name)
44
44
  end
45
45
 
46
46
  sql << ")"
@@ -9,7 +9,7 @@ class Baza::Driver::Mysql::Sql::CreateTable
9
9
  def sql
10
10
  sql = "CREATE"
11
11
  sql << " TEMPORARY" if @temporary
12
- sql << " TABLE #{Baza::Driver::Mysql::SEPARATOR_TABLE}#{Baza::Driver::Mysql.escape_table(@name)}#{Baza::Driver::Mysql::SEPARATOR_TABLE} ("
12
+ sql << " TABLE #{Baza::Driver::Mysql.quote_table(@name)} ("
13
13
 
14
14
  first = true
15
15
  @columns.each do |col_data|
@@ -30,7 +30,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
30
30
  raise "Cant drop native table: '#{name}'" if native?
31
31
 
32
32
  @db.with_database(database_name) do
33
- @db.query("DROP TABLE `#{@db.escape_table(name)}`")
33
+ @db.query("DROP TABLE #{@db.quote_table(name)}")
34
34
  end
35
35
 
36
36
  @tables.__send__(:remove_from_list, self)
@@ -45,7 +45,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
45
45
  end
46
46
 
47
47
  def optimize
48
- @db.query("OPTIMIZE TABLE `#{@db.escape_table(name)}`")
48
+ @db.query("OPTIMIZE TABLE #{@db.quote_table(name)}")
49
49
  self
50
50
  end
51
51
 
@@ -65,7 +65,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
65
65
  def columns(args = nil)
66
66
  @db.columns
67
67
  ret = []
68
- sql = "SHOW FULL COLUMNS FROM `#{@db.escape_table(name)}`"
68
+ sql = "SHOW FULL COLUMNS FROM #{@db.quote_table(name)}"
69
69
  sql << " WHERE `Field` = '#{@db.esc(args.fetch(:name))}'" if args && args.key?(:name)
70
70
 
71
71
  @db.q(sql) do |d_cols|
@@ -108,11 +108,11 @@ class Baza::Driver::Mysql::Table < Baza::Table
108
108
  INFORMATION_SCHEMA.KEY_COLUMN_USAGE
109
109
 
110
110
  WHERE
111
- REFERENCED_TABLE_SCHEMA = '#{@db.escape_database(@db.current_database_name)}' AND
112
- TABLE_NAME = '#{@db.escape_table(name)}'
111
+ REFERENCED_TABLE_SCHEMA = #{@db.quote_value(@db.current_database_name)} AND
112
+ TABLE_NAME = #{@db.quote_value(name)}
113
113
  "
114
114
 
115
- sql << " AND CONSTRAINT_NAME = '#{@db.escape(args.fetch(:name))}'" if args[:name]
115
+ sql << " AND CONSTRAINT_NAME = #{@db.quote_value(args.fetch(:name))}" if args[:name]
116
116
 
117
117
  result = [] unless block_given?
118
118
 
@@ -143,8 +143,8 @@ class Baza::Driver::Mysql::Table < Baza::Table
143
143
  def indexes(args = nil, &blk)
144
144
  ret = {}
145
145
 
146
- sql = "SHOW INDEX FROM `#{@db.escape_table(name)}`"
147
- sql << " WHERE `Key_name` = '#{@db.esc(args.fetch(:name))}'" if args && args.key?(:name)
146
+ sql = "SHOW INDEX FROM #{@db.quote_table(name)}"
147
+ sql << " WHERE #{@db.quote_column("Key_name")} = #{@db.quote_value(args.fetch(:name))}" if args && args.key?(:name)
148
148
 
149
149
  @db.query(sql) do |d_indexes|
150
150
  next if d_indexes[:Key_name] == "PRIMARY"
@@ -218,10 +218,10 @@ class Baza::Driver::Mysql::Table < Baza::Table
218
218
  end
219
219
 
220
220
  sql << " UNIQUE" if index_data[:unique]
221
- sql << " INDEX #{db.sep_index}#{db.escape_index(index_data.fetch(:name))}#{db.sep_index}"
221
+ sql << " INDEX #{db.quote_index(index_data.fetch(:name))}"
222
222
 
223
223
  if args[:on_table] || !args.key?(:on_table)
224
- sql << " ON #{db.sep_table}#{db.escape_table(args.fetch(:table_name))}#{db.sep_table}"
224
+ sql << " ON #{db.quote_table(args.fetch(:table_name))}"
225
225
  end
226
226
 
227
227
  sql << " ("
@@ -231,7 +231,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
231
231
  sql << ", " unless first
232
232
  first = false if first
233
233
 
234
- sql << "#{db.sep_col}#{db.escape_column(col_name)}#{db.sep_col}"
234
+ sql << db.quote_column(col_name)
235
235
  end
236
236
 
237
237
  sql << ")"
@@ -247,7 +247,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
247
247
  oldname = name
248
248
 
249
249
  @tables.__send__(:remove_from_list, self)
250
- @db.query("ALTER TABLE `#{@db.escape_table(oldname)}` RENAME TO `#{@db.escape_table(newname)}`")
250
+ @db.query("ALTER TABLE #{@db.quote_table(oldname)} RENAME TO #{@db.quote_table(newname)}")
251
251
 
252
252
  @data[:name] = newname
253
253
  @name = newname
@@ -283,7 +283,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
283
283
  def clone(newname, args = {})
284
284
  raise "Invalid name." if newname.to_s.strip.empty?
285
285
 
286
- sql = "CREATE TABLE #{@db.sep_table}#{@db.escape_table(newname)}#{@db.sep_table} ("
286
+ sql = "CREATE TABLE #{@db.quote_table(newname)} ("
287
287
  first = true
288
288
  pkey_found = false
289
289
  pkeys = []
@@ -316,7 +316,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
316
316
  pkeys.each do |pkey|
317
317
  sql << ", " unless first
318
318
  first = false if first
319
- sql << "#{@db.sep_col}#{@db.escape_column(pkey)}#{@db.sep_col}"
319
+ sql << @db.quote_column(pkey)
320
320
  end
321
321
 
322
322
  sql << ")"
@@ -332,7 +332,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
332
332
 
333
333
 
334
334
  # Insert data of previous data in a single query.
335
- @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}")
335
+ @db.query("INSERT INTO #{@db.quote_table(newname)} SELECT * FROM #{@db.quote_table(name)}")
336
336
 
337
337
 
338
338
  # Create indexes.
@@ -357,7 +357,7 @@ class Baza::Driver::Mysql::Table < Baza::Table
357
357
  # Changes the engine for a table.
358
358
  def engine=(newengine)
359
359
  raise "Invalid engine: '#{newengine}'." unless newengine.to_s =~ /^[A-z]+$/
360
- @db.query("ALTER TABLE `#{@db.escape_table(name)}` ENGINE = #{newengine}") if engine.to_s != newengine.to_s
360
+ @db.query("ALTER TABLE #{@db.quote_table(name)} ENGINE = #{newengine}") if engine.to_s != newengine.to_s
361
361
  @data[:ENGINE] = newengine
362
362
  end
363
363
 
@@ -105,7 +105,7 @@ class Baza::Driver::MysqlJava < Baza::JdbcDriver
105
105
  keys.each do |col_name|
106
106
  sql << "," unless first
107
107
  first = false if first
108
- sql << "`#{escape_column(col_name)}`"
108
+ sql << quote_column(col_name)
109
109
  end
110
110
 
111
111
  sql << ") VALUES ("
@@ -127,7 +127,7 @@ class Baza::Driver::MysqlJava < Baza::JdbcDriver
127
127
  sql << ","
128
128
  end
129
129
 
130
- sql << @db.sqlval(val)
130
+ sql << @db.quote_value(val)
131
131
  end
132
132
  else
133
133
  hash.each do |_key, val|
@@ -137,7 +137,7 @@ class Baza::Driver::MysqlJava < Baza::JdbcDriver
137
137
  sql << ","
138
138
  end
139
139
 
140
- sql << @db.sqlval(val)
140
+ sql << @db.quote_value(val)
141
141
  end
142
142
  end
143
143
  end
@@ -19,7 +19,7 @@ class Baza::Driver::Pg::Column < Baza::Column
19
19
  other_table = other_column.table
20
20
 
21
21
  sql = "
22
- ALTER TABLE #{@db.escape_table(table_name)}
22
+ ALTER TABLE #{@db.quote_table(table_name)}
23
23
  ADD CONSTRAINT #{@db.escape_table(fk_name)}
24
24
  FOREIGN KEY (#{@db.escape_table(name)})
25
25
  REFERENCES #{@db.escape_table(other_table.name)} (#{@db.escape_column(other_column.name)})
@@ -66,7 +66,7 @@ class Baza::Driver::Pg::Column < Baza::Column
66
66
  end
67
67
 
68
68
  def drop
69
- @db.query("ALTER TABLE #{@db.sep_table}#{@db.escape_table(table_name)}#{@db.sep_table} DROP COLUMN #{@db.sep_col}#{@db.escape_column(name)}#{@db.sep_col}")
69
+ @db.query("ALTER TABLE #{@db.quote_table(table_name)} DROP COLUMN #{@db.quote_column(name)}")
70
70
  nil
71
71
  end
72
72
 
@@ -78,7 +78,7 @@ class Baza::Driver::Pg::Column < Baza::Column
78
78
 
79
79
  def change(data)
80
80
  if data.key?(:name) && data.fetch(:name).to_s != name
81
- @db.query("#{alter_table_sql} RENAME #{col_escaped} TO #{@db.sep_col}#{@db.escape_column(data.fetch(:name))}#{@db.sep_col}")
81
+ @db.query("#{alter_table_sql} RENAME #{@db.quote_column(name)} TO #{@db.quote_column(data.fetch(:name))}")
82
82
  @name = data.fetch(:name).to_s
83
83
  end
84
84
 
@@ -126,19 +126,11 @@ class Baza::Driver::Pg::Column < Baza::Column
126
126
 
127
127
  private
128
128
 
129
- def col_escaped
130
- "#{@db.sep_col}#{@db.escape_column(name)}#{@db.sep_col}"
131
- end
132
-
133
- def table_escaped
134
- "#{@db.sep_table}#{@db.escape_table(table_name)}#{@db.sep_table}"
135
- end
136
-
137
129
  def alter_table_sql
138
- "ALTER TABLE #{table_escaped}"
130
+ "ALTER TABLE #{@db.quote_table(table_name)}"
139
131
  end
140
132
 
141
133
  def alter_column_sql
142
- "#{alter_table_sql} ALTER COLUMN #{col_escaped}"
134
+ "#{alter_table_sql} ALTER COLUMN #{@db.quote_column(name)}"
143
135
  end
144
136
  end
@@ -32,7 +32,7 @@ class Baza::Driver::Pg::Columns
32
32
 
33
33
  data[:maxlength] = 255 if type == :varchar && !data.key?(:maxlength)
34
34
 
35
- sql = "#{@db.sep_col}#{@db.escape_column(data.fetch(:name))}#{@db.sep_col} #{type}"
35
+ sql = "#{@db.quote_column(data.fetch(:name))} #{type}"
36
36
  sql << "(#{maxlength})" if maxlength
37
37
  sql << " PRIMARY KEY" if data[:primarykey]
38
38
  sql << " NOT NULL" if data.key?(:null) && !data[:null]
@@ -40,11 +40,11 @@ class Baza::Driver::Pg::Columns
40
40
  if data.key?(:default_func)
41
41
  sql << " DEFAULT #{data[:default_func]}"
42
42
  elsif data.key?(:default) && data[:default]
43
- sql << " DEFAULT #{@db.sqlval(data.fetch(:default))}"
43
+ sql << " DEFAULT #{@db.quote_value(data.fetch(:default))}"
44
44
  end
45
45
 
46
- sql << " COMMENT '#{@db.escape(data.fetch(:comment))}'" if data.key?(:comment)
47
- sql << " AFTER #{@db.sep_col}#{@db.escape_column(data.fetch(:after))}#{@db.sep_col}" if data[:after] && !data[:first]
46
+ sql << " COMMENT #{@db.quote_value(data.fetch(:comment))}" if data.key?(:comment)
47
+ sql << " AFTER #{@db.quote_column(data.fetch(:after))}" if data[:after] && !data[:first]
48
48
  sql << " FIRST" if data[:first]
49
49
  sql << " STORAGE #{data[:storage].to_s.upcase}" if data[:storage]
50
50
 
@@ -31,10 +31,10 @@ class Baza::Driver::Pg::CreateIndexSqlCreator
31
31
  raise "No columns was given on index: '#{index_data.fetch(:name)}'." if !index_data[:columns] || index_data[:columns].empty?
32
32
 
33
33
  sql << " UNIQUE" if index_data[:unique]
34
- sql << " INDEX #{@db.sep_index}#{@db.escape_index(index_data.fetch(:name))}#{@db.sep_index}"
34
+ sql << " INDEX #{@db.quote_index(index_data.fetch(:name))}"
35
35
 
36
36
  if args[:on_table] || !args.key?(:on_table)
37
- sql << " ON #{@db.sep_table}#{@db.escape_table(args.fetch(:table_name))}#{@db.sep_table}"
37
+ sql << " ON #{@db.quote_table(args.fetch(:table_name))}"
38
38
  end
39
39
 
40
40
  sql << " ("
@@ -43,7 +43,7 @@ class Baza::Driver::Pg::CreateIndexSqlCreator
43
43
  index_data.fetch(:columns).each do |col_name|
44
44
  sql << ", " unless first
45
45
  first = false if first
46
- sql << "#{@db.sep_col}#{@db.escape_column(col_name)}#{@db.sep_col}"
46
+ sql << @db.quote_column(col_name)
47
47
  end
48
48
 
49
49
  sql << ")"
@@ -7,7 +7,7 @@ class Baza::Driver::Pg::Database < Baza::Database
7
7
  def drop
8
8
  with_cloned_conn_and_terminated_connections do |cloned_conn|
9
9
  # Drop the database
10
- cloned_conn.query("DROP DATABASE #{db.sep_database}#{db.escape_database(name)}#{db.sep_database}")
10
+ cloned_conn.query("DROP DATABASE #{db.quote_database(name)}")
11
11
  end
12
12
 
13
13
  self
@@ -65,7 +65,7 @@ private
65
65
 
66
66
  def rename(new_name)
67
67
  with_cloned_conn_and_terminated_connections do |cloned_conn|
68
- cloned_conn.query("ALTER DATABASE #{db.sep_database}#{db.escape_database(name_was)}#{db.sep_database} RENAME TO #{db.sep_database}#{db.escape_database(name)}#{db.sep_database}")
68
+ cloned_conn.query("ALTER DATABASE #{db.quote_database(name_was)} RENAME TO #{db.quote_database(name)}")
69
69
  end
70
70
 
71
71
  @name = new_name.to_s
@@ -78,8 +78,8 @@ private
78
78
  # Drop database through a cloned connection, because Postgres might bug up if dropping the current
79
79
  db.clone_conn(db: other_db.name) do |cloned_conn|
80
80
  # Close existing connections to avoid 'is being accessed by other users' errors
81
- cloned_conn.query("REVOKE CONNECT ON DATABASE #{db.sep_database}#{db.escape_database(name_was)}#{db.sep_database} FROM public") unless name_changed?
82
- cloned_conn.query("SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = #{db.sep_val}#{@db.esc(name_was)}#{db.sep_val} AND pid != pg_backend_pid()")
81
+ cloned_conn.query("REVOKE CONNECT ON DATABASE #{db.quote_database(name_was)} FROM public") unless name_changed?
82
+ cloned_conn.query("SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = #{@db.quote_value(name_was)} AND pid != pg_backend_pid()")
83
83
 
84
84
  yield cloned_conn
85
85
  end
@@ -22,7 +22,7 @@ class Baza::Driver::Pg::Databases
22
22
  end
23
23
  end
24
24
 
25
- @db.query("CREATE DATABASE #{@db.sep_database}#{@db.escape_table(args.fetch(:name))}#{@db.sep_database}")
25
+ @db.query("CREATE DATABASE #{@db.quote_table(args.fetch(:name))}")
26
26
  true
27
27
  end
28
28
 
@@ -11,8 +11,8 @@ class Baza::Driver::Pg::ForeignKey < Baza::ForeignKey
11
11
 
12
12
  def drop
13
13
  @db.query("
14
- ALTER TABLE #{@db.escape_table(table_name)}
15
- DROP CONSTRAINT #{@db.escape_table(name)}
14
+ ALTER TABLE #{@db.quote_table(table_name)}
15
+ DROP CONSTRAINT #{@db.quote_table(name)}
16
16
  ")
17
17
  true
18
18
  end
@@ -24,7 +24,7 @@ class Baza::Driver::Pg::Index < Baza::Index
24
24
  end
25
25
 
26
26
  def rename(new_name)
27
- @db.query("ALTER INDEX #{@db.sep_index}#{@db.escape_index(name)}#{@db.sep_index} RENAME TO #{@db.sep_index}#{@db.escape_index(new_name)}#{@db.sep_index}")
27
+ @db.query("ALTER INDEX #{@db.quote_index(name)} RENAME TO #{@db.quote_index(new_name)}")
28
28
  @name = new_name.to_s
29
29
  self
30
30
  end
@@ -9,7 +9,7 @@ class Baza::Driver::Pg::Table < Baza::Table
9
9
 
10
10
  def drop
11
11
  @db.with_database(database_name) do
12
- @db.query("DROP TABLE \"#{@db.escape_table(name)}\"")
12
+ @db.query("DROP TABLE #{@db.quote_table(name)}")
13
13
  end
14
14
  end
15
15
 
@@ -72,7 +72,7 @@ class Baza::Driver::Pg::Table < Baza::Table
72
72
  end
73
73
 
74
74
  def truncate
75
- @db.query("TRUNCATE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table} RESTART IDENTITY")
75
+ @db.query("TRUNCATE #{@db.quote_table(name)} RESTART IDENTITY")
76
76
  self
77
77
  end
78
78
 
@@ -164,7 +164,7 @@ class Baza::Driver::Pg::Table < Baza::Table
164
164
  end
165
165
 
166
166
  def rename(new_name)
167
- @db.query("ALTER TABLE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table} RENAME TO #{@db.sep_table}#{@db.escape_table(new_name)}#{@db.sep_table}")
167
+ @db.query("ALTER TABLE #{@db.quote_table(name)} RENAME TO #{@db.quote_table(new_name)}")
168
168
  @name = new_name.to_s
169
169
  self
170
170
  end
@@ -184,13 +184,13 @@ class Baza::Driver::Pg::Table < Baza::Table
184
184
 
185
185
  def rows_count
186
186
  @db.databases.with_database(database_name) do
187
- sql = "SELECT COUNT(*) AS count FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}"
187
+ sql = "SELECT COUNT(*) AS count FROM #{@db.quote_table(name)}"
188
188
  return @db.query(sql).fetch.fetch(:count).to_i
189
189
  end
190
190
  end
191
191
 
192
192
  def optimize
193
- @db.query("VACUUM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}")
193
+ @db.query("VACUUM #{@db.quote_table(name)}")
194
194
  self
195
195
  end
196
196
 
@@ -220,13 +220,13 @@ class Baza::Driver::Pg::Table < Baza::Table
220
220
  private
221
221
 
222
222
  def clone_insert_from_original_table(newname, columns_list)
223
- sql_clone = "INSERT INTO #{@db.sep_table}#{@db.escape_table(newname)}#{@db.sep_table} ("
223
+ sql_clone = "INSERT INTO #{@db.quote_table(newname)} ("
224
224
 
225
225
  first = true
226
226
  columns_list.each do |column_data|
227
227
  sql_clone << "," unless first
228
228
  first = false if first
229
- sql_clone << "#{@db.sep_col}#{@db.escape_column(column_data.fetch(:name))}#{@db.sep_col}"
229
+ sql_clone << @db.quote_column(column_data.fetch(:name))
230
230
  end
231
231
 
232
232
  sql_clone << ") SELECT "
@@ -235,10 +235,10 @@ private
235
235
  columns_list.each do |column_data|
236
236
  sql_clone << "," unless first
237
237
  first = false if first
238
- sql_clone << "#{@db.sep_col}#{@db.escape_column(column_data.fetch(:name))}#{@db.sep_col}"
238
+ sql_clone << @db.quote_column(column_data.fetch(:name))
239
239
  end
240
240
 
241
- sql_clone << " FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}"
241
+ sql_clone << " FROM #{@db.quote_table(name)}"
242
242
 
243
243
  @db.query(sql_clone)
244
244
  end