aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-22 12:58:29 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-22 13:57:42 +0000
commit946ccf2dd8c9a9ed3f79a20732877f6edb2e5b33 (patch)
tree9fe11203eec68efc2bcc323bc386acda2880ba67 /src
parent8b566496f827630b29552fe5bb2fb33e42ef4408 (diff)
downloadrspamd-946ccf2dd8c9a9ed3f79a20732877f6edb2e5b33.tar.gz
rspamd-946ccf2dd8c9a9ed3f79a20732877f6edb2e5b33.zip
[Minor] Return result from sqlite queries
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_redis.c2
-rw-r--r--src/lua/lua_sqlite3.c15
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