Merge 0.10->trunk
[prosody.git] / util / sql.lua
index 735fbce825d688d596e2d2bd20ce44c4ee936441..5a1dda5d41d3261885a0a8f5f919b42c76bc2202 100644 (file)
@@ -264,13 +264,14 @@ function engine:_create_table(table)
                if col_type == "MEDIUMTEXT" and self.params.driver ~= "MySQL" then
                        col_type = "TEXT"; -- MEDIUMTEXT is MySQL-specific
                end
+               if col.auto_increment == true and self.params.driver == "PostgreSQL" then
+                       col_type = "BIGSERIAL";
+               end
                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
-                       if self.params.driver == "PostgreSQL" then
-                               sql = sql.." SERIAL";
-                       elseif self.params.driver == "MySQL" then
+                       if self.params.driver == "MySQL" then
                                sql = sql.." AUTO_INCREMENT";
                        elseif self.params.driver == "SQLite3" then
                                sql = sql.." AUTOINCREMENT";
@@ -307,13 +308,13 @@ function engine:set_encoding() -- to UTF-8
        if driver == "MySQL" then
                set_names_query = set_names_query:gsub(";$", " COLLATE 'utf8_bin';");
                local ok, charsets = self:transaction(function()
-                       return self:select"SELECT `CHARACTER_SET_NAME` FROM `CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;";
+                       return self:select"SELECT `CHARACTER_SET_NAME` FROM `information_schema`.`CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;";
                end);
                local row = ok and charsets();
                charset = row and row[1] or charset;
        end
        self.charset = charset;
-       return self:transaction(function() return engine:execute(set_names_query:format(charset)); end);
+       return self:transaction(function() return self:execute(set_names_query:format(charset)); end);
 end
 local engine_mt = { __index = engine };