diff options
author | Kim Alvefur <zash@zash.se> | 2016-03-13 18:31:53 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-03-13 18:31:53 +0100 |
commit | c51163554308c18df6e85676db4a71ec4ac517c8 (patch) | |
tree | 4d97e58da9b4b6f6706c0ec08bb8329e56e91458 /util/sql.lua | |
parent | 3fde897b559ed27596eb31d3b1fd5a46274b0217 (diff) | |
download | prosody-c51163554308c18df6e85676db4a71ec4ac517c8.tar.gz prosody-c51163554308c18df6e85676db4a71ec4ac517c8.zip |
util.sql: Don't break out of result retreival loops
Diffstat (limited to 'util/sql.lua')
-rw-r--r-- | util/sql.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/util/sql.lua b/util/sql.lua index 85664567..43c65a19 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -299,19 +299,21 @@ function engine:set_encoding() -- to UTF-8 local driver = self.params.driver; if driver == "SQLite3" then return self:transaction(function() - if self:select"PRAGMA encoding;"()[1] == "UTF-8" then - self.charset = "utf8"; + for encoding in self:select"PRAGMA encoding;" do + if encoding[1] == "UTF-8" then + self.charset = "utf8"; + end end end); end local set_names_query = "SET NAMES '%s';" local charset = "utf8"; if driver == "MySQL" then - local ok, charsets = self:transaction(function() - return self:select"SELECT `CHARACTER_SET_NAME` FROM `information_schema`.`CHARACTER_SETS` WHERE `CHARACTER_SET_NAME` LIKE 'utf8%' ORDER BY MAXLEN DESC LIMIT 1;"; + 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 + charset = row and row[1] or charset; + end end); - local row = ok and charsets(); - charset = row and row[1] or charset; set_names_query = set_names_query:gsub(";$", (" COLLATE '%s';"):format(charset.."_bin")); end self.charset = charset; @@ -325,12 +327,16 @@ function engine:set_encoding() -- to UTF-8 local ok, actual_charset = self:transaction(function () return self:select"SHOW SESSION VARIABLES LIKE 'character_set_client'"; end); + local charset_ok; for row in actual_charset do if row[2] ~= charset then log("error", "MySQL %s is actually %q (expected %q)", row[1], row[2], charset); - return false, "Failed to set connection encoding"; + charset_ok = false; end end + if not charset_ok then + return false, "Failed to set connection encoding"; + end end return true; |