diff --git a/dev/select_constraints.h b/dev/select_constraints.h index 983b7d406..c5a60be30 100644 --- a/dev/select_constraints.h +++ b/dev/select_constraints.h @@ -288,7 +288,9 @@ namespace sqlite_orm { with_t(bool recursiveIndicated, cte_type cte, expression_type expression) : recursiveIndicated{recursiveIndicated}, cte{std::move(cte)}, expression{std::move(expression)} { - this->expression.highest_level = true; + if constexpr(is_select_v) { + this->expression.highest_level = true; + } } }; #endif diff --git a/dev/storage.h b/dev/storage.h index 6a452bcc8..334bed279 100644 --- a/dev/storage.h +++ b/dev/storage.h @@ -1131,10 +1131,11 @@ namespace sqlite_orm { using storage_base::table_exists; // now that it is in storage_base make it into overload set #ifdef SQLITE_ORM_WITH_CTE - template - prepared_statement_t, CTEs...>> - prepare(with_t, CTEs...> sel) { - return prepare_impl, CTEs...>>(std::move(sel)); + template, is_insert_raw>, bool> = true> + prepared_statement_t> prepare(with_t sel) { + return prepare_impl>(std::move(sel)); } #endif @@ -1253,14 +1254,23 @@ namespace sqlite_orm { template void execute(const prepared_statement_t>& statement) { sqlite3_stmt* stmt = reset_stmt(statement.stmt); - iterate_ast(statement.expression.args, conditional_binder{statement.stmt}); + iterate_ast(statement.expression, conditional_binder{stmt}); + perform_step(stmt); + } + +#ifdef SQLITE_ORM_WITH_CTE + template = true> + void execute(const prepared_statement_t>& statement) { + sqlite3_stmt* stmt = reset_stmt(statement.stmt); + iterate_ast(statement.expression, conditional_binder{stmt}); perform_step(stmt); } +#endif template void execute(const prepared_statement_t>& statement) { sqlite3_stmt* stmt = reset_stmt(statement.stmt); - iterate_ast(statement.expression.args, conditional_binder{stmt}); + iterate_ast(statement.expression, conditional_binder{stmt}); perform_step(stmt); } diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index f8913de5a..fda8ea4c8 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -8102,7 +8102,9 @@ namespace sqlite_orm { with_t(bool recursiveIndicated, cte_type cte, expression_type expression) : recursiveIndicated{recursiveIndicated}, cte{std::move(cte)}, expression{std::move(expression)} { - this->expression.highest_level = true; + if constexpr(is_select_v) { + this->expression.highest_level = true; + } } }; #endif @@ -21615,10 +21617,11 @@ namespace sqlite_orm { using storage_base::table_exists; // now that it is in storage_base make it into overload set #ifdef SQLITE_ORM_WITH_CTE - template - prepared_statement_t, CTEs...>> - prepare(with_t, CTEs...> sel) { - return prepare_impl, CTEs...>>(std::move(sel)); + template, is_insert_raw>, bool> = true> + prepared_statement_t> prepare(with_t sel) { + return prepare_impl>(std::move(sel)); } #endif @@ -21737,14 +21740,23 @@ namespace sqlite_orm { template void execute(const prepared_statement_t>& statement) { sqlite3_stmt* stmt = reset_stmt(statement.stmt); - iterate_ast(statement.expression.args, conditional_binder{statement.stmt}); + iterate_ast(statement.expression, conditional_binder{stmt}); perform_step(stmt); } +#ifdef SQLITE_ORM_WITH_CTE + template = true> + void execute(const prepared_statement_t>& statement) { + sqlite3_stmt* stmt = reset_stmt(statement.stmt); + iterate_ast(statement.expression, conditional_binder{stmt}); + perform_step(stmt); + } +#endif + template void execute(const prepared_statement_t>& statement) { sqlite3_stmt* stmt = reset_stmt(statement.stmt); - iterate_ast(statement.expression.args, conditional_binder{stmt}); + iterate_ast(statement.expression, conditional_binder{stmt}); perform_step(stmt); }