From ce450996954b32801bfcb44d3e21627dd6d7dd83 Mon Sep 17 00:00:00 2001 From: Oleg Smolsky Date: Sat, 15 Jun 2019 10:27:30 -0700 Subject: [PATCH 1/2] Add Statement::getExtendedSQL() - it returns a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded --- include/SQLiteCpp/Statement.h | 4 ++++ src/Statement.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index c5c6e3f..df24816 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -608,6 +608,10 @@ public: { return mQuery; } + + // Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded. + std::string getExtendedSQL(); + /// Return the number of columns in the result set returned by the prepared statement inline int getColumnCount() const { diff --git a/src/Statement.cpp b/src/Statement.cpp index 5c285d6..9ea8e6e 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -401,17 +401,24 @@ int Statement::getErrorCode() const noexcept // nothrow { return sqlite3_errcode(mStmtPtr); } + // Return the extended numeric result code for the most recent failed API call (if any). int Statement::getExtendedErrorCode() const noexcept // nothrow { return sqlite3_extended_errcode(mStmtPtr); } + // Return UTF-8 encoded English language explanation of the most recent failed API call (if any). const char* Statement::getErrorMsg() const noexcept // nothrow { return sqlite3_errmsg(mStmtPtr); } +// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded. +std::string Statement::getExtendedSQL() { + return sqlite3_expanded_sql(mStmtPtr); +} + //////////////////////////////////////////////////////////////////////////////// // Internal class : shared pointer to the sqlite3_stmt SQLite Statement Object //////////////////////////////////////////////////////////////////////////////// From 7dba62bcf16cc9bf44c5c444ea2f41be9461b6d3 Mon Sep 17 00:00:00 2001 From: Oleg Smolsky Date: Tue, 18 Jun 2019 09:42:35 -0700 Subject: [PATCH 2/2] Added a minimal test for Statement::getExtendedSQL() - there is nothing conditional here in the wrapper --- tests/Statement_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 4d31e5d..f351d91 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -252,6 +252,7 @@ TEST(Statement, bindings) { insert.bind(1, text); insert.bind(2, integer); insert.bind(3, dbl); + EXPECT_EQ(insert.getExtendedSQL(), "INSERT INTO test VALUES (NULL, 'first', -123, 0.123)"); EXPECT_EQ(1, insert.exec()); EXPECT_EQ(SQLITE_DONE, db.getErrorCode());