aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-04-10 23:16:13 +0200
committerKim Alvefur <zash@zash.se>2017-04-10 23:16:13 +0200
commit61c1325aa6509896b202f731c546e980ef97fff4 (patch)
treee163b8572f88719bc01ba397d169da78c4fc8d48 /util
parentfcca450715b5ccb94002dc9dd2babfe214955f4b (diff)
parent1796c0795624152f8415ad64f9cdab62a9ad6402 (diff)
downloadprosody-61c1325aa6509896b202f731c546e980ef97fff4.tar.gz
prosody-61c1325aa6509896b202f731c546e980ef97fff4.zip
Merge 0.10->trunk
Diffstat (limited to 'util')
-rw-r--r--util/sql.lua26
1 files changed, 12 insertions, 14 deletions
diff --git a/util/sql.lua b/util/sql.lua
index eb562eb2..a859ddc9 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -128,8 +128,8 @@ function engine:onconnect()
end
function engine:prepquery(sql)
- if self.params.driver == "PostgreSQL" then
- sql = sql:gsub("`", "\"");
+ if self.params.driver == "MySQL" then
+ sql = sql:gsub("\"", "`");
end
return sql;
end
@@ -242,27 +242,26 @@ function engine:transaction(...)
return ok, ret;
end
function engine:_create_index(index)
- local sql = "CREATE INDEX `"..index.name.."` ON `"..index.table.."` (";
+ local sql = "CREATE INDEX \""..index.name.."\" ON \""..index.table.."\" (";
for i=1,#index do
- sql = sql.."`"..index[i].."`";
+ sql = sql.."\""..index[i].."\"";
if i ~= #index then sql = sql..", "; end
end
sql = sql..");"
- if self.params.driver == "PostgreSQL" then
- sql = sql:gsub("`", "\"");
- elseif self.params.driver == "MySQL" then
- sql = sql:gsub("`([,)])", "`(20)%1");
+ if self.params.driver == "MySQL" then
+ sql = sql:gsub("\"([,)])", "\"(20)%1");
end
if index.unique then
sql = sql:gsub("^CREATE", "CREATE UNIQUE");
end
+ sql = self:prepquery(sql);
if self._debug then
debugquery("create", sql);
end
return self:execute(sql);
end
function engine:_create_table(table)
- local sql = "CREATE TABLE `"..table.name.."` (";
+ local sql = "CREATE TABLE \""..table.name.."\" (";
for i,col in ipairs(table.c) do
local col_type = col.type;
if col_type == "MEDIUMTEXT" and self.params.driver ~= "MySQL" then
@@ -271,7 +270,7 @@ function engine:_create_table(table)
if col.auto_increment == true and self.params.driver == "PostgreSQL" then
col_type = "BIGSERIAL";
end
- sql = sql.."`"..col.name.."` "..col_type;
+ sql = sql.."\""..col.name.."\" "..col_type;
if col.nullable == false then sql = sql.." NOT NULL"; end
if col.primary_key == true then sql = sql.." PRIMARY KEY"; end
if col.auto_increment == true then
@@ -284,11 +283,10 @@ function engine:_create_table(table)
if i ~= #table.c then sql = sql..", "; end
end
sql = sql.. ");"
- if self.params.driver == "PostgreSQL" then
- sql = sql:gsub("`", "\"");
- elseif self.params.driver == "MySQL" then
+ if self.params.driver == "MySQL" then
sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset));
end
+ sql = self:prepquery(sql);
if self._debug then
debugquery("create", sql);
end
@@ -316,7 +314,7 @@ function engine:set_encoding() -- to UTF-8
local charset = "utf8";
if driver == "MySQL" then
self:transaction(function()
- for row in self:select"SELECT `CHARACTER_SET_NAME` FROM `information_schema`.`CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;" do
+ for row in self:select"SELECT \"CHARACTER_SET_NAME\" FROM \"information_schema\".\"CHARACTER_SETS\" WHERE \"CHARACTER_SET_NAME\" LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;" do
charset = row and row[1] or charset;
end
end);