Mercurial > prosody-modules
comparison mod_mam_sql/mod_mam_sql.lua @ 1206:04bf76c3e4c6
mod_mam_sql: Add better error handling
author | Rob Hoelz <rob@hoelz.ro> |
---|---|
date | Mon, 02 Sep 2013 19:55:51 +0200 |
parents | 1e0d273bcb75 |
children | c6b8ae5a8369 |
comparison
equal
deleted
inserted
replaced
1205:7d2d440e2fa5 | 1206:04bf76c3e4c6 |
---|---|
112 | 112 |
113 function getsql(sql, ...) | 113 function getsql(sql, ...) |
114 if params.driver == "PostgreSQL" then | 114 if params.driver == "PostgreSQL" then |
115 sql = sql:gsub("`", "\""); | 115 sql = sql:gsub("`", "\""); |
116 end | 116 end |
117 if not connection then | |
118 return nil, 'connection failed'; | |
119 end | |
117 -- do prepared statement stuff | 120 -- do prepared statement stuff |
118 local stmt, err = connection:prepare(sql); | 121 local stmt, err = connection:prepare(sql); |
119 if not stmt and not test_connection() then error("connection failed"); end | 122 if not stmt and not test_connection() then |
123 return nil, "connection failed"; | |
124 end | |
120 if not stmt then module:log("error", "QUERY FAILED: %s %s", err, debug.traceback()); return nil, err; end | 125 if not stmt then module:log("error", "QUERY FAILED: %s %s", err, debug.traceback()); return nil, err; end |
121 -- run query | 126 -- run query |
122 local ok, err = stmt:execute(...); | 127 local ok, err = stmt:execute(...); |
123 if not ok and not test_connection() then error("connection failed"); end | 128 if not ok and not test_connection() then |
129 return nil, "connection failed"; | |
130 end | |
124 if not ok then return nil, err; end | 131 if not ok then return nil, err; end |
125 | 132 |
126 return stmt; | 133 return stmt; |
127 end | 134 end |
128 function setsql(sql, ...) | 135 function setsql(sql, ...) |