]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Return result from sqlite queries
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Feb 2018 12:58:29 +0000 (12:58 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Feb 2018 13:57:42 +0000 (13:57 +0000)
src/lua/lua_redis.c
src/lua/lua_sqlite3.c

index 557639cefc8cf7a7dc3f9e02808f792c2f8cd49a..3651f9c7a21ac4215947ec3f4c2e6409861701e6 100644 (file)
@@ -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);
                        }
 
index bb1fcdeba408b43fc4672b4dfb741b98b5394cdb..2a451dc31cc5d4c4c0fa75a85b718f90b343dbf4 100644 (file)
@@ -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