diff options
author | Kim Alvefur <zash@zash.se> | 2016-03-21 14:52:43 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-03-21 14:52:43 +0100 |
commit | 1193a4bdb914eba2a902ae5275bd56438bd49b55 (patch) | |
tree | 85a3c7b4d4efadd9c68b69eac3178dca98372e19 | |
parent | 0a88a8699681f8ebf26b2f86531328c583c97f7b (diff) | |
parent | 6a65e76fc615bd10c21776bd4c4455ab522d2f29 (diff) | |
download | prosody-1193a4bdb914eba2a902ae5275bd56438bd49b55.tar.gz prosody-1193a4bdb914eba2a902ae5275bd56438bd49b55.zip |
Merge 0.10->trunk
-rw-r--r-- | plugins/mod_storage_sql.lua | 8 | ||||
-rw-r--r-- | util/sql.lua | 3 |
2 files changed, 5 insertions, 6 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 70f1ab83..4f46b3f6 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -82,16 +82,14 @@ local function keyval_store_set(data) local extradata = {}; for key, value in pairs(data) do if type(key) == "string" and key ~= "" then - local t, value = serialize(value); - assert(t, value); + local t, value = assert(serialize(value)); engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, key, t, value); else extradata[key] = value; end end if next(extradata) ~= nil then - local t, extradata = serialize(extradata); - assert(t, extradata); + local t, extradata = assert(serialize(extradata)); engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, user or "", store, "", t, extradata); end end @@ -197,7 +195,7 @@ function archive_store:append(username, key, value, when, with) else key = uuid.generate(); end - local t, value = serialize(value); + local t, value = assert(serialize(value)); engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value); return key; end); diff --git a/util/sql.lua b/util/sql.lua index dcf665fb..f64e8e10 100644 --- a/util/sql.lua +++ b/util/sql.lua @@ -102,11 +102,12 @@ function engine:connect() local params = self.params; assert(params.driver, "no driver") log("debug", "Connecting to [%s] %s...", params.driver, params.database); - local dbh, err = DBI.Connect( + local ok, dbh, err = pcall(DBI.Connect, params.driver, params.database, params.username, params.password, params.host, params.port ); + if not ok then return ok, dbh; end if not dbh then return nil, err; end dbh:autocommit(false); -- don't commit automatically self.conn = dbh; |