Software /
code /
prosody
Changeset
7306:98c4c3a2b536
util.sql: Catch errors from LuaDBI connect (Fixes #568)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 21 Mar 2016 09:50:52 +0100 |
parents | 7305:c02e3d8f23fc |
children | 7308:397f45107795 7309:471189342890 |
files | util/sql.lua |
diffstat | 1 files changed, 2 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/sql.lua Mon Mar 21 09:33:12 2016 +0100 +++ b/util/sql.lua Mon Mar 21 09:50:52 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;