--- a/dbd/sqlite3/statement.c Tue Feb 17 00:23:00 2009 +0000 +++ b/dbd/sqlite3/statement.c Fri Apr 17 23:46:12 2009 +0000 @@ -78,6 +78,32 @@ } /* + * column_names = statement:columns() + */ +static int statement_columns(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); + + int i; + int num_columns; + int d = 1; + + if (!statement->stmt) { + luaL_error(L, DBI_ERR_INVALID_STATEMENT); + return 0; + } + + num_columns = sqlite3_column_count(statement->stmt); + lua_newtable(L); + for (i = 0; i < num_columns; i++) { + const char *name = sqlite3_column_name(statement->stmt, i); + + LUA_PUSH_ARRAY_STRING(d, name); + } + + return 1; +} + +/* * success,err = statement:execute(...) */ static int statement_execute(lua_State *L) { @@ -340,6 +366,7 @@ static const luaL_Reg statement_methods[] = { {"affected", statement_affected}, {"close", statement_close}, + {"columns", statement_columns}, {"execute", statement_execute}, {"fetch", statement_fetch}, {"rows", statement_rows},