187 |
187 |
188 lua_pushboolean(L, 1); |
188 lua_pushboolean(L, 1); |
189 return 1; |
189 return 1; |
190 } |
190 } |
191 |
191 |
192 static int statement_fetch_impl(lua_State *L, int named_columns) { |
192 static int statement_fetch_impl(lua_State *L, statement_t *statement, int named_columns) { |
193 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
|
194 int column_count; |
193 int column_count; |
195 MYSQL_BIND *bind = NULL; |
194 MYSQL_BIND *bind = NULL; |
196 const char *error_message = NULL; |
195 const char *error_message = NULL; |
197 |
196 |
198 if (!statement->stmt) { |
197 if (!statement->stmt) { |
301 } |
300 } |
302 |
301 |
303 return 1; |
302 return 1; |
304 } |
303 } |
305 |
304 |
|
305 static int next_iterator(lua_State *L) { |
|
306 statement_t *statement = (statement_t *)luaL_checkudata(L, lua_upvalueindex(1), DBD_MYSQL_STATEMENT); |
|
307 int named_columns = lua_toboolean(L, lua_upvalueindex(2)); |
|
308 |
|
309 return statement_fetch_impl(L, statement, named_columns); |
|
310 } |
|
311 |
306 /* |
312 /* |
307 * array = statement:fetch() |
313 * iterfunc = statement:fetch(named_indexes) |
308 */ |
314 */ |
|
315 |
309 static int statement_fetch(lua_State *L) { |
316 static int statement_fetch(lua_State *L) { |
310 return statement_fetch_impl(L, 0); |
317 if (lua_gettop(L) == 1) { |
|
318 lua_pushvalue(L, 1); |
|
319 lua_pushboolean(L, 0); |
|
320 } else { |
|
321 lua_pushvalue(L, 1); |
|
322 lua_pushboolean(L, lua_toboolean(L, 2)); |
|
323 } |
|
324 |
|
325 lua_pushcclosure(L, next_iterator, 2); |
|
326 return 1; |
311 } |
327 } |
312 |
328 |
313 /* |
329 /* |
314 * hashmap = statement:fetchtable() |
330 * table = statement:row(named_indexes) |
315 */ |
331 */ |
316 static int statement_fetchtable(lua_State *L) { |
332 static int statement_row(lua_State *L) { |
317 return statement_fetch_impl(L, 1); |
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); |
318 } |
337 } |
319 |
338 |
320 /* |
339 /* |
321 * __gc |
340 * __gc |
322 */ |
341 */ |
360 int dbd_mysql_statement(lua_State *L) { |
379 int dbd_mysql_statement(lua_State *L) { |
361 static const luaL_Reg statement_methods[] = { |
380 static const luaL_Reg statement_methods[] = { |
362 {"close", statement_close}, |
381 {"close", statement_close}, |
363 {"execute", statement_execute}, |
382 {"execute", statement_execute}, |
364 {"fetch", statement_fetch}, |
383 {"fetch", statement_fetch}, |
365 {"fetchtable", statement_fetchtable}, |
384 {"row", statement_row}, |
366 {NULL, NULL} |
385 {NULL, NULL} |
367 }; |
386 }; |
368 |
387 |
369 static const luaL_Reg statement_class_methods[] = { |
388 static const luaL_Reg statement_class_methods[] = { |
370 {NULL, NULL} |
389 {NULL, NULL} |