72 |
72 |
73 statement->stmt = NULL; |
73 statement->stmt = NULL; |
74 } |
74 } |
75 |
75 |
76 lua_pushboolean(L, ok); |
76 lua_pushboolean(L, ok); |
|
77 return 1; |
|
78 } |
|
79 |
|
80 /* |
|
81 * column_names = statement:columns() |
|
82 */ |
|
83 static int statement_columns(lua_State *L) { |
|
84 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); |
|
85 |
|
86 int i; |
|
87 int num_columns; |
|
88 int d = 1; |
|
89 |
|
90 if (!statement->stmt) { |
|
91 luaL_error(L, DBI_ERR_INVALID_STATEMENT); |
|
92 return 0; |
|
93 } |
|
94 |
|
95 num_columns = sqlite3_column_count(statement->stmt); |
|
96 lua_newtable(L); |
|
97 for (i = 0; i < num_columns; i++) { |
|
98 const char *name = sqlite3_column_name(statement->stmt, i); |
|
99 |
|
100 LUA_PUSH_ARRAY_STRING(d, name); |
|
101 } |
|
102 |
77 return 1; |
103 return 1; |
78 } |
104 } |
79 |
105 |
80 /* |
106 /* |
81 * success,err = statement:execute(...) |
107 * success,err = statement:execute(...) |
338 |
364 |
339 int dbd_sqlite3_statement(lua_State *L) { |
365 int dbd_sqlite3_statement(lua_State *L) { |
340 static const luaL_Reg statement_methods[] = { |
366 static const luaL_Reg statement_methods[] = { |
341 {"affected", statement_affected}, |
367 {"affected", statement_affected}, |
342 {"close", statement_close}, |
368 {"close", statement_close}, |
|
369 {"columns", statement_columns}, |
343 {"execute", statement_execute}, |
370 {"execute", statement_execute}, |
344 {"fetch", statement_fetch}, |
371 {"fetch", statement_fetch}, |
345 {"rows", statement_rows}, |
372 {"rows", statement_rows}, |
346 {"rowcount", statement_rowcount}, |
373 {"rowcount", statement_rowcount}, |
347 {NULL, NULL} |
374 {NULL, NULL} |