Software /
code /
prosody
Diff
util/sql.lua @ 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 |
parent | 7276:30dfaf36ea6d |
child | 7312:b4e99602ae75 |
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;