From 946ccf2dd8c9a9ed3f79a20732877f6edb2e5b33 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 22 Feb 2018 12:58:29 +0000 Subject: [PATCH] [Minor] Return result from sqlite queries --- src/lua/lua_redis.c | 2 +- src/lua/lua_sqlite3.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 557639cef..3651f9c7a 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -1299,7 +1299,7 @@ lua_redis_exec (lua_State *L) } 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); } diff --git a/src/lua/lua_sqlite3.c b/src/lua/lua_sqlite3.c index bb1fcdeba..2a451dc31 100644 --- a/src/lua/lua_sqlite3.c +++ b/src/lua/lua_sqlite3.c @@ -62,6 +62,8 @@ static const struct luaL_reg sqlitestmtlib_m[] = { {NULL, NULL} }; +static void lua_sqlite3_push_row (lua_State *L, sqlite3_stmt *stmt); + static sqlite3 * lua_check_sqlite3 (lua_State * L, gint pos) { @@ -170,13 +172,12 @@ lua_sqlite3_sql (lua_State *L) 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); @@ -187,9 +188,15 @@ lua_sqlite3_sql (lua_State *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)); @@ -201,7 +208,7 @@ lua_sqlite3_sql (lua_State *L) lua_pushboolean (L, ret); - return 1; + return top; } static void -- 2.39.5