diff --git a/CHANGELOG.md b/CHANGELOG.md index d26a2c0..9c80d81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -136,3 +136,4 @@ Version ? - #192 Add wrapper for bind parameter count - #197 Add tuple_bind and execute_many - #199 Fix #156 misleading error message in exception from Statement::exec +- #201 Add Statement::getExpandedSQL() to get the SQL text of prepared statement with bound parameters expanded \ No newline at end of file diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index df24816..f5e082c 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -610,7 +610,7 @@ public: } // Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded. - std::string getExtendedSQL(); + std::string getExpandedSQL(); /// 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 0e601f0..6af7556 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -426,8 +426,11 @@ const char* Statement::getErrorMsg() const noexcept // nothrow } // 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); +std::string Statement::getExpandedSQL() { + char* expanded = sqlite3_expanded_sql(mStmtPtr); + std::string expandedString(expanded); + sqlite3_free(expanded); + return expandedString; } //////////////////////////////////////////////////////////////////////////////// diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 3381359..a54a0c8 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -257,7 +257,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(insert.getExpandedSQL(), "INSERT INTO test VALUES (NULL, 'first', -123, 0.123)"); EXPECT_EQ(1, insert.exec()); EXPECT_EQ(SQLITE_DONE, db.getErrorCode());