Skip to content

Commit

Permalink
Fallback for old SQLite versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zauguin committed Feb 14, 2017
1 parent 96b1230 commit 6c99c9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hdr/sqlite_modern_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ namespace sqlite {
}

std::string sql() {
#if SQLITE_VERSION_NUMBER >= 3014000
auto sqlite_deleter = [](void *ptr) {sqlite3_free(ptr);};
std::unique_ptr<char, decltype(sqlite_deleter)> str(sqlite3_expanded_sql(_stmt.get()), sqlite_deleter);
return str ? str.get() : original_sql();
#else
return original_sql();
#endif
}

std::string original_sql() {
Expand Down
4 changes: 4 additions & 0 deletions tests/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ int main() {
cerr << e.get_code() << ": " << e.what() << " during "
<< quoted(e.get_sql()) << endl;
expception_thrown = true;
#if SQLITE_VERSION_NUMBER >= 3014000
if(e.get_sql() != "INSERT INTO person (id,name) VALUES (1,'jack')") {
#else
if(e.get_sql() != "INSERT INTO person (id,name) VALUES (?,?)") {
#endif
cerr << "Wrong statement failed\n";
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 6c99c9b

Please sign in to comment.