58 } |
58 } |
59 |
59 |
60 lua_pushboolean(L, 1); |
60 lua_pushboolean(L, 1); |
61 return 1; |
61 return 1; |
62 } |
62 } |
|
63 |
|
64 /* |
|
65 * column_names = statement:columns() |
|
66 */ |
|
67 static int statement_columns(lua_State *L) { |
|
68 statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); |
|
69 |
|
70 MYSQL_FIELD *fields; |
|
71 int i; |
|
72 int num_columns; |
|
73 int d = 1; |
|
74 |
|
75 if (!statement->stmt) { |
|
76 luaL_error(L, DBI_ERR_INVALID_STATEMENT); |
|
77 return 0; |
|
78 } |
|
79 |
|
80 fields = mysql_fetch_fields(statement->metadata); |
|
81 num_columns = mysql_num_fields(statement->metadata); |
|
82 lua_newtable(L); |
|
83 for (i = 0; i < num_columns; i++) { |
|
84 const char *name = fields[i].name; |
|
85 |
|
86 LUA_PUSH_ARRAY_STRING(d, name); |
|
87 } |
|
88 |
|
89 return 1; |
|
90 } |
|
91 |
63 |
92 |
64 /* |
93 /* |
65 * success,err = statement:execute(...) |
94 * success,err = statement:execute(...) |
66 */ |
95 */ |
67 static int statement_execute(lua_State *L) { |
96 static int statement_execute(lua_State *L) { |
411 |
434 |
412 int dbd_mysql_statement(lua_State *L) { |
435 int dbd_mysql_statement(lua_State *L) { |
413 static const luaL_Reg statement_methods[] = { |
436 static const luaL_Reg statement_methods[] = { |
414 {"affected", statement_affected}, |
437 {"affected", statement_affected}, |
415 {"close", statement_close}, |
438 {"close", statement_close}, |
|
439 {"columns", statement_columns}, |
416 {"execute", statement_execute}, |
440 {"execute", statement_execute}, |
417 {"fetch", statement_fetch}, |
441 {"fetch", statement_fetch}, |
418 {"rowcount", statement_rowcount}, |
442 {"rowcount", statement_rowcount}, |
419 {"rows", statement_rows}, |
443 {"rows", statement_rows}, |
420 {NULL, NULL} |
444 {NULL, NULL} |