Comparison

util/sql.lua @ 5742:3c57c2281087

util.sql: Don't fetch row count of result sets for queries that don't have result sets
author Kim Alvefur <zash@zash.se>
date Fri, 12 Jul 2013 17:03:09 +0200
parent 5739:2e9ad9cb206f
child 5743:8363dda76155
comparison
equal deleted inserted replaced
5741:c7a664e496b3 5742:3c57c2281087
176 return stmt; 176 return stmt;
177 end 177 end
178 178
179 local result_mt = { __index = { 179 local result_mt = { __index = {
180 affected = function(self) return self.__affected; end; 180 affected = function(self) return self.__affected; end;
181 rowcount = function(self) return self.__rowcount; end;
182 } }; 181 } };
183 182
184 function engine:execute_query(sql, ...) 183 function engine:execute_query(sql, ...)
185 if self.params.driver == "PostgreSQL" then 184 if self.params.driver == "PostgreSQL" then
186 sql = sql:gsub("`", "\""); 185 sql = sql:gsub("`", "\"");
198 if not stmt then 197 if not stmt then
199 stmt = assert(self.conn:prepare(sql)); 198 stmt = assert(self.conn:prepare(sql));
200 prepared[sql] = stmt; 199 prepared[sql] = stmt;
201 end 200 end
202 assert(stmt:execute(...)); 201 assert(stmt:execute(...));
203 return setmetatable({ __affected = stmt:affected(), __rowcount = stmt:rowcount() }, result_mt); 202 return setmetatable({ __affected = stmt:affected() }, result_mt);
204 end 203 end
205 engine.insert = engine.execute_update; 204 engine.insert = engine.execute_update;
206 engine.select = engine.execute_query; 205 engine.select = engine.execute_query;
207 engine.delete = engine.execute_update; 206 engine.delete = engine.execute_update;
208 engine.update = engine.execute_update; 207 engine.update = engine.execute_update;