--- a/dbd/postgresql/statement.c Fri Dec 12 03:46:34 2008 +0000 +++ b/dbd/postgresql/statement.c Fri Dec 19 09:17:16 2008 +0000 @@ -26,6 +26,20 @@ return lua_type; } +/* + * num_affected_rows = statement:affected() + */ +static int statement_affected(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT); + + if (!statement->result) { + luaL_error(L, DBI_ERR_INVALID_STATEMENT); + } + + lua_pushinteger(L, atoi(PQcmdTuples(statement->result))); + + return 1; +} /* * success = statement:close() @@ -243,6 +257,21 @@ } /* + * num_rows = statement:rowcount() + */ +static int statement_rowcount(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT); + + if (!statement->result) { + luaL_error(L, DBI_ERR_INVALID_STATEMENT); + } + + lua_pushinteger(L, PQntuples(statement->result)); + + return 1; +} + +/* * iterfunc = statement:rows(named_indexes) */ static int statement_rows(lua_State *L) { @@ -322,9 +351,11 @@ int dbd_postgresql_statement(lua_State *L) { static const luaL_Reg statement_methods[] = { + {"affected", statement_affected}, {"close", statement_close}, {"execute", statement_execute}, {"fetch", statement_fetch}, + {"rowcount", statement_rowcount}, {"rows", statement_rows}, {NULL, NULL} };