From 70b43ec9b9ee5743166e705612936b9a1b376708 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 27 Jan 2016 14:06:17 +0000 Subject: [PATCH] Never set negative learn counts Issue: #496 --- src/libstat/backends/sqlite3_backend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index 7f57636e4..bead2cecb 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -190,8 +190,8 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] = }, [RSPAMD_STAT_BACKEND_DEC_LEARNS] = { .idx = RSPAMD_STAT_BACKEND_DEC_LEARNS, - .sql = "UPDATE languages SET learns=learns - 1 WHERE id=?1;" - "UPDATE users SET learns=learns - 1 WHERE id=?2;", + .sql = "UPDATE languages SET learns=MAX(0, learns - 1) WHERE id=?1;" + "UPDATE users SET learns=MAX(0, learns - 1) WHERE id=?2;", .stmt = NULL, .args = "II", .result = SQLITE_DONE, @@ -200,7 +200,7 @@ static struct rspamd_sqlite3_prstmt prepared_stmts[RSPAMD_STAT_BACKEND_MAX] = }, [RSPAMD_STAT_BACKEND_GET_LEARNS] = { .idx = RSPAMD_STAT_BACKEND_GET_LEARNS, - .sql = "SELECT sum(learns) FROM languages;", + .sql = "SELECT SUM(MAX(0, learns)) FROM languages;", .stmt = NULL, .args = "", .result = SQLITE_ROW, -- 2.39.5