Skip to content

Commit 49c1f6c

Browse files
committed
Rename Statement::getExpandedSQL() from #201 and fix #203 #205 memory leak
1 parent a68397c commit 49c1f6c

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ Version ?
136136
- #192 Add wrapper for bind parameter count
137137
- #197 Add tuple_bind and execute_many
138138
- #199 Fix #156 misleading error message in exception from Statement::exec
139+
- #201 Add Statement::getExpandedSQL() to get the SQL text of prepared statement with bound parameters expanded

include/SQLiteCpp/Statement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ class Statement
610610
}
611611

612612
// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded.
613-
std::string getExtendedSQL();
613+
std::string getExpandedSQL();
614614

615615
/// Return the number of columns in the result set returned by the prepared statement
616616
inline int getColumnCount() const

src/Statement.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,11 @@ const char* Statement::getErrorMsg() const noexcept // nothrow
426426
}
427427

428428
// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded.
429-
std::string Statement::getExtendedSQL() {
430-
return sqlite3_expanded_sql(mStmtPtr);
429+
std::string Statement::getExpandedSQL() {
430+
char* expanded = sqlite3_expanded_sql(mStmtPtr);
431+
std::string expandedString(expanded);
432+
sqlite3_free(expanded);
433+
return expandedString;
431434
}
432435

433436
////////////////////////////////////////////////////////////////////////////////

tests/Statement_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ TEST(Statement, bindings)
257257
insert.bind(1, text);
258258
insert.bind(2, integer);
259259
insert.bind(3, dbl);
260-
EXPECT_EQ(insert.getExtendedSQL(), "INSERT INTO test VALUES (NULL, 'first', -123, 0.123)");
260+
EXPECT_EQ(insert.getExpandedSQL(), "INSERT INTO test VALUES (NULL, 'first', -123, 0.123)");
261261
EXPECT_EQ(1, insert.exec());
262262
EXPECT_EQ(SQLITE_DONE, db.getErrorCode());
263263

0 commit comments

Comments
 (0)