Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ if (SQLITECPP_DISABLE_STD_FILESYSTEM)
add_definitions(-DSQLITECPP_DISABLE_STD_FILESYSTEM)
endif (SQLITECPP_DISABLE_STD_FILESYSTEM)

## disable the optional support for sqlite3_expanded_sql (from sqlite3 3.14.0)
option(SQLITECPP_DISABLE_EXPANDED_SQL "Disable the use of sqlite3_expanded_sql in SQLiteCpp." OFF)
if (SQLITECPP_DISABLE_EXPANDED_SQL)
message (STATUS "Disabling sqlite3_expanded_sql support")
target_compile_definitions(SQLiteCpp PUBLIC SQLITECPP_DISABLE_EXPANDED_SQL)
endif (SQLITECPP_DISABLE_EXPANDED_SQL)

# Link target with pthread and dl for Unix
if (UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ if get_option('SQLITECPP_DISABLE_STD_FILESYSTEM')
sqlitecpp_cxx_flags += ['-DSQLITECPP_DISABLE_STD_FILESYSTEM']
endif

## get the user option for the SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
disable_sqlitecpp_expanded_sql = get_option('SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL')

## Disable the use of sqlite3_expanded_sql (from sqlite3 3.14.0)
if disable_sqlitecpp_expanded_sql
sqlitecpp_args += ['-DSQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL']
endif

## stack protection hardening
if get_option('SQLITECPP_USE_STACK_PROTECTION')
## if is on MinGW-W64 give a warning that is not supported
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ option('SQLITE_USE_LEGACY_STRUCT', type: 'boolean', value: false, description: '
option('SQLITE_OMIT_LOAD_EXTENSION', type: 'boolean', value: false, description: 'Enable ommit load extension.')
## Disable the support for std::filesystem (C++17)
option('SQLITECPP_DISABLE_STD_FILESYSTEM', type: 'boolean', value: false, description: 'Disable the support for std::filesystem (C++17)')
## Disable the support for sqlite3_expanded_sql (since SQLite 3.14.0)
option('SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL', type: 'boolean', value: false, description: 'Disable the support for sqlite3_expanded_sql (since SQLite 3.14.0)')
## Stack protection is not supported on MinGW-W64 on Windows, allow this flag to be turned off.
option('SQLITECPP_USE_STACK_PROTECTION', type: 'boolean', value: true, description: 'Enable stack protection for MySQL.')
## Enable build for the tests of SQLiteC++
Expand Down
17 changes: 17 additions & 0 deletions src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

#include <sqlite3.h>

// check for if SQLite3 version >= 3.14.0
#if SQLITE_VERSION_NUMBER < 3014000
#warning "SQLite3 version is less than 3.14.0, so expanded SQL is not available"
#warning "To use expanded SQL, please upgrade to SQLite3 version 3.14.0 or later"
#warning "If you want to disable this warning, define SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL"
#warning "or use the specific project option in your build system"
#warning "disabling expanded SQL support"
#define SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
#endif


namespace SQLite
{

Expand Down Expand Up @@ -331,14 +342,20 @@ const char* Statement::getErrorMsg() const noexcept
return sqlite3_errmsg(mpSQLite);
}


// Return a UTF-8 string containing the SQL text of prepared statement with bound parameters expanded.
std::string Statement::getExpandedSQL() const {
#ifdef SQLITECPP_DISABLE_SQLITE3_EXPANDED_SQL
throw SQLite::Exception("this version of SQLiteCpp does not support expanded SQL");
#else
char* expanded = sqlite3_expanded_sql(getPreparedStatement());
std::string expandedString(expanded);
sqlite3_free(expanded);
return expandedString;
#endif
}


// Prepare SQLite statement object and return shared pointer to this object
Statement::TStatementPtr Statement::prepareStatement()
{
Expand Down