308 |
308 |
309 return statement_fetch_impl(L, statement, named_columns); |
309 return statement_fetch_impl(L, statement, named_columns); |
310 } |
310 } |
311 |
311 |
312 /* |
312 /* |
313 * iterfunc = statement:fetch(named_indexes) |
313 * table = statement:fetch(named_indexes) |
314 */ |
314 */ |
315 |
|
316 static int statement_fetch(lua_State *L) { |
315 static int statement_fetch(lua_State *L) { |
|
316 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
|
317 int named_columns = lua_toboolean(L, 2); |
|
318 |
|
319 return statement_fetch_impl(L, statement, named_columns); |
|
320 } |
|
321 |
|
322 /* |
|
323 * iterfunc = statement:rows(named_indexes) |
|
324 */ |
|
325 |
|
326 static int statement_rows(lua_State *L) { |
317 if (lua_gettop(L) == 1) { |
327 if (lua_gettop(L) == 1) { |
318 lua_pushvalue(L, 1); |
328 lua_pushvalue(L, 1); |
319 lua_pushboolean(L, 0); |
329 lua_pushboolean(L, 0); |
320 } else { |
330 } else { |
321 lua_pushvalue(L, 1); |
331 lua_pushvalue(L, 1); |
325 lua_pushcclosure(L, next_iterator, 2); |
335 lua_pushcclosure(L, next_iterator, 2); |
326 return 1; |
336 return 1; |
327 } |
337 } |
328 |
338 |
329 /* |
339 /* |
330 * table = statement:row(named_indexes) |
|
331 */ |
|
332 static int statement_row(lua_State *L) { |
|
333 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
|
334 int named_columns = lua_toboolean(L, 2); |
|
335 |
|
336 return statement_fetch_impl(L, statement, named_columns); |
|
337 } |
|
338 |
|
339 /* |
|
340 * __gc |
340 * __gc |
341 */ |
341 */ |
342 static int statement_gc(lua_State *L) { |
342 static int statement_gc(lua_State *L) { |
343 /* always free the handle */ |
343 /* always free the handle */ |
344 statement_close(L); |
344 statement_close(L); |
379 int dbd_mysql_statement(lua_State *L) { |
379 int dbd_mysql_statement(lua_State *L) { |
380 static const luaL_Reg statement_methods[] = { |
380 static const luaL_Reg statement_methods[] = { |
381 {"close", statement_close}, |
381 {"close", statement_close}, |
382 {"execute", statement_execute}, |
382 {"execute", statement_execute}, |
383 {"fetch", statement_fetch}, |
383 {"fetch", statement_fetch}, |
384 {"row", statement_row}, |
384 {"rows", statement_rows}, |
385 {NULL, NULL} |
385 {NULL, NULL} |
386 }; |
386 }; |
387 |
387 |
388 static const luaL_Reg statement_class_methods[] = { |
388 static const luaL_Reg statement_class_methods[] = { |
389 {NULL, NULL} |
389 {NULL, NULL} |