From f927c17c606bb6f13376a683f2f6776fc4c3e4c9 Mon Sep 17 00:00:00 2001 From: peavey Date: Sun, 14 Jan 2007 23:14:23 +0000 Subject: Hook qlite3_update_hook to queries to also catch affected rows on UPDATE/INSERT/DELETE. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6344 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_sqlite3.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index 469d5e153..5fba3880e 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -126,6 +126,11 @@ class SQLite3Result : public SQLresult rows++; } + void UpdateAffectedCount() + { + rows++; + } + virtual int Rows() { return rows; @@ -339,8 +344,7 @@ class SQLConn : public classbase *queryend = 0; req.query.q = query; -// Instance->Log(DEBUG, "<******> Doing query: " + ConvToStr(req.query.q.data())); - + //Instance->Log(DEBUG, "<******> Doing query: " + ConvToStr(req.query.q.data())); SQLite3Result* res = new SQLite3Result(mod, req.GetSource(), req.id); res->dbid = host.id; res->query = req.query.q; @@ -349,6 +353,7 @@ class SQLConn : public classbase params.push_back(res); char *errmsg = 0; + sqlite3_update_hook(conn, QueryUpdateHook, ¶ms); if (sqlite3_exec(conn, req.query.q.data(), QueryResult, ¶ms, &errmsg) != SQLITE_OK) { Instance->Log(DEBUG, "Query failed: " + ConvToStr(errmsg)); @@ -372,11 +377,22 @@ class SQLConn : public classbase return 0; } + static void QueryUpdateHook(void *params, int eventid, char const * azSQLite, char const * azColName, sqlite_int64 rowid) + { + paramlist* p = (paramlist*)params; + ((SQLConn*)(*p)[0])->AffectedReady(((SQLite3Result*)(*p)[1])); + } + void ResultReady(SQLite3Result *res, int cols, char **data, char **colnames) { res->AddRow(cols, data, colnames); } + void AffectedReady(SQLite3Result *res) + { + res->UpdateAffectedCount(); + } + int OpenDB() { return sqlite3_open(host.host.c_str(), &conn); -- cgit v1.2.3