Software /
code /
prosody
Comparison
util/sql.lua @ 5743:8363dda76155
Backed out changeset 3c57c2281087
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Jul 2013 17:41:54 +0200 |
parent | 5742:3c57c2281087 |
child | 5744:253dfea0e3f6 |
comparison
equal
deleted
inserted
replaced
5742:3c57c2281087 | 5743:8363dda76155 |
---|---|
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; | |
181 } }; | 182 } }; |
182 | 183 |
183 function engine:execute_query(sql, ...) | 184 function engine:execute_query(sql, ...) |
184 if self.params.driver == "PostgreSQL" then | 185 if self.params.driver == "PostgreSQL" then |
185 sql = sql:gsub("`", "\""); | 186 sql = sql:gsub("`", "\""); |
197 if not stmt then | 198 if not stmt then |
198 stmt = assert(self.conn:prepare(sql)); | 199 stmt = assert(self.conn:prepare(sql)); |
199 prepared[sql] = stmt; | 200 prepared[sql] = stmt; |
200 end | 201 end |
201 assert(stmt:execute(...)); | 202 assert(stmt:execute(...)); |
202 return setmetatable({ __affected = stmt:affected() }, result_mt); | 203 return setmetatable({ __affected = stmt:affected(), __rowcount = stmt:rowcount() }, result_mt); |
203 end | 204 end |
204 engine.insert = engine.execute_update; | 205 engine.insert = engine.execute_update; |
205 engine.select = engine.execute_query; | 206 engine.select = engine.execute_query; |
206 engine.delete = engine.execute_update; | 207 engine.delete = engine.execute_update; |
207 engine.update = engine.execute_update; | 208 engine.update = engine.execute_update; |