348 statement_close(L); |
348 statement_close(L); |
349 |
349 |
350 return 0; |
350 return 0; |
351 } |
351 } |
352 |
352 |
|
353 /* |
|
354 * __tostring |
|
355 */ |
|
356 static int statement_tostring(lua_State *L) { |
|
357 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT); |
|
358 |
|
359 lua_pushfstring(L, "%s: %p", DBD_POSTGRESQL_STATEMENT, statement); |
|
360 |
|
361 return 1; |
|
362 } |
|
363 |
353 int dbd_postgresql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
364 int dbd_postgresql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { |
354 statement_t *statement = NULL; |
365 statement_t *statement = NULL; |
355 ExecStatusType status; |
366 ExecStatusType status; |
356 PGresult *result = NULL; |
367 PGresult *result = NULL; |
357 char *new_sql; |
368 char *new_sql; |
424 lua_setfield(L, -2, "__index"); |
435 lua_setfield(L, -2, "__index"); |
425 |
436 |
426 lua_pushcfunction(L, statement_gc); |
437 lua_pushcfunction(L, statement_gc); |
427 lua_setfield(L, -2, "__gc"); |
438 lua_setfield(L, -2, "__gc"); |
428 |
439 |
|
440 lua_pushcfunction(L, statement_tostring); |
|
441 lua_setfield(L, -2, "__tostring"); |
|
442 |
429 luaL_register(L, DBD_POSTGRESQL_STATEMENT, statement_class_methods); |
443 luaL_register(L, DBD_POSTGRESQL_STATEMENT, statement_class_methods); |
430 |
444 |
431 return 1; |
445 return 1; |
432 } |
446 } |