From 13df5e20c9afcf518bf6c4fa064ba681bd29f8e8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 21 May 2018 02:36:19 +0200 Subject: Add sql debug, fix action counter in request wrong number --- include/odhtdb/sql/Sql.hpp | 3 +++ project.conf | 3 +++ src/Database.cpp | 2 +- src/sql/Sql.cpp | 17 +++++++++++++++++ src/sql/SqlExec.cpp | 11 +++++++++++ src/sql/SqlQuery.cpp | 11 +++++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/odhtdb/sql/Sql.hpp b/include/odhtdb/sql/Sql.hpp index cb740a4..21517e4 100644 --- a/include/odhtdb/sql/Sql.hpp +++ b/include/odhtdb/sql/Sql.hpp @@ -1,6 +1,7 @@ #pragma once #include "../DataView.hpp" +#include class sqlite3; class sqlite3_stmt; @@ -24,6 +25,8 @@ namespace odhtdb SqlArg(u64 data) : uinteger64(data), type(Type::UINT64) {} int bind(sqlite3_stmt *stmt, int paramIndex) const; + + std::string toString() const; private: union { diff --git a/project.conf b/project.conf index b3e01cc..6c4316a 100644 --- a/project.conf +++ b/project.conf @@ -8,6 +8,9 @@ tests = "tests" [config] expose_include_dirs = ["include"] +[define] +ODHTDB_SQL_DEBUG = "1" + [dependencies] opendht = "1.7.0" libsodium = "1.0.16" diff --git a/src/Database.cpp b/src/Database.cpp index 169c066..27caba0 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -412,7 +412,7 @@ namespace odhtdb databaseStorage.fetchNodeUserLatestActionCounter(*nodeToSeed.getRequestHash(), [&userLatestActionCounter](const DataView userPublicKeyRaw, u64 latestActionCounter) { Signature::PublicKey userPublicKey((const char*)userPublicKeyRaw.data, userPublicKeyRaw.size); - userLatestActionCounter[userPublicKey] = std::max(userLatestActionCounter[userPublicKey], latestActionCounter); + userLatestActionCounter[userPublicKey] = std::max(userLatestActionCounter[userPublicKey], latestActionCounter + 1); }); for(auto userLatestActionCounterData : userLatestActionCounter) diff --git a/src/sql/Sql.cpp b/src/sql/Sql.cpp index 4e65ddb..0bfbbe6 100644 --- a/src/sql/Sql.cpp +++ b/src/sql/Sql.cpp @@ -21,6 +21,23 @@ namespace odhtdb return SQLITE_OK; } + std::string SqlArg::toString() const + { + switch(type) + { + case Type::DATA_VIEW: + return std::string((const char*)dataView.data, dataView.size); + case Type::INT: + return std::to_string(integer); + case Type::INT64: + return std::to_string(integer64); + case Type::UINT64: // TODO: Find a way to use u64 in sqlite + return std::to_string(uinteger64); + default: + return ""; + } + } + SqlTransaction::SqlTransaction(sqlite3 *_db) : db(_db) { diff --git a/src/sql/SqlExec.cpp b/src/sql/SqlExec.cpp index bdb0fbd..52d953f 100644 --- a/src/sql/SqlExec.cpp +++ b/src/sql/SqlExec.cpp @@ -1,4 +1,5 @@ #include "../../include/odhtdb/sql/SqlExec.hpp" +#include "../../include/odhtdb/Log.hpp" #include namespace odhtdb @@ -39,6 +40,16 @@ namespace odhtdb throw SqlExecException(errMsg); } +#ifdef ODHTDB_SQL_DEBUG + Log::debug("Executing sql exec: %s; args(%u): ", sqlite3_sql(stmt), args.size()); + usize i = 0; + for(const SqlArg &arg : args) + { + Log::debug("arg(%u): %s", i, arg.toString().c_str()); + ++i; + } +#endif + int paramIndex = 1; for(const SqlArg &arg : args) { diff --git a/src/sql/SqlQuery.cpp b/src/sql/SqlQuery.cpp index 6201332..24694db 100644 --- a/src/sql/SqlQuery.cpp +++ b/src/sql/SqlQuery.cpp @@ -1,4 +1,5 @@ #include "../../include/odhtdb/sql/SqlQuery.hpp" +#include "../../include/odhtdb/Log.hpp" #include namespace odhtdb @@ -29,6 +30,16 @@ namespace odhtdb throw SqlQueryException(errMsg); } +#ifdef ODHTDB_SQL_DEBUG + Log::debug("Executing sql query: %s; args(%u): ", sql, args.size()); + usize i = 0; + for(const SqlArg &arg : args) + { + Log::debug("arg(%u): %s", i, arg.toString().c_str()); + ++i; + } +#endif + int paramIndex = 1; for(const SqlArg &arg : args) { -- cgit v1.2.3