Skip to content

Commit 1841e6b

Browse files
committed
add disable option for sqlite3_expanded_sql
make sqlite3_expanded_sql use optional and give a warning at compile time along with a exception at runtime when used in an application
1 parent 0d2550b commit 1841e6b

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ if (SQLITECPP_DISABLE_STD_FILESYSTEM)
304304
add_definitions(-DSQLITECPP_DISABLE_STD_FILESYSTEM)
305305
endif (SQLITECPP_DISABLE_STD_FILESYSTEM)
306306

307+
## disable the optional support for sqlite3_expanded_sql (from sqlite3 3.14.0)
308+
option(SQLITECPP_DISABLE_EXPANDED_SQL "Disable the use of sqlite3_expanded_sql in SQLiteCpp." OFF)
309+
if (SQLITECPP_DISABLE_EXPANDED_SQL)
310+
message (STATUS "Disabling sqlite3_expanded_sql support")
311+
add_definitions(-DSQLITECPP_DISABLE_EXPANDED_SQL)
312+
endif (SQLITECPP_DISABLE_EXPANDED_SQL)
313+
307314
# Link target with pthread and dl for Unix
308315
if (UNIX)
309316
set(THREADS_PREFER_PTHREAD_FLAG ON)

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ if get_option('SQLITECPP_DISABLE_STD_FILESYSTEM')
134134
sqlitecpp_cxx_flags += ['-DSQLITECPP_DISABLE_STD_FILESYSTEM']
135135
endif
136136

137+
## get the user option for the SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
138+
disable_sqlitecpp_expanded_sql = get_option('SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL')
139+
140+
## Disable the use of sqlite3_expanded_sql (from sqlite3 3.14.0)
141+
if disable_sqlitecpp_expanded_sql
142+
sqlitecpp_args += ['-DSQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL']
143+
endif
144+
137145
## stack protection hardening
138146
if get_option('SQLITECPP_USE_STACK_PROTECTION')
139147
## if is on MinGW-W64 give a warning that is not supported

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ option('SQLITE_USE_LEGACY_STRUCT', type: 'boolean', value: false, description: '
1313
option('SQLITE_OMIT_LOAD_EXTENSION', type: 'boolean', value: false, description: 'Enable ommit load extension.')
1414
## Disable the support for std::filesystem (C++17)
1515
option('SQLITECPP_DISABLE_STD_FILESYSTEM', type: 'boolean', value: false, description: 'Disable the support for std::filesystem (C++17)')
16+
## Disable the support for sqlite3_expanded_sql (since SQLite 3.14.0)
17+
option('SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL', type: 'boolean', value: false, description: 'Disable the support for sqlite3_expanded_sql (since SQLite 3.14.0)')
1618
## Stack protection is not supported on MinGW-W64 on Windows, allow this flag to be turned off.
1719
option('SQLITECPP_USE_STACK_PROTECTION', type: 'boolean', value: true, description: 'Enable stack protection for MySQL.')
1820
## Enable build for the tests of SQLiteC++

src/Statement.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818
#include <sqlite3.h>
1919

20+
// check for if SQLite3 version >= 3.14.0
21+
#if SQLITE_VERSION_NUMBER < 3014000
22+
#warning "SQLite3 version is less than 3.14.0, so expanded SQL is not available"
23+
#warning "To use expanded SQL, please upgrade to SQLite3 version 3.14.0 or later"
24+
#warning "If you want to disable this warning, define SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL"
25+
#warning "or use the specific project option in your build system"
26+
#warning "disabling expanded SQL support"
27+
#define SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
28+
#endif
29+
30+
2031
namespace SQLite
2132
{
2233

@@ -331,14 +342,20 @@ const char* Statement::getErrorMsg() const noexcept
331342
return sqlite3_errmsg(mpSQLite);
332343
}
333344

345+
334346
// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded.
335347
std::string Statement::getExpandedSQL() const {
348+
#ifdef SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
349+
throw SQLite::Exception("this version of SQLiteCpp does not support expanded SQL");
350+
#else
336351
char* expanded = sqlite3_expanded_sql(getPreparedStatement());
337352
std::string expandedString(expanded);
338353
sqlite3_free(expanded);
339354
return expandedString;
355+
#endif
340356
}
341357

358+
342359
// Prepare SQLite statement object and return shared pointer to this object
343360
Statement::TStatementPtr Statement::prepareStatement()
344361
{

0 commit comments

Comments
 (0)