From b99e1b0e7dc96a55aa1e8cbf7b3592afb5891990 Mon Sep 17 00:00:00 2001 From: Marcell Egyed Date: Wed, 11 Sep 2024 09:03:00 +0200 Subject: [PATCH] SQLite3: Enable execute() to run prepared_statements Limit execute to run only non-select statements. (Note: Does not apply to raw sql string select queries). --- include/sqlpp11/sqlite3/connection.h | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/include/sqlpp11/sqlite3/connection.h b/include/sqlpp11/sqlite3/connection.h index 1909782a..8a92d394 100644 --- a/include/sqlpp11/sqlite3/connection.h +++ b/include/sqlpp11/sqlite3/connection.h @@ -372,14 +372,28 @@ namespace sqlpp return static_cast(sqlite3_changes(native_handle())); } - template < - typename Execute, - typename Enable = typename std::enable_if::value, void>::type> - size_t execute(const Execute& x) - { - _context_t context{*this}; - serialize(x, context); - return execute(context.str()); + template < + typename Execute, + typename std::enable_if::value + and not sqlpp::is_prepared_statement_t::value, int>::type = 0> + size_t execute(const Execute& x) + { + static_assert(not sqlpp::is_select_t::value, "argument must not be a select statement - use operator() instead"); + + _context_t context{*this}; + serialize(x, context); + return execute(context.str()); + } + + template < + typename Execute, + typename std::enable_if::value, int>::type = 0> + size_t execute(const Execute& x) + { + static_assert(not sqlpp::is_select_t::value, "argument must not be a select statement - use operator() instead"); + + operator()(x); + return static_cast(sqlite3_changes(native_handle())); } template