Comparison

util/sql.lua @ 7308:397f45107795

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 21 Mar 2016 14:52:43 +0100
parent 7306:98c4c3a2b536
child 7312:b4e99602ae75
comparison
equal deleted inserted replaced
7307:6bbe47e30af4 7308:397f45107795
100 if self.conn then return true; end 100 if self.conn then return true; end
101 101
102 local params = self.params; 102 local params = self.params;
103 assert(params.driver, "no driver") 103 assert(params.driver, "no driver")
104 log("debug", "Connecting to [%s] %s...", params.driver, params.database); 104 log("debug", "Connecting to [%s] %s...", params.driver, params.database);
105 local dbh, err = DBI.Connect( 105 local ok, dbh, err = pcall(DBI.Connect,
106 params.driver, params.database, 106 params.driver, params.database,
107 params.username, params.password, 107 params.username, params.password,
108 params.host, params.port 108 params.host, params.port
109 ); 109 );
110 if not ok then return ok, dbh; end
110 if not dbh then return nil, err; end 111 if not dbh then return nil, err; end
111 dbh:autocommit(false); -- don't commit automatically 112 dbh:autocommit(false); -- don't commit automatically
112 self.conn = dbh; 113 self.conn = dbh;
113 self.prepared = {}; 114 self.prepared = {};
114 local ok, err = self:set_encoding(); 115 local ok, err = self:set_encoding();