}
else {
if (!lua_checkstack (L, (ctx->cmds_pending * 2) + 1)) {
- return luaL_error (L, "cannot resiz stack to fit %d commands",
+ return luaL_error (L, "cannot resize stack to fit %d commands",
ctx->cmds_pending);
}
{NULL, NULL}
};
+static void lua_sqlite3_push_row (lua_State *L, sqlite3_stmt *stmt);
+
static sqlite3 *
lua_check_sqlite3 (lua_State * L, gint pos)
{
const gchar *query = luaL_checkstring (L, 2);
sqlite3_stmt *stmt;
gboolean ret = FALSE;
- gint top, rc;
+ gint top = 1, rc;
if (db && query) {
if (sqlite3_prepare_v2 (db, query, -1, &stmt, NULL) != SQLITE_OK) {
msg_err ("cannot prepare query %s: %s", query, sqlite3_errmsg (db));
- lua_pushstring (L, sqlite3_errmsg (db));
- lua_error (L);
+ return luaL_error (L, sqlite3_errmsg (db));
}
else {
top = lua_gettop (L);
}
rc = sqlite3_step (stmt);
+ top = 1;
if (rc == SQLITE_ROW || rc == SQLITE_OK || rc == SQLITE_DONE) {
ret = TRUE;
+
+ if (rc == SQLITE_ROW) {
+ lua_sqlite3_push_row (L, stmt);
+ top = 2;
+ }
}
else {
msg_warn ("sqlite3 error: %s", sqlite3_errmsg (db));
lua_pushboolean (L, ret);
- return 1;
+ return top;
}
static void