253 |
253 |
254 return statement_fetch_impl(L, statement, named_columns); |
254 return statement_fetch_impl(L, statement, named_columns); |
255 } |
255 } |
256 |
256 |
257 /* |
257 /* |
258 * iterfunc = statement:fetch(named_indexes) |
258 * table = statement:fetch(named_indexes) |
259 */ |
259 */ |
260 |
|
261 static int statement_fetch(lua_State *L) { |
260 static int statement_fetch(lua_State *L) { |
|
261 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); |
|
262 int named_columns = lua_toboolean(L, 2); |
|
263 |
|
264 return statement_fetch_impl(L, statement, named_columns); |
|
265 } |
|
266 |
|
267 /* |
|
268 * iterfunc = statement:rows(named_indexes) |
|
269 */ |
|
270 static int statement_rows(lua_State *L) { |
262 if (lua_gettop(L) == 1) { |
271 if (lua_gettop(L) == 1) { |
263 lua_pushvalue(L, 1); |
272 lua_pushvalue(L, 1); |
264 lua_pushboolean(L, 0); |
273 lua_pushboolean(L, 0); |
265 } else { |
274 } else { |
266 lua_pushvalue(L, 1); |
275 lua_pushvalue(L, 1); |
270 lua_pushcclosure(L, next_iterator, 2); |
279 lua_pushcclosure(L, next_iterator, 2); |
271 return 1; |
280 return 1; |
272 } |
281 } |
273 |
282 |
274 /* |
283 /* |
275 * table = statement:row(named_indexes) |
|
276 */ |
|
277 static int statement_row(lua_State *L) { |
|
278 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); |
|
279 int named_columns = lua_toboolean(L, 2); |
|
280 |
|
281 return statement_fetch_impl(L, statement, named_columns); |
|
282 } |
|
283 |
|
284 /* |
|
285 * __gc |
284 * __gc |
286 */ |
285 */ |
287 static int statement_gc(lua_State *L) { |
286 static int statement_gc(lua_State *L) { |
288 /* always free the handle */ |
287 /* always free the handle */ |
289 statement_close(L); |
288 statement_close(L); |
313 int dbd_sqlite3_statement(lua_State *L) { |
312 int dbd_sqlite3_statement(lua_State *L) { |
314 static const luaL_Reg statement_methods[] = { |
313 static const luaL_Reg statement_methods[] = { |
315 {"close", statement_close}, |
314 {"close", statement_close}, |
316 {"execute", statement_execute}, |
315 {"execute", statement_execute}, |
317 {"fetch", statement_fetch}, |
316 {"fetch", statement_fetch}, |
318 {"row", statement_row}, |
317 {"rows", statement_rows}, |
319 {NULL, NULL} |
318 {NULL, NULL} |
320 }; |
319 }; |
321 |
320 |
322 static const luaL_Reg statement_class_methods[] = { |
321 static const luaL_Reg statement_class_methods[] = { |
323 {NULL, NULL} |
322 {NULL, NULL} |