diff --git a/src/lua/LuaIQuery.cpp b/src/lua/LuaIQuery.cpp index 981c0d3..430514e 100644 --- a/src/lua/LuaIQuery.cpp +++ b/src/lua/LuaIQuery.cpp @@ -77,7 +77,7 @@ void LuaIQuery::runAbortedCallback(ILuaBase *LUA, const std::shared_ptr &data) { +void LuaIQuery::runErrorCallback(ILuaBase *LUA, const std::shared_ptr &iQuery, const std::shared_ptr &data) { if (data->m_tableReference == 0) return; if (!LuaIQuery::pushCallbackReference(LUA, data->m_errorReference, data->m_tableReference, @@ -87,7 +87,8 @@ void LuaIQuery::runErrorCallback(ILuaBase *LUA, const std::shared_ptrReferencePush(data->m_tableReference); auto error = data->getError(); LUA->PushString(error.c_str()); - LuaObject::pcallWithErrorReporter(LUA, 2); + LUA->PushString(iQuery->getSQLString().c_str()); + LuaObject::pcallWithErrorReporter(LUA, 3); } void LuaIQuery::addMetaTableFunctions(ILuaBase *LUA) { @@ -160,7 +161,7 @@ void LuaIQuery::runCallback(ILuaBase *LUA, const std::shared_ptr &iQuery case QUERY_NONE: break; //Should not happen case QUERY_ERROR: - runErrorCallback(LUA, data); + runErrorCallback(LUA, iQuery, data); break; case QUERY_SUCCESS: if (auto query = std::dynamic_pointer_cast(iQuery)) { diff --git a/src/lua/LuaIQuery.h b/src/lua/LuaIQuery.h index 42c5917..1f8821c 100644 --- a/src/lua/LuaIQuery.h +++ b/src/lua/LuaIQuery.h @@ -26,7 +26,7 @@ class LuaIQuery : public LuaObject { static void runAbortedCallback(ILuaBase *LUA, const std::shared_ptr &data); - static void runErrorCallback(ILuaBase *LUA, const std::shared_ptr &data); + static void runErrorCallback(ILuaBase *LUA, const std::shared_ptr &iQuery, const std::shared_ptr &data); static void runCallback(ILuaBase *LUA, const std::shared_ptr &query, const std::shared_ptr &data); diff --git a/src/mysql/IQuery.h b/src/mysql/IQuery.h index 8cbf218..a359a87 100644 --- a/src/mysql/IQuery.h +++ b/src/mysql/IQuery.h @@ -75,6 +75,8 @@ class IQuery : public std::enable_shared_from_this { std::vector> abort(); + virtual std::string getSQLString() = 0; + void wait(bool shouldSwap); bool hasCallbackData() const { diff --git a/src/mysql/PingQuery.h b/src/mysql/PingQuery.h index 3fbbff9..bf4c478 100644 --- a/src/mysql/PingQuery.h +++ b/src/mysql/PingQuery.h @@ -1,6 +1,7 @@ #pragma once #ifndef PINGQUERY_ #define PINGQUERY_ + #include #include "Query.h" #include "MySQLHeader.h" @@ -9,12 +10,19 @@ class PingQuery : public Query { - friend class Database; + friend class Database; + public: - ~PingQuery() override; + ~PingQuery() override; + protected: - explicit PingQuery(const std::shared_ptr& dbase); - void executeStatement(Database &database, MYSQL* m_sql, const std::shared_ptr &data) override; - bool pingSuccess = false; + explicit PingQuery(const std::shared_ptr &dbase); + + std::string getSQLString() override { return ""; }; + + void executeStatement(Database &database, MYSQL *m_sql, const std::shared_ptr &data) override; + + bool pingSuccess = false; }; + #endif \ No newline at end of file diff --git a/src/mysql/Query.h b/src/mysql/Query.h index 3618f67..4572bbb 100644 --- a/src/mysql/Query.h +++ b/src/mysql/Query.h @@ -18,7 +18,7 @@ class Query : public IQuery { public: ~Query() override; - void executeStatement(Database &database, MYSQL *m_sql, const std::shared_ptr& data) override; + void executeStatement(Database &database, MYSQL *m_sql, const std::shared_ptr &data) override; my_ulonglong lastInsert(); @@ -32,7 +32,10 @@ class Query : public IQuery { int m_dataReference = 0; - static std::shared_ptr create(const std::shared_ptr &dbase, const std::string& query); + std::string getSQLString() override { return m_query; }; + + static std::shared_ptr create(const std::shared_ptr &dbase, const std::string &query); + protected: Query(const std::shared_ptr &dbase, std::string query); @@ -75,6 +78,7 @@ class QueryData : public IQueryData { std::deque m_affectedRows; std::deque m_insertIds; std::deque m_results; + QueryData() = default; }; diff --git a/src/mysql/Transaction.h b/src/mysql/Transaction.h index 7df286e..b6a0546 100644 --- a/src/mysql/Transaction.h +++ b/src/mysql/Transaction.h @@ -30,14 +30,17 @@ class Transaction : public IQuery { static std::shared_ptr create(const std::shared_ptr &database); + std::string getSQLString() override { return ""; }; + protected: - void executeStatement(Database &database, MYSQL *connection, const std::shared_ptr& data) override; + void executeStatement(Database &database, MYSQL *connection, const std::shared_ptr &data) override; explicit Transaction(const std::shared_ptr &database) : IQuery(database) { } + private: - static void applyChildResultStatus(const std::shared_ptr& data); + static void applyChildResultStatus(const std::shared_ptr &data); static void mysqlAutocommit(MYSQL *sql, bool auto_mode);