Rename Statement::getExpandedSQL() from #201 and fix #203 #205 memory leak

This commit is contained in:
Sébastien Rombauts 2019-06-24 21:45:18 +02:00
parent a68397c7ac
commit 49c1f6c08d
4 changed files with 8 additions and 4 deletions

View File

@ -136,3 +136,4 @@ Version ?
- #192 Add wrapper for bind parameter count - #192 Add wrapper for bind parameter count
- #197 Add tuple_bind and execute_many - #197 Add tuple_bind and execute_many
- #199 Fix #156 misleading error message in exception from Statement::exec - #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

View File

@ -610,7 +610,7 @@ public:
} }
// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded. // 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 /// Return the number of columns in the result set returned by the prepared statement
inline int getColumnCount() const inline int getColumnCount() const

View File

@ -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. // Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded.
std::string Statement::getExtendedSQL() { std::string Statement::getExpandedSQL() {
return sqlite3_expanded_sql(mStmtPtr); char* expanded = sqlite3_expanded_sql(mStmtPtr);
std::string expandedString(expanded);
sqlite3_free(expanded);
return expandedString;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -257,7 +257,7 @@ TEST(Statement, bindings)
insert.bind(1, text); insert.bind(1, text);
insert.bind(2, integer); insert.bind(2, integer);
insert.bind(3, dbl); 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(1, insert.exec());
EXPECT_EQ(SQLITE_DONE, db.getErrorCode()); EXPECT_EQ(SQLITE_DONE, db.getErrorCode());