24 } |
24 } |
25 |
25 |
26 return lua_type; |
26 return lua_type; |
27 } |
27 } |
28 |
28 |
|
29 /* |
|
30 * success = statement:close() |
|
31 */ |
29 static int statement_close(lua_State *L) { |
32 static int statement_close(lua_State *L) { |
30 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
33 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
31 |
34 |
32 if (statement->metadata) { |
35 if (statement->metadata) { |
33 mysql_free_result(statement->metadata); |
36 mysql_free_result(statement->metadata); |
38 } |
41 } |
39 |
42 |
40 return 1; |
43 return 1; |
41 } |
44 } |
42 |
45 |
|
46 /* |
|
47 * success = statement:execute(...) |
|
48 */ |
43 static int statement_execute(lua_State *L) { |
49 static int statement_execute(lua_State *L) { |
44 int n = lua_gettop(L); |
50 int n = lua_gettop(L); |
45 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
51 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
46 int num_bind_params = n - 1; |
52 int num_bind_params = n - 1; |
47 |
53 |
228 } |
234 } |
229 |
235 |
230 return 1; |
236 return 1; |
231 } |
237 } |
232 |
238 |
233 |
239 /* |
|
240 * array = statement:fetch() |
|
241 */ |
234 static int statement_fetch(lua_State *L) { |
242 static int statement_fetch(lua_State *L) { |
235 return statement_fetch_impl(L, 0); |
243 return statement_fetch_impl(L, 0); |
236 } |
244 } |
237 |
245 |
|
246 /* |
|
247 * hashmap = statement:fetchtable() |
|
248 */ |
238 static int statement_fetchtable(lua_State *L) { |
249 static int statement_fetchtable(lua_State *L) { |
239 return statement_fetch_impl(L, 1); |
250 return statement_fetch_impl(L, 1); |
240 } |
251 } |
241 |
252 |
|
253 /* |
|
254 * __gc |
|
255 */ |
242 static int statement_gc(lua_State *L) { |
256 static int statement_gc(lua_State *L) { |
243 /* always free the handle */ |
257 /* always free the handle */ |
244 statement_close(L); |
258 statement_close(L); |
245 |
259 |
246 return 0; |
260 return 0; |
247 } |
261 } |
248 |
|
249 |
|
250 static const luaL_Reg statement_methods[] = { |
|
251 {"close", statement_close}, |
|
252 {"execute", statement_execute}, |
|
253 {"fetch", statement_fetch}, |
|
254 {"fetchtable", statement_fetchtable}, |
|
255 {NULL, NULL} |
|
256 }; |
|
257 |
|
258 static const luaL_Reg statement_class_methods[] = { |
|
259 {NULL, NULL} |
|
260 }; |
|
261 |
262 |
262 int dbd_mysql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
263 int dbd_mysql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
263 unsigned long sql_len = strlen(sql_query); |
264 unsigned long sql_len = strlen(sql_query); |
264 |
265 |
265 statement_t *statement = NULL; |
266 statement_t *statement = NULL; |
286 |
287 |
287 return 1; |
288 return 1; |
288 } |
289 } |
289 |
290 |
290 int dbd_mysql_statement(lua_State *L) { |
291 int dbd_mysql_statement(lua_State *L) { |
|
292 static const luaL_Reg statement_methods[] = { |
|
293 {"close", statement_close}, |
|
294 {"execute", statement_execute}, |
|
295 {"fetch", statement_fetch}, |
|
296 {"fetchtable", statement_fetchtable}, |
|
297 {NULL, NULL} |
|
298 }; |
|
299 |
|
300 static const luaL_Reg statement_class_methods[] = { |
|
301 {NULL, NULL} |
|
302 }; |
|
303 |
291 luaL_newmetatable(L, DBD_MYSQL_STATEMENT); |
304 luaL_newmetatable(L, DBD_MYSQL_STATEMENT); |
292 luaL_register(L, 0, statement_methods); |
305 luaL_register(L, 0, statement_methods); |
293 lua_pushvalue(L,-1); |
306 lua_pushvalue(L,-1); |
294 lua_setfield(L, -2, "__index"); |
307 lua_setfield(L, -2, "__index"); |
295 |
308 |