Software /
code /
prosody
Changeset
7308:397f45107795
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 21 Mar 2016 14:52:43 +0100 |
parents | 7307:6bbe47e30af4 (current diff) 7306:98c4c3a2b536 (diff) |
children | 7310:66873c5e2061 |
files | |
diffstat | 2 files changed, 5 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua Mon Mar 21 12:10:10 2016 +0100 +++ b/plugins/mod_storage_sql.lua Mon Mar 21 14:52:43 2016 +0100 @@ -82,16 +82,14 @@ 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 @@ 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);
--- a/util/sql.lua Mon Mar 21 12:10:10 2016 +0100 +++ b/util/sql.lua Mon Mar 21 14:52:43 2016 +0100 @@ -102,11 +102,12 @@ 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;