dbd/postgresql/statement.c

changeset 21
7956401a0c5e
parent 20
5ab0b30f8fbd
child 30
8599f34c139b
equal deleted inserted replaced
20:5ab0b30f8fbd 21:7956401a0c5e
24 } 24 }
25 25
26 return lua_type; 26 return lua_type;
27 } 27 }
28 28
29 /*
30 * num_affected_rows = statement:affected()
31 */
32 static int statement_affected(lua_State *L) {
33 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT);
34
35 if (!statement->result) {
36 luaL_error(L, DBI_ERR_INVALID_STATEMENT);
37 }
38
39 lua_pushinteger(L, atoi(PQcmdTuples(statement->result)));
40
41 return 1;
42 }
29 43
30 /* 44 /*
31 * success = statement:close() 45 * success = statement:close()
32 */ 46 */
33 static int statement_close(lua_State *L) { 47 static int statement_close(lua_State *L) {
241 255
242 return statement_fetch_impl(L, statement, named_columns); 256 return statement_fetch_impl(L, statement, named_columns);
243 } 257 }
244 258
245 /* 259 /*
260 * num_rows = statement:rowcount()
261 */
262 static int statement_rowcount(lua_State *L) {
263 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT);
264
265 if (!statement->result) {
266 luaL_error(L, DBI_ERR_INVALID_STATEMENT);
267 }
268
269 lua_pushinteger(L, PQntuples(statement->result));
270
271 return 1;
272 }
273
274 /*
246 * iterfunc = statement:rows(named_indexes) 275 * iterfunc = statement:rows(named_indexes)
247 */ 276 */
248 static int statement_rows(lua_State *L) { 277 static int statement_rows(lua_State *L) {
249 if (lua_gettop(L) == 1) { 278 if (lua_gettop(L) == 1) {
250 lua_pushvalue(L, 1); 279 lua_pushvalue(L, 1);
320 return 1; 349 return 1;
321 } 350 }
322 351
323 int dbd_postgresql_statement(lua_State *L) { 352 int dbd_postgresql_statement(lua_State *L) {
324 static const luaL_Reg statement_methods[] = { 353 static const luaL_Reg statement_methods[] = {
354 {"affected", statement_affected},
325 {"close", statement_close}, 355 {"close", statement_close},
326 {"execute", statement_execute}, 356 {"execute", statement_execute},
327 {"fetch", statement_fetch}, 357 {"fetch", statement_fetch},
358 {"rowcount", statement_rowcount},
328 {"rows", statement_rows}, 359 {"rows", statement_rows},
329 {NULL, NULL} 360 {NULL, NULL}
330 }; 361 };
331 362
332 static const luaL_Reg statement_class_methods[] = { 363 static const luaL_Reg statement_class_methods[] = {

mercurial