From a89fdf8d21e27d2e5453209d5d6b1cb1a2260feb Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Thu, 23 Jan 2025 23:29:53 +0200 Subject: [PATCH 1/2] Upgraded to clang-format 19 DoozyX/clang-format-lint-action is still at version 18. This commit is trying to fetch from the forked repo d-griet/clang-format-lint-action. --- .github/workflows/clang-format-lint.yaml | 4 +- dev/alias.h | 12 +- dev/alias_traits.h | 2 +- dev/ast_iterator.h | 2 +- dev/column_pointer.h | 10 +- dev/column_result.h | 2 +- dev/conditions.h | 2 +- dev/cte_column_names_collector.h | 4 +- dev/cte_moniker.h | 4 +- dev/cte_storage.h | 6 +- dev/cte_types.h | 4 +- dev/functional/config.h | 6 +- dev/functional/cstring_literal.h | 58 +- dev/functional/cxx_compiler_quirks.h | 4 +- dev/functional/cxx_functional_polyfill.h | 2 +- dev/functional/cxx_tuple_polyfill.h | 66 +- dev/functional/function_traits.h | 135 ++- dev/functional/index_sequence_util.h | 108 +-- dev/functional/mpl.h | 3 +- dev/functional/mpl/conditional.h | 54 +- dev/node_tuple.h | 2 +- dev/schema/table.h | 4 +- dev/select_constraints.h | 4 +- dev/statement_serializer.h | 2 +- dev/storage.h | 16 +- dev/storage_impl.h | 6 +- dev/table_info.h | 10 +- dev/transaction_guard.h | 4 +- dev/tuple_helper/tuple_filter.h | 9 +- dev/tuple_helper/tuple_traits.h | 9 +- dev/type_traits.h | 2 +- dev/udf_proxy.h | 436 +++++----- examples/common_table_expressions.cpp | 2 +- examples/core_functions.cpp | 3 +- examples/except_intersection.cpp | 3 +- include/sqlite_orm/sqlite_orm.h | 146 ++-- tests/ast_iterator_tests.cpp | 2 +- .../core_functions_tests.cpp | 3 +- .../math_functions.cpp | 806 ++++++++++-------- tests/catch_matchers.h | 46 +- tests/constraints/foreign_key.cpp | 4 +- tests/iterate.cpp | 2 +- .../prepared_common.h | 4 +- .../aggregate_functions.cpp | 2 +- .../alias_extractor.cpp | 2 +- .../column_names.cpp | 2 +- .../statement_serializer_tests/conditions.cpp | 90 +- .../select_constraints.cpp | 2 +- .../statements/insert_replace.cpp | 4 +- .../statements/remove_all.cpp | 2 +- .../statements/update_all.cpp | 2 +- tests/static_tests/alias.cpp | 2 +- tests/static_tests/column_expression_type.cpp | 2 +- tests/static_tests/column_pointer.cpp | 374 ++++---- tests/static_tests/column_result_t.cpp | 2 +- tests/static_tests/cte.cpp | 2 +- tests/static_tests/iterator_t.cpp | 14 +- tests/static_tests/node_tuple.cpp | 4 +- tests/static_tests/operators_adl.cpp | 6 +- .../static_tests_storage_traits.h | 192 ++--- tests/storage_tests.cpp | 2 +- tests/table_name_collector.cpp | 2 +- tests/tests5.cpp | 2 +- 63 files changed, 1381 insertions(+), 1342 deletions(-) diff --git a/.github/workflows/clang-format-lint.yaml b/.github/workflows/clang-format-lint.yaml index 49fdc4db4..65f060047 100644 --- a/.github/workflows/clang-format-lint.yaml +++ b/.github/workflows/clang-format-lint.yaml @@ -9,6 +9,6 @@ jobs: steps: - uses: actions/checkout@v1 - name: clang-format lint - uses: DoozyX/clang-format-lint-action@v0.16.2 + uses: d-griet/clang-format-lint-action@99a106be2f3f1a92d9783ea7c744fde62d8ce1fa with: - clangFormatVersion: 16 + clangFormatVersion: 19 diff --git a/dev/alias.h b/dev/alias.h index fd1541ee9..01b852701 100644 --- a/dev/alias.h +++ b/dev/alias.h @@ -4,7 +4,7 @@ #include // std::make_index_sequence, std::move #include // std::string #include // std::stringstream -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #endif @@ -101,7 +101,7 @@ namespace sqlite_orm { return alias_extractor::extract(); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // for CTE monikers -> empty template, A> = true> static std::string as_alias() { @@ -168,7 +168,7 @@ namespace sqlite_orm { }; #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template SQLITE_ORM_CONSTEVAL auto n_to_colalias() { constexpr column_alias<'1' + n % 10, C...> colalias{}; @@ -223,7 +223,7 @@ namespace sqlite_orm { polyfill::conjunction, polyfill::negation>>>::value, bool> = true> - constexpr auto alias_column(F O::*field) { + constexpr auto alias_column(F O::* field) { using namespace ::sqlite_orm::internal; using aliased_type = type_t; static_assert(is_field_of_v, "Column must be from aliased table"); @@ -281,7 +281,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Create a column reference to an aliased CTE column. */ @@ -474,7 +474,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) inline namespace literals { /** * column_alias<'1'[, ...]> from a numeric literal. diff --git a/dev/alias_traits.h b/dev/alias_traits.h index 4aaeee5f4..abdb2d389 100644 --- a/dev/alias_traits.h +++ b/dev/alias_traits.h @@ -55,7 +55,7 @@ namespace sqlite_orm { */ template SQLITE_ORM_INLINE_VAR constexpr bool is_cte_moniker_v = -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) polyfill::conjunction_v, std::is_same, std::remove_const_t>>; #else diff --git a/dev/ast_iterator.h b/dev/ast_iterator.h index 7e166566e..7d55996ad 100644 --- a/dev/ast_iterator.h +++ b/dev/ast_iterator.h @@ -226,7 +226,7 @@ namespace sqlite_orm { } }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct ast_iterator> { using node_type = CTE; diff --git a/dev/column_pointer.h b/dev/column_pointer.h index c2b6b75bd..e33efb1ea 100644 --- a/dev/column_pointer.h +++ b/dev/column_pointer.h @@ -35,7 +35,7 @@ namespace sqlite_orm { SQLITE_ORM_INLINE_VAR constexpr bool is_operator_argument_v::value>> = true; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct alias_holder; #endif @@ -51,7 +51,7 @@ namespace sqlite_orm { * storage.select(column(&BaseType::id)); */ template = true> - constexpr internal::column_pointer column(F Base::*field) { + constexpr internal::column_pointer column(F Base::* field) { static_assert(std::is_convertible::value, "Field must be from derived class"); return {field}; } @@ -61,7 +61,7 @@ namespace sqlite_orm { * Explicitly refer to a column. */ template - constexpr auto column(F O::*field) { + constexpr auto column(F O::* field) { return column>(field); } @@ -72,7 +72,7 @@ namespace sqlite_orm { * Explicitly refer to a column. */ template - constexpr auto operator->*(const R& /*table*/, F O::*field) { + constexpr auto operator->*(const R& /*table*/, F O::* field) { return column(field); } } @@ -96,7 +96,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Explicitly refer to a column alias mapped into a CTE or subquery. * diff --git a/dev/column_result.h b/dev/column_result.h index 725546b34..9244d0a28 100644 --- a/dev/column_result.h +++ b/dev/column_result.h @@ -240,7 +240,7 @@ namespace sqlite_orm { template struct column_result_t, void> : column_result_t {}; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct column_result_t>, void> { using table_type = storage_pick_table_t; diff --git a/dev/conditions.h b/dev/conditions.h index 56cf4c918..880336a56 100644 --- a/dev/conditions.h +++ b/dev/conditions.h @@ -963,7 +963,7 @@ namespace sqlite_orm { } template - internal::using_t using_(F O::*field) { + internal::using_t using_(F O::* field) { return {field}; } template diff --git a/dev/cte_column_names_collector.h b/dev/cte_column_names_collector.h index 69bb9b5e0..a8904275c 100644 --- a/dev/cte_column_names_collector.h +++ b/dev/cte_column_names_collector.h @@ -1,6 +1,6 @@ #pragma once -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #include // std::reference_wrapper @@ -15,7 +15,7 @@ #include "select_constraints.h" #include "serializer_context.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { // collecting column names utilizes the statement serializer diff --git a/dev/cte_moniker.h b/dev/cte_moniker.h index f23584621..03e7dcc8e 100644 --- a/dev/cte_moniker.h +++ b/dev/cte_moniker.h @@ -1,6 +1,6 @@ #pragma once -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES #include #include // std::make_index_sequence @@ -13,7 +13,7 @@ #include "functional/cstring_literal.h" #include "alias.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { diff --git a/dev/cte_storage.h b/dev/cte_storage.h index 023e6ebe8..5fb5d0115 100644 --- a/dev/cte_storage.h +++ b/dev/cte_storage.h @@ -1,6 +1,6 @@ #pragma once -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #include @@ -21,7 +21,7 @@ namespace sqlite_orm { namespace internal { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // F = field_type template field/getter template - auto extract_colref_expressions(const DBOs& /*dbObjects*/, F O::*col, std::index_sequence = {}) { + auto extract_colref_expressions(const DBOs& /*dbObjects*/, F O::* col, std::index_sequence = {}) { return std::make_tuple(col); } diff --git a/dev/cte_types.h b/dev/cte_types.h index 7594da147..c7d5cbfc7 100644 --- a/dev/cte_types.h +++ b/dev/cte_types.h @@ -1,6 +1,6 @@ #pragma once -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #endif @@ -9,7 +9,7 @@ #include "functional/cxx_type_traits_polyfill.h" #include "tuple_helper/tuple_fy.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { diff --git a/dev/functional/config.h b/dev/functional/config.h index aa2ee2cba..4b98290eb 100644 --- a/dev/functional/config.h +++ b/dev/functional/config.h @@ -65,13 +65,13 @@ // The check here doesn't care and checks the library versions in use. // // Another way of detection might be the feature-test macro __cpp_lib_concepts -#if(__cplusplus >= 202002L) && \ +#if (__cplusplus >= 202002L) && \ ((!_LIBCPP_VERSION || _LIBCPP_VERSION >= 13000) && (!_GLIBCXX_RELEASE || _GLIBCXX_RELEASE >= 10)) #define SQLITE_ORM_STL_HAS_DEFAULT_SENTINEL #endif -#if(defined(SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED) && defined(SQLITE_ORM_INLINE_VARIABLES_SUPPORTED) && \ - defined(SQLITE_ORM_CONSTEVAL_SUPPORTED)) && \ +#if (defined(SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED) && defined(SQLITE_ORM_INLINE_VARIABLES_SUPPORTED) && \ + defined(SQLITE_ORM_CONSTEVAL_SUPPORTED)) && \ (defined(SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED)) #define SQLITE_ORM_WITH_CPP20_ALIASES #endif diff --git a/dev/functional/cstring_literal.h b/dev/functional/cstring_literal.h index f78eefe91..3521ca5cb 100644 --- a/dev/functional/cstring_literal.h +++ b/dev/functional/cstring_literal.h @@ -1,32 +1,32 @@ -#pragma once - -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES -#include // std::index_sequence -#include // std::copy_n -#endif - -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES -namespace sqlite_orm::internal { +#pragma once + +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +#include // std::index_sequence +#include // std::copy_n +#endif + +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +namespace sqlite_orm::internal { /* * Wraps a C string of fixed size. * Its main purpose is to enable the user-defined string literal operator template. - */ - template - struct cstring_literal { - static constexpr size_t size() { - return N - 1; - } - - constexpr cstring_literal(const char (&cstr)[N]) { - std::copy_n(cstr, N, this->cstr); - } - - char cstr[N]; - }; - - template class Template, cstring_literal literal, size_t... Idx> - consteval auto explode_into(std::index_sequence) { - return Template{}; - } -} -#endif + */ + template + struct cstring_literal { + static constexpr size_t size() { + return N - 1; + } + + constexpr cstring_literal(const char (&cstr)[N]) { + std::copy_n(cstr, N, this->cstr); + } + + char cstr[N]; + }; + + template class Template, cstring_literal literal, size_t... Idx> + consteval auto explode_into(std::index_sequence) { + return Template{}; + } +} +#endif diff --git a/dev/functional/cxx_compiler_quirks.h b/dev/functional/cxx_compiler_quirks.h index d2a0b2d85..e666ad36d 100644 --- a/dev/functional/cxx_compiler_quirks.h +++ b/dev/functional/cxx_compiler_quirks.h @@ -46,12 +46,12 @@ // In these cases we have to use helper structures to break down the type alias. // Note that the detection of specific compilers is so complicated because some compilers emulate other compilers, // so we simply exclude all compilers that do not support C++20, even though this test is actually inaccurate. -#if(defined(_MSC_VER) && (_MSC_VER < 1920)) || (!defined(_MSC_VER) && (__cplusplus < 202002L)) +#if (defined(_MSC_VER) && (_MSC_VER < 1920)) || (!defined(_MSC_VER) && (__cplusplus < 202002L)) #define SQLITE_ORM_BROKEN_ALIAS_TEMPLATE_DEPENDENT_EXPR_SFINAE #endif // overwrite SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED -#if(__cpp_nontype_template_args < 201911L) && \ +#if (__cpp_nontype_template_args < 201911L) && \ (defined(__clang__) && (__clang_major__ >= 12) && (__cplusplus >= 202002L)) #define SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED #endif diff --git a/dev/functional/cxx_functional_polyfill.h b/dev/functional/cxx_functional_polyfill.h index 474ab2f38..3b9fdc8fa 100644 --- a/dev/functional/cxx_functional_polyfill.h +++ b/dev/functional/cxx_functional_polyfill.h @@ -19,7 +19,7 @@ namespace sqlite_orm { // The check here doesn't care and checks the library versions in use. // // Another way of detection would be the constrained algorithms feature-test macro __cpp_lib_ranges -#if(__cplusplus >= 202002L) && \ +#if (__cplusplus >= 202002L) && \ ((!_LIBCPP_VERSION || _LIBCPP_VERSION >= 13000) && (!_GLIBCXX_RELEASE || _GLIBCXX_RELEASE >= 10)) using std::identity; #else diff --git a/dev/functional/cxx_tuple_polyfill.h b/dev/functional/cxx_tuple_polyfill.h index d8fee12c3..b795e8656 100644 --- a/dev/functional/cxx_tuple_polyfill.h +++ b/dev/functional/cxx_tuple_polyfill.h @@ -1,33 +1,33 @@ -#pragma once - -#include // std::apply; std::tuple_size -#if __cpp_lib_apply < 201603L -#include // std::forward, std::index_sequence, std::make_index_sequence -#endif - -#include "../functional/cxx_functional_polyfill.h" // std::invoke - -namespace sqlite_orm { - namespace internal { - namespace polyfill { -#if __cpp_lib_apply >= 201603L - using std::apply; -#else - template - decltype(auto) apply(Callable&& callable, Tpl&& tpl, std::index_sequence) { - return polyfill::invoke(std::forward(callable), std::get(std::forward(tpl))...); - } - - template - decltype(auto) apply(Callable&& callable, Tpl&& tpl) { - constexpr size_t size = std::tuple_size>::value; - return apply(std::forward(callable), - std::forward(tpl), - std::make_index_sequence{}); - } -#endif - } - } - - namespace polyfill = internal::polyfill; -} +#pragma once + +#include // std::apply; std::tuple_size +#if __cpp_lib_apply < 201603L +#include // std::forward, std::index_sequence, std::make_index_sequence +#endif + +#include "../functional/cxx_functional_polyfill.h" // std::invoke + +namespace sqlite_orm { + namespace internal { + namespace polyfill { +#if __cpp_lib_apply >= 201603L + using std::apply; +#else + template + decltype(auto) apply(Callable&& callable, Tpl&& tpl, std::index_sequence) { + return polyfill::invoke(std::forward(callable), std::get(std::forward(tpl))...); + } + + template + decltype(auto) apply(Callable&& callable, Tpl&& tpl) { + constexpr size_t size = std::tuple_size>::value; + return apply(std::forward(callable), + std::forward(tpl), + std::make_index_sequence{}); + } +#endif + } + } + + namespace polyfill = internal::polyfill; +} diff --git a/dev/functional/function_traits.h b/dev/functional/function_traits.h index a5f6a642b..c814eaf25 100644 --- a/dev/functional/function_traits.h +++ b/dev/functional/function_traits.h @@ -1,85 +1,84 @@ -#pragma once - -#include "cxx_type_traits_polyfill.h" -#include "mpl.h" - -namespace sqlite_orm { - namespace internal { +#pragma once + +#include "cxx_type_traits_polyfill.h" +#include "mpl.h" + +namespace sqlite_orm { + namespace internal { /* * Define nested typenames: * - return_type * - arguments_tuple * - signature_type - */ - template - struct function_traits; - + */ + template + struct function_traits; + /* * A function's return type - */ - template - using function_return_type_t = typename function_traits::return_type; - + */ + template + using function_return_type_t = typename function_traits::return_type; + /* * A function's arguments tuple - */ - template - class Tuple, - template class ProjectOp = polyfill::type_identity_t> - using function_arguments = typename function_traits::template arguments_tuple; - + */ + template class Tuple, + template class ProjectOp = polyfill::type_identity_t> + using function_arguments = typename function_traits::template arguments_tuple; + /* * A function's signature - */ - template - using function_signature_type_t = typename function_traits::signature_type; - - template - struct function_traits { - using return_type = R; - - template class Tuple, template class ProjectOp> - using arguments_tuple = Tuple...>; - - using signature_type = R(Args...); - }; - - // non-exhaustive partial specializations of `function_traits` - - template - struct function_traits : function_traits { - using signature_type = R(Args...) const; - }; - -#ifdef SQLITE_ORM_NOTHROW_ALIASES_SUPPORTED - template - struct function_traits : function_traits { - using signature_type = R(Args...) noexcept; - }; - - template - struct function_traits : function_traits { - using signature_type = R(Args...) const noexcept; - }; -#endif - + */ + template + using function_signature_type_t = typename function_traits::signature_type; + + template + struct function_traits { + using return_type = R; + + template class Tuple, template class ProjectOp> + using arguments_tuple = Tuple...>; + + using signature_type = R(Args...); + }; + + // non-exhaustive partial specializations of `function_traits` + + template + struct function_traits : function_traits { + using signature_type = R(Args...) const; + }; + +#ifdef SQLITE_ORM_NOTHROW_ALIASES_SUPPORTED + template + struct function_traits : function_traits { + using signature_type = R(Args...) noexcept; + }; + + template + struct function_traits : function_traits { + using signature_type = R(Args...) const noexcept; + }; +#endif + /* * Pick signature of function pointer - */ - template - struct function_traits : function_traits {}; - + */ + template + struct function_traits : function_traits {}; + /* * Pick signature of function reference - */ - template - struct function_traits : function_traits {}; - + */ + template + struct function_traits : function_traits {}; + /* * Pick signature of pointer-to-member function - */ - template - struct function_traits : function_traits {}; - } -} + */ + template + struct function_traits : function_traits {}; + } +} diff --git a/dev/functional/index_sequence_util.h b/dev/functional/index_sequence_util.h index beda370d0..3abb4a2e2 100644 --- a/dev/functional/index_sequence_util.h +++ b/dev/functional/index_sequence_util.h @@ -1,61 +1,61 @@ -#pragma once - -#include // std::index_sequence - -namespace sqlite_orm { - namespace internal { -#if defined(SQLITE_ORM_PACK_INDEXING_SUPPORTED) +#pragma once + +#include // std::index_sequence + +namespace sqlite_orm { + namespace internal { +#if defined(SQLITE_ORM_PACK_INDEXING_SUPPORTED) /** * Get the index value of an `index_sequence` at a specific position. - */ - template - SQLITE_ORM_CONSTEVAL auto index_sequence_value_at(std::index_sequence) { - return Idx...[Pos]; - } -#elif defined(SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED) + */ + template + SQLITE_ORM_CONSTEVAL auto index_sequence_value_at(std::index_sequence) { + return Idx...[Pos]; + } +#elif defined(SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED) /** * Get the index value of an `index_sequence` at a specific position. - */ - template - SQLITE_ORM_CONSTEVAL size_t index_sequence_value_at(std::index_sequence) { - static_assert(Pos < sizeof...(Idx)); -#ifdef SQLITE_ORM_CONSTEVAL_SUPPORTED - size_t result; -#else - size_t result = 0; -#endif - size_t i = 0; - // note: `(void)` cast silences warning 'expression result unused' - (void)((result = Idx, i++ == Pos) || ...); - return result; - } -#else + */ + template + SQLITE_ORM_CONSTEVAL size_t index_sequence_value_at(std::index_sequence) { + static_assert(Pos < sizeof...(Idx)); +#ifdef SQLITE_ORM_CONSTEVAL_SUPPORTED + size_t result; +#else + size_t result = 0; +#endif + size_t i = 0; + // note: `(void)` cast silences warning 'expression result unused' + (void)((result = Idx, i++ == Pos) || ...); + return result; + } +#else /** * Get the index value of an `index_sequence` at a specific position. * `Pos` must always be `0`. - */ - template - SQLITE_ORM_CONSTEVAL size_t index_sequence_value_at(std::index_sequence) { - static_assert(Pos == 0, ""); - return I; - } -#endif - - template - struct flatten_idxseq { - using type = std::index_sequence<>; - }; - - template - struct flatten_idxseq> { - using type = std::index_sequence; - }; - - template - struct flatten_idxseq, std::index_sequence, Seq...> - : flatten_idxseq, Seq...> {}; - - template - using flatten_idxseq_t = typename flatten_idxseq::type; - } -} + */ + template + SQLITE_ORM_CONSTEVAL size_t index_sequence_value_at(std::index_sequence) { + static_assert(Pos == 0, ""); + return I; + } +#endif + + template + struct flatten_idxseq { + using type = std::index_sequence<>; + }; + + template + struct flatten_idxseq> { + using type = std::index_sequence; + }; + + template + struct flatten_idxseq, std::index_sequence, Seq...> + : flatten_idxseq, Seq...> {}; + + template + using flatten_idxseq_t = typename flatten_idxseq::type; + } +} diff --git a/dev/functional/mpl.h b/dev/functional/mpl.h index 61dd6edb2..6da008aa0 100644 --- a/dev/functional/mpl.h +++ b/dev/functional/mpl.h @@ -329,8 +329,7 @@ namespace sqlite_orm { * Bind a metafunction and arguments at the front of a higher-order metafunction. */ template class Fn, class... Args2> class HigherFn, - template - class BoundFn, + template class BoundFn, class... Bound> using bind_front_higherorder_fn = bind_front::quote_fn, quote_fn, Bound...>; diff --git a/dev/functional/mpl/conditional.h b/dev/functional/mpl/conditional.h index 8018b9b91..af21ba4e5 100644 --- a/dev/functional/mpl/conditional.h +++ b/dev/functional/mpl/conditional.h @@ -1,9 +1,9 @@ -#pragma once - -namespace sqlite_orm { - namespace internal { - namespace mpl { - +#pragma once + +namespace sqlite_orm { + namespace internal { + namespace mpl { + /* * Binary quoted metafunction equivalent to `std::conditional`, * using an improved implementation in respect to memoization. @@ -11,24 +11,24 @@ namespace sqlite_orm { * Because `conditional` is only typed on a single bool non-type template parameter, * the compiler only ever needs to memoize 2 instances of this class template. * The type selection is a nested cheap alias template. - */ - template - struct conditional { - template - using fn = A; - }; - - template<> - struct conditional { - template - using fn = B; - }; - - // directly invoke `conditional` - template - using conditional_t = typename conditional::template fn; - } - } - - namespace mpl = internal::mpl; -} + */ + template + struct conditional { + template + using fn = A; + }; + + template<> + struct conditional { + template + using fn = B; + }; + + // directly invoke `conditional` + template + using conditional_t = typename conditional::template fn; + } + } + + namespace mpl = internal::mpl; +} diff --git a/dev/node_tuple.h b/dev/node_tuple.h index e551b04b3..f86ccd330 100644 --- a/dev/node_tuple.h +++ b/dev/node_tuple.h @@ -127,7 +127,7 @@ namespace sqlite_orm { template struct node_tuple> : node_tuple {}; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct node_tuple> : node_tuple {}; diff --git a/dev/schema/table.h b/dev/schema/table.h index aa569c0cf..f344417fb 100644 --- a/dev/schema/table.h +++ b/dev/schema/table.h @@ -41,7 +41,7 @@ namespace sqlite_orm { check_if_is_template>, T>; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * A subselect mapper's CTE moniker, void otherwise. */ @@ -69,7 +69,7 @@ namespace sqlite_orm { */ template struct table_t : basic_table { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // this typename is used in contexts where it is known that the 'table' holds a subselect_mapper // instead of a regular object type using cte_mapper_type = O; diff --git a/dev/select_constraints.h b/dev/select_constraints.h index e159bef54..8c2d1c142 100644 --- a/dev/select_constraints.h +++ b/dev/select_constraints.h @@ -217,7 +217,7 @@ namespace sqlite_orm { using super::super; }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /* * Turn explicit columns for a CTE into types that the CTE backend understands */ @@ -530,7 +530,7 @@ namespace sqlite_orm { return {{std::forward(expressions)...}}; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #if SQLITE_VERSION_NUMBER >= 3035003 #ifdef SQLITE_ORM_WITH_CPP20_ALIASES /* diff --git a/dev/statement_serializer.h b/dev/statement_serializer.h index 8c98ed5d5..1946f76d8 100644 --- a/dev/statement_serializer.h +++ b/dev/statement_serializer.h @@ -588,7 +588,7 @@ namespace sqlite_orm { } }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #if SQLITE_VERSION_NUMBER >= 3035003 #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template<> diff --git a/dev/storage.h b/dev/storage.h index 4fb15492c..63485101b 100644 --- a/dev/storage.h +++ b/dev/storage.h @@ -269,7 +269,7 @@ namespace sqlite_orm { return {this->db_objects, std::move(con), std::move(expression)}; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED requires(is_select_v) @@ -344,7 +344,7 @@ namespace sqlite_orm { protected: template - std::string group_concat_internal(F O::*m, std::unique_ptr y, Args&&... args) { + std::string group_concat_internal(F O::* m, std::unique_ptr y, Args&&... args) { this->assert_mapped_type(); std::vector rows; if(y) { @@ -731,7 +731,7 @@ namespace sqlite_orm { return this->execute(statement); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Using a CTE, select a single column into std::vector or multiple columns into std::vector>. */ @@ -996,12 +996,12 @@ namespace sqlite_orm { template [[deprecated("Use the more accurately named function `find_column_name()`")]] const std::string* - column_name(F O::*memberPointer) const { + column_name(F O::* memberPointer) const { return internal::find_column_name(this->db_objects, memberPointer); } template - const std::string* find_column_name(F O::*memberPointer) const { + const std::string* find_column_name(F O::* memberPointer) const { return internal::find_column_name(this->db_objects, memberPointer); } @@ -1249,7 +1249,7 @@ namespace sqlite_orm { using storage_base::table_exists; // now that it is in storage_base make it into overload set -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template, @@ -1383,7 +1383,7 @@ namespace sqlite_orm { perform_step(stmt); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template< class... CTEs, class E, @@ -1618,7 +1618,7 @@ namespace sqlite_orm { perform_step(stmt); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template auto execute(const prepared_statement_t, CTEs...>>& statement) { using ExprDBOs = decltype(db_objects_for_expression(this->db_objects, statement.expression)); diff --git a/dev/storage_impl.h b/dev/storage_impl.h index 74e75b727..bc40b6389 100644 --- a/dev/storage_impl.h +++ b/dev/storage_impl.h @@ -43,7 +43,7 @@ namespace sqlite_orm { * Find column name by its type and member pointer. */ template = true> - const std::string* find_column_name(const DBOs& dbObjects, F O::*field) { + const std::string* find_column_name(const DBOs& dbObjects, F O::* field) { return pick_table(dbObjects).find_column_name(field); } @@ -57,7 +57,7 @@ namespace sqlite_orm { return cp.field; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Materialize column pointer: * 3. by moniker and alias_holder<>. @@ -93,7 +93,7 @@ namespace sqlite_orm { return pick_table(dbObjects).find_column_name(field); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Find column name by: * 3. by moniker and alias_holder<>. diff --git a/dev/table_info.h b/dev/table_info.h index 975b203eb..ac0118412 100644 --- a/dev/table_info.h +++ b/dev/table_info.h @@ -19,9 +19,8 @@ namespace sqlite_orm { decltype(notnull) notnull_, decltype(dflt_value) dflt_value_, decltype(pk) pk_) : - cid(cid_), - name(std::move(name_)), type(std::move(type_)), notnull(notnull_), dflt_value(std::move(dflt_value_)), - pk(pk_) {} + cid(cid_), name(std::move(name_)), type(std::move(type_)), notnull(notnull_), + dflt_value(std::move(dflt_value_)), pk(pk_) {} #endif }; @@ -42,9 +41,8 @@ namespace sqlite_orm { decltype(dflt_value) dflt_value_, decltype(pk) pk_, decltype(hidden) hidden_) : - cid(cid_), - name(std::move(name_)), type(std::move(type_)), notnull(notnull_), dflt_value(std::move(dflt_value_)), - pk(pk_), hidden{hidden_} {} + cid(cid_), name(std::move(name_)), type(std::move(type_)), notnull(notnull_), + dflt_value(std::move(dflt_value_)), pk(pk_), hidden{hidden_} {} #endif }; } diff --git a/dev/transaction_guard.h b/dev/transaction_guard.h index 3ad6d7785..d83fad5c6 100644 --- a/dev/transaction_guard.h +++ b/dev/transaction_guard.h @@ -28,8 +28,8 @@ namespace sqlite_orm { transaction_guard_t(connection_ref connection_, std::function commit_func_, std::function rollback_func_) : - connection(std::move(connection_)), - commit_func(std::move(commit_func_)), rollback_func(std::move(rollback_func_)) {} + connection(std::move(connection_)), commit_func(std::move(commit_func_)), + rollback_func(std::move(rollback_func_)) {} transaction_guard_t(transaction_guard_t&& other) : commit_on_destroy(other.commit_on_destroy), connection(std::move(other.connection)), diff --git a/dev/tuple_helper/tuple_filter.h b/dev/tuple_helper/tuple_filter.h index ce501760b..d28485ebb 100644 --- a/dev/tuple_helper/tuple_filter.h +++ b/dev/tuple_helper/tuple_filter.h @@ -60,8 +60,7 @@ namespace sqlite_orm { * `FilterProj` is a metafunction */ template - class Pred, + template class Pred, template class FilterProj = polyfill::type_identity_t, class Seq = std::make_index_sequence::value>> using filter_tuple_sequence_t = typename filter_tuple_sequence::type; @@ -71,8 +70,7 @@ namespace sqlite_orm { * `FilterProj` is a metafunction */ template - class Pred, + template class Pred, template class FilterProj = polyfill::type_identity_t, class Seq = std::make_index_sequence::value>> using filter_tuple_t = tuple_from_index_sequence_t>; @@ -87,8 +85,7 @@ namespace sqlite_orm { * with a default Sequence in function template parameters [SQLITE_ORM_BROKEN_VARIADIC_PACK_EXPANSION]. */ template - class Pred, + template class Pred, class Seq, template class FilterProj = polyfill::type_identity_t> struct count_filtered_tuple diff --git a/dev/tuple_helper/tuple_traits.h b/dev/tuple_helper/tuple_traits.h index fbde4d0f7..c53fb6f03 100644 --- a/dev/tuple_helper/tuple_traits.h +++ b/dev/tuple_helper/tuple_traits.h @@ -12,8 +12,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class TraitFn, + template class TraitFn, template class ProjOp = polyfill::type_identity_t> using tuple_has = mpl::invoke_t, Pack, mpl::quote_fn>; @@ -31,8 +30,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class Template, + template class Template, template class ProjOp = polyfill::type_identity_t> using tuple_has_template = mpl::invoke_t, Pack, mpl::quote_fn>; @@ -48,8 +46,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class Template, + template class Template, template class ProjOp = polyfill::type_identity_t> using find_tuple_template = mpl::invoke_t, Pack, mpl::quote_fn>; diff --git a/dev/type_traits.h b/dev/type_traits.h index e55c22d8e..b4baa5d6a 100644 --- a/dev/type_traits.h +++ b/dev/type_traits.h @@ -116,7 +116,7 @@ namespace sqlite_orm { using auto_udf_type_t = typename decltype(a)::udf_type; #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template using cte_moniker_type_t = typename T::cte_moniker_type; diff --git a/dev/udf_proxy.h b/dev/udf_proxy.h index cf152de95..31cfd140c 100644 --- a/dev/udf_proxy.h +++ b/dev/udf_proxy.h @@ -1,231 +1,231 @@ -#pragma once - -#include -#include // assert macro -#include // std::true_type, std::false_type -#include // std::bad_alloc -#include // std::allocator, std::allocator_traits, std::unique_ptr -#include // std::string -#include // std::function -#include // std::move, std::pair - -#include "error_code.h" - -namespace sqlite_orm { - namespace internal { +#pragma once + +#include +#include // assert macro +#include // std::true_type, std::false_type +#include // std::bad_alloc +#include // std::allocator, std::allocator_traits, std::unique_ptr +#include // std::string +#include // std::function +#include // std::move, std::pair + +#include "error_code.h" + +namespace sqlite_orm { + namespace internal { /* * Returns properly allocated memory space for the specified application-defined function object * paired with an accompanying deallocation function. - */ - template - std::pair preallocate_udf_memory() { - std::allocator allocator; - using traits = std::allocator_traits; - - SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { - std::allocator allocator; - using traits = std::allocator_traits; - traits::deallocate(allocator, (UDF*)location, 1); - }; - - return {traits::allocate(allocator, 1), deallocate}; - } - + */ + template + std::pair preallocate_udf_memory() { + std::allocator allocator; + using traits = std::allocator_traits; + + SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { + std::allocator allocator; + using traits = std::allocator_traits; + traits::deallocate(allocator, (UDF*)location, 1); + }; + + return {traits::allocate(allocator, 1), deallocate}; + } + /* * Returns a pair of functions to allocate/deallocate properly aligned memory space for the specified application-defined function object. - */ - template - std::pair obtain_udf_allocator() { - SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto allocate = []() { - std::allocator allocator; - using traits = std::allocator_traits; - return (void*)traits::allocate(allocator, 1); - }; - - SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { - std::allocator allocator; - using traits = std::allocator_traits; - traits::deallocate(allocator, (UDF*)location, 1); - }; - - return {allocate, deallocate}; - } - + */ + template + std::pair obtain_udf_allocator() { + SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto allocate = []() { + std::allocator allocator; + using traits = std::allocator_traits; + return (void*)traits::allocate(allocator, 1); + }; + + SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { + std::allocator allocator; + using traits = std::allocator_traits; + traits::deallocate(allocator, (UDF*)location, 1); + }; + + return {allocate, deallocate}; + } + /* * A deleter that only destroys the application-defined function object. - */ - struct udf_destruct_only_deleter { - template - void operator()(UDF* f) const noexcept { - std::allocator allocator; - using traits = std::allocator_traits; - traits::destroy(allocator, f); - } - }; - + */ + struct udf_destruct_only_deleter { + template + void operator()(UDF* f) const noexcept { + std::allocator allocator; + using traits = std::allocator_traits; + traits::destroy(allocator, f); + } + }; + /* * Stores type-erased information in relation to an application-defined scalar or aggregate function object: * - name and argument count * - function dispatch (step, final) * - either preallocated memory with a possibly a priori constructed function object [scalar], * - or memory allocation/deallocation functions [aggregate] - */ - struct udf_proxy { - using sqlite_func_t = void (*)(sqlite3_context* context, int argsCount, sqlite3_value** values); - using final_call_fn_t = void (*)(void* udfHandle, sqlite3_context* context); - using memory_alloc = std::pair; - using memory_space = std::pair; - - std::string name; - int argumentsCount; - std::function constructAt; - xdestroy_fn_t destroy; - sqlite_func_t func; - final_call_fn_t finalAggregateCall; - - // allocator/deallocator function pair for aggregate UDF - const memory_alloc udfAllocator; - // pointer to preallocated memory space for scalar UDF, already constructed by caller if stateless - const memory_space udfMemorySpace; - - udf_proxy(std::string name, - int argumentsCount, - std::function constructAt, - xdestroy_fn_t destroy, - sqlite_func_t func, - memory_space udfMemorySpace) : - name{std::move(name)}, - argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, destroy{destroy}, func{func}, - finalAggregateCall{nullptr}, udfAllocator{}, udfMemorySpace{udfMemorySpace} {} - - udf_proxy(std::string name, - int argumentsCount, - std::function constructAt, - xdestroy_fn_t destroy, - sqlite_func_t func, - final_call_fn_t finalAggregateCall, - memory_alloc udfAllocator) : - name{std::move(name)}, - argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, destroy{destroy}, func{func}, - finalAggregateCall{finalAggregateCall}, udfAllocator{udfAllocator}, udfMemorySpace{} {} - - ~udf_proxy() { - // destruct - if(/*bool aprioriConstructed = */ !constructAt && destroy) { - destroy(udfMemorySpace.first); - } - // deallocate - if(udfMemorySpace.second) { - udfMemorySpace.second(udfMemorySpace.first); - } - } - - udf_proxy(const udf_proxy&) = delete; - udf_proxy& operator=(const udf_proxy&) = delete; - - // convenience accessors for better legibility; - // [`friend` is intentional - it ensures that these are core accessors (only found via ADL), yet still be an out-of-class interface] - - friend void* preallocated_udf_handle(udf_proxy* proxy) { - return proxy->udfMemorySpace.first; - } - - friend void* allocate_udf(udf_proxy* proxy) { - return proxy->udfAllocator.first(); - } - - friend void deallocate_udf(udf_proxy* proxy, void* udfHandle) { - proxy->udfAllocator.second(udfHandle); - } - }; - - // safety net of doing a triple check at runtime - inline void assert_args_count(const udf_proxy* proxy, int argsCount) { - assert((proxy->argumentsCount == -1) || (proxy->argumentsCount == argsCount || - /*check fin call*/ argsCount == -1)); - (void)proxy; - (void)argsCount; - } - - // safety net of doing a triple check at runtime - inline void proxy_assert_args_count(sqlite3_context* context, int argsCount) { - udf_proxy* proxy; - assert((proxy = static_cast(sqlite3_user_data(context))) != nullptr); - assert_args_count(proxy, argsCount); - (void)context; - } - - // note: may throw `std::bad_alloc` in case memory space for the aggregate function object cannot be allocated - inline void* ensure_aggregate_udf(sqlite3_context* context, udf_proxy* proxy, int argsCount) { - // reserve memory for storing a void pointer (which is the `udfHandle`, i.e. address of the aggregate function object) - void* ctxMemory = sqlite3_aggregate_context(context, sizeof(void*)); - if(!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { - throw std::bad_alloc(); - } - void*& udfHandle = *static_cast(ctxMemory); - - if(udfHandle) SQLITE_ORM_CPP_LIKELY { - return udfHandle; - } else { - assert_args_count(proxy, argsCount); - udfHandle = allocate_udf(proxy); - // Note on the use of the `udfHandle` pointer after the object construction: - // since we only ever cast between void* and UDF* pointer types and - // only use the memory space for one type during the entire lifetime of a proxy, - // we can use `udfHandle` interconvertibly without laundering its provenance. - proxy->constructAt(udfHandle); - return udfHandle; - } - } - - inline void delete_aggregate_udf(udf_proxy* proxy, void* udfHandle) { - proxy->destroy(udfHandle); - deallocate_udf(proxy, udfHandle); - } - - // Return C pointer to preallocated and a priori constructed UDF - template - inline UDF* - proxy_get_scalar_udf(std::true_type /*is_stateless*/, sqlite3_context* context, int argsCount) noexcept { - proxy_assert_args_count(context, argsCount); - udf_proxy* proxy = static_cast(sqlite3_user_data(context)); - return static_cast(preallocated_udf_handle(proxy)); - } - - // Return unique pointer to newly constructed UDF at preallocated memory space - template - inline auto proxy_get_scalar_udf(std::false_type /*is_stateless*/, sqlite3_context* context, int argsCount) { - proxy_assert_args_count(context, argsCount); - udf_proxy* proxy = static_cast(sqlite3_user_data(context)); - // Note on the use of the `udfHandle` pointer after the object construction: - // since we only ever cast between void* and UDF* pointer types and - // only use the memory space for one type during the entire lifetime of a proxy, - // we can use `udfHandle` interconvertibly without laundering its provenance. - proxy->constructAt(preallocated_udf_handle(proxy)); - return std::unique_ptr{static_cast(preallocated_udf_handle(proxy)), - proxy->destroy}; - } - - // note: may throw `std::bad_alloc` in case memory space for the aggregate function object cannot be allocated - template - inline UDF* proxy_get_aggregate_step_udf(sqlite3_context* context, int argsCount) { - udf_proxy* proxy = static_cast(sqlite3_user_data(context)); - void* udfHandle = ensure_aggregate_udf(context, proxy, argsCount); - return static_cast(udfHandle); - } - - inline void aggregate_function_final_callback(sqlite3_context* context) { - udf_proxy* proxy = static_cast(sqlite3_user_data(context)); - void* udfHandle; - try { - // note: it is possible that the 'step' function was never called - udfHandle = ensure_aggregate_udf(context, proxy, -1); - } catch(const std::bad_alloc&) { - sqlite3_result_error_nomem(context); - return; - } - proxy->finalAggregateCall(udfHandle, context); - delete_aggregate_udf(proxy, udfHandle); - } - } -} + */ + struct udf_proxy { + using sqlite_func_t = void (*)(sqlite3_context* context, int argsCount, sqlite3_value** values); + using final_call_fn_t = void (*)(void* udfHandle, sqlite3_context* context); + using memory_alloc = std::pair; + using memory_space = std::pair; + + std::string name; + int argumentsCount; + std::function constructAt; + xdestroy_fn_t destroy; + sqlite_func_t func; + final_call_fn_t finalAggregateCall; + + // allocator/deallocator function pair for aggregate UDF + const memory_alloc udfAllocator; + // pointer to preallocated memory space for scalar UDF, already constructed by caller if stateless + const memory_space udfMemorySpace; + + udf_proxy(std::string name, + int argumentsCount, + std::function constructAt, + xdestroy_fn_t destroy, + sqlite_func_t func, + memory_space udfMemorySpace) : + name{std::move(name)}, argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, + destroy{destroy}, func{func}, finalAggregateCall{nullptr}, udfAllocator{}, + udfMemorySpace{udfMemorySpace} {} + + udf_proxy(std::string name, + int argumentsCount, + std::function constructAt, + xdestroy_fn_t destroy, + sqlite_func_t func, + final_call_fn_t finalAggregateCall, + memory_alloc udfAllocator) : + name{std::move(name)}, argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, + destroy{destroy}, func{func}, finalAggregateCall{finalAggregateCall}, udfAllocator{udfAllocator}, + udfMemorySpace{} {} + + ~udf_proxy() { + // destruct + if(/*bool aprioriConstructed = */ !constructAt && destroy) { + destroy(udfMemorySpace.first); + } + // deallocate + if(udfMemorySpace.second) { + udfMemorySpace.second(udfMemorySpace.first); + } + } + + udf_proxy(const udf_proxy&) = delete; + udf_proxy& operator=(const udf_proxy&) = delete; + + // convenience accessors for better legibility; + // [`friend` is intentional - it ensures that these are core accessors (only found via ADL), yet still be an out-of-class interface] + + friend void* preallocated_udf_handle(udf_proxy* proxy) { + return proxy->udfMemorySpace.first; + } + + friend void* allocate_udf(udf_proxy* proxy) { + return proxy->udfAllocator.first(); + } + + friend void deallocate_udf(udf_proxy* proxy, void* udfHandle) { + proxy->udfAllocator.second(udfHandle); + } + }; + + // safety net of doing a triple check at runtime + inline void assert_args_count(const udf_proxy* proxy, int argsCount) { + assert((proxy->argumentsCount == -1) || (proxy->argumentsCount == argsCount || + /*check fin call*/ argsCount == -1)); + (void)proxy; + (void)argsCount; + } + + // safety net of doing a triple check at runtime + inline void proxy_assert_args_count(sqlite3_context* context, int argsCount) { + udf_proxy* proxy; + assert((proxy = static_cast(sqlite3_user_data(context))) != nullptr); + assert_args_count(proxy, argsCount); + (void)context; + } + + // note: may throw `std::bad_alloc` in case memory space for the aggregate function object cannot be allocated + inline void* ensure_aggregate_udf(sqlite3_context* context, udf_proxy* proxy, int argsCount) { + // reserve memory for storing a void pointer (which is the `udfHandle`, i.e. address of the aggregate function object) + void* ctxMemory = sqlite3_aggregate_context(context, sizeof(void*)); + if(!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { + throw std::bad_alloc(); + } + void*& udfHandle = *static_cast(ctxMemory); + + if(udfHandle) SQLITE_ORM_CPP_LIKELY { + return udfHandle; + } else { + assert_args_count(proxy, argsCount); + udfHandle = allocate_udf(proxy); + // Note on the use of the `udfHandle` pointer after the object construction: + // since we only ever cast between void* and UDF* pointer types and + // only use the memory space for one type during the entire lifetime of a proxy, + // we can use `udfHandle` interconvertibly without laundering its provenance. + proxy->constructAt(udfHandle); + return udfHandle; + } + } + + inline void delete_aggregate_udf(udf_proxy* proxy, void* udfHandle) { + proxy->destroy(udfHandle); + deallocate_udf(proxy, udfHandle); + } + + // Return C pointer to preallocated and a priori constructed UDF + template + inline UDF* + proxy_get_scalar_udf(std::true_type /*is_stateless*/, sqlite3_context* context, int argsCount) noexcept { + proxy_assert_args_count(context, argsCount); + udf_proxy* proxy = static_cast(sqlite3_user_data(context)); + return static_cast(preallocated_udf_handle(proxy)); + } + + // Return unique pointer to newly constructed UDF at preallocated memory space + template + inline auto proxy_get_scalar_udf(std::false_type /*is_stateless*/, sqlite3_context* context, int argsCount) { + proxy_assert_args_count(context, argsCount); + udf_proxy* proxy = static_cast(sqlite3_user_data(context)); + // Note on the use of the `udfHandle` pointer after the object construction: + // since we only ever cast between void* and UDF* pointer types and + // only use the memory space for one type during the entire lifetime of a proxy, + // we can use `udfHandle` interconvertibly without laundering its provenance. + proxy->constructAt(preallocated_udf_handle(proxy)); + return std::unique_ptr{static_cast(preallocated_udf_handle(proxy)), + proxy->destroy}; + } + + // note: may throw `std::bad_alloc` in case memory space for the aggregate function object cannot be allocated + template + inline UDF* proxy_get_aggregate_step_udf(sqlite3_context* context, int argsCount) { + udf_proxy* proxy = static_cast(sqlite3_user_data(context)); + void* udfHandle = ensure_aggregate_udf(context, proxy, argsCount); + return static_cast(udfHandle); + } + + inline void aggregate_function_final_callback(sqlite3_context* context) { + udf_proxy* proxy = static_cast(sqlite3_user_data(context)); + void* udfHandle; + try { + // note: it is possible that the 'step' function was never called + udfHandle = ensure_aggregate_udf(context, proxy, -1); + } catch(const std::bad_alloc&) { + sqlite3_result_error_nomem(context); + return; + } + proxy->finalAggregateCall(udfHandle, context); + delete_aggregate_udf(proxy, udfHandle); + } + } +} diff --git a/examples/common_table_expressions.cpp b/examples/common_table_expressions.cpp index e45120d2d..36efcb1d4 100644 --- a/examples/common_table_expressions.cpp +++ b/examples/common_table_expressions.cpp @@ -3,7 +3,7 @@ */ #include -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #define ENABLE_THIS_EXAMPLE #endif diff --git a/examples/core_functions.cpp b/examples/core_functions.cpp index cf20d88ea..4e81a8610 100644 --- a/examples/core_functions.cpp +++ b/examples/core_functions.cpp @@ -61,8 +61,7 @@ struct Customer { std::unique_ptr fax, std::string email, int supportRepId) : - id{id}, - firstName{std::move(firstName)}, lastName{std::move(lastName)}, company{std::move(company)}, + id{id}, firstName{std::move(firstName)}, lastName{std::move(lastName)}, company{std::move(company)}, address{std::move(address)}, city{std::move(city)}, state{std::move(state)}, country{std::move(country)}, postalCode{std::move(postalCode)}, phone{std::move(phone)}, fax{std::move(fax)}, email{std::move(email)}, supportRepId{supportRepId} {} diff --git a/examples/except_intersection.cpp b/examples/except_intersection.cpp index 97a7629ed..c409ce17c 100644 --- a/examples/except_intersection.cpp +++ b/examples/except_intersection.cpp @@ -32,8 +32,7 @@ struct EmpMaster { std::string lastName, long salary, decltype(DeptMaster::deptId) deptId) : - empId{empId}, - firstName{std::move(firstName)}, lastName{std::move(lastName)}, salary{salary}, deptId{deptId} {} + empId{empId}, firstName{std::move(firstName)}, lastName{std::move(lastName)}, salary{salary}, deptId{deptId} {} #endif }; diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 12513f9be..a1266c80f 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -177,12 +177,12 @@ using std::nullptr_t; // In these cases we have to use helper structures to break down the type alias. // Note that the detection of specific compilers is so complicated because some compilers emulate other compilers, // so we simply exclude all compilers that do not support C++20, even though this test is actually inaccurate. -#if(defined(_MSC_VER) && (_MSC_VER < 1920)) || (!defined(_MSC_VER) && (__cplusplus < 202002L)) +#if (defined(_MSC_VER) && (_MSC_VER < 1920)) || (!defined(_MSC_VER) && (__cplusplus < 202002L)) #define SQLITE_ORM_BROKEN_ALIAS_TEMPLATE_DEPENDENT_EXPR_SFINAE #endif // overwrite SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED -#if(__cpp_nontype_template_args < 201911L) && \ +#if (__cpp_nontype_template_args < 201911L) && \ (defined(__clang__) && (__clang_major__ >= 12) && (__cplusplus >= 202002L)) #define SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED #endif @@ -257,13 +257,13 @@ using std::nullptr_t; // The check here doesn't care and checks the library versions in use. // // Another way of detection might be the feature-test macro __cpp_lib_concepts -#if(__cplusplus >= 202002L) && \ +#if (__cplusplus >= 202002L) && \ ((!_LIBCPP_VERSION || _LIBCPP_VERSION >= 13000) && (!_GLIBCXX_RELEASE || _GLIBCXX_RELEASE >= 10)) #define SQLITE_ORM_STL_HAS_DEFAULT_SENTINEL #endif -#if(defined(SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED) && defined(SQLITE_ORM_INLINE_VARIABLES_SUPPORTED) && \ - defined(SQLITE_ORM_CONSTEVAL_SUPPORTED)) && \ +#if (defined(SQLITE_ORM_CLASSTYPE_TEMPLATE_ARGS_SUPPORTED) && defined(SQLITE_ORM_INLINE_VARIABLES_SUPPORTED) && \ + defined(SQLITE_ORM_CONSTEVAL_SUPPORTED)) && \ (defined(SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED)) #define SQLITE_ORM_WITH_CPP20_ALIASES #endif @@ -603,7 +603,7 @@ namespace sqlite_orm { // The check here doesn't care and checks the library versions in use. // // Another way of detection would be the constrained algorithms feature-test macro __cpp_lib_ranges -#if(__cplusplus >= 202002L) && \ +#if (__cplusplus >= 202002L) && \ ((!_LIBCPP_VERSION || _LIBCPP_VERSION >= 13000) && (!_GLIBCXX_RELEASE || _GLIBCXX_RELEASE >= 10)) using std::identity; #else @@ -1076,8 +1076,7 @@ namespace sqlite_orm { * Bind a metafunction and arguments at the front of a higher-order metafunction. */ template class Fn, class... Args2> class HigherFn, - template - class BoundFn, + template class BoundFn, class... Bound> using bind_front_higherorder_fn = bind_front::quote_fn, quote_fn, Bound...>; @@ -1303,8 +1302,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class TraitFn, + template class TraitFn, template class ProjOp = polyfill::type_identity_t> using tuple_has = mpl::invoke_t, Pack, mpl::quote_fn>; @@ -1322,8 +1320,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class Template, + template class Template, template class ProjOp = polyfill::type_identity_t> using tuple_has_template = mpl::invoke_t, Pack, mpl::quote_fn>; @@ -1339,8 +1336,7 @@ namespace sqlite_orm { * `ProjOp` is a metafunction */ template - class Template, + template class Template, template class ProjOp = polyfill::type_identity_t> using find_tuple_template = mpl::invoke_t, Pack, mpl::quote_fn>; @@ -1478,8 +1474,7 @@ namespace sqlite_orm { * `FilterProj` is a metafunction */ template - class Pred, + template class Pred, template class FilterProj = polyfill::type_identity_t, class Seq = std::make_index_sequence::value>> using filter_tuple_sequence_t = typename filter_tuple_sequence::type; @@ -1489,8 +1484,7 @@ namespace sqlite_orm { * `FilterProj` is a metafunction */ template - class Pred, + template class Pred, template class FilterProj = polyfill::type_identity_t, class Seq = std::make_index_sequence::value>> using filter_tuple_t = tuple_from_index_sequence_t>; @@ -1505,8 +1499,7 @@ namespace sqlite_orm { * with a default Sequence in function template parameters [SQLITE_ORM_BROKEN_VARIADIC_PACK_EXPANSION]. */ template - class Pred, + template class Pred, class Seq, template class FilterProj = polyfill::type_identity_t> struct count_filtered_tuple @@ -1838,7 +1831,7 @@ namespace sqlite_orm { using auto_udf_type_t = typename decltype(a)::udf_type; #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template using cte_moniker_type_t = typename T::cte_moniker_type; @@ -1871,7 +1864,7 @@ namespace sqlite_orm { #include // std::make_index_sequence, std::move #include // std::string #include // std::stringstream -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #endif @@ -2018,7 +2011,7 @@ namespace sqlite_orm { */ template SQLITE_ORM_INLINE_VAR constexpr bool is_cte_moniker_v = -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) polyfill::conjunction_v, std::is_same, std::remove_const_t>>; #else @@ -2224,7 +2217,7 @@ namespace sqlite_orm { SQLITE_ORM_INLINE_VAR constexpr bool is_operator_argument_v::value>> = true; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct alias_holder; #endif @@ -2240,7 +2233,7 @@ namespace sqlite_orm { * storage.select(column(&BaseType::id)); */ template = true> - constexpr internal::column_pointer column(F Base::*field) { + constexpr internal::column_pointer column(F Base::* field) { static_assert(std::is_convertible::value, "Field must be from derived class"); return {field}; } @@ -2250,7 +2243,7 @@ namespace sqlite_orm { * Explicitly refer to a column. */ template - constexpr auto column(F O::*field) { + constexpr auto column(F O::* field) { return column>(field); } @@ -2261,7 +2254,7 @@ namespace sqlite_orm { * Explicitly refer to a column. */ template - constexpr auto operator->*(const R& /*table*/, F O::*field) { + constexpr auto operator->*(const R& /*table*/, F O::* field) { return column(field); } } @@ -2285,7 +2278,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Explicitly refer to a column alias mapped into a CTE or subquery. * @@ -2434,7 +2427,7 @@ namespace sqlite_orm { return alias_extractor::extract(); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // for CTE monikers -> empty template, A> = true> static std::string as_alias() { @@ -2501,7 +2494,7 @@ namespace sqlite_orm { }; #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template SQLITE_ORM_CONSTEVAL auto n_to_colalias() { constexpr column_alias<'1' + n % 10, C...> colalias{}; @@ -2556,7 +2549,7 @@ namespace sqlite_orm { polyfill::conjunction, polyfill::negation>>>::value, bool> = true> - constexpr auto alias_column(F O::*field) { + constexpr auto alias_column(F O::* field) { using namespace ::sqlite_orm::internal; using aliased_type = type_t; static_assert(is_field_of_v, "Column must be from aliased table"); @@ -2614,7 +2607,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Create a column reference to an aliased CTE column. */ @@ -2807,7 +2800,7 @@ namespace sqlite_orm { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) inline namespace literals { /** * column_alias<'1'[, ...]> from a numeric literal. @@ -5745,7 +5738,7 @@ namespace sqlite_orm { } template - internal::using_t using_(F O::*field) { + internal::using_t using_(F O::* field) { return {field}; } template @@ -8250,7 +8243,7 @@ namespace sqlite_orm { // #include "cte_moniker.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES #include #include // std::make_index_sequence @@ -8264,7 +8257,7 @@ namespace sqlite_orm { // #include "alias.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { @@ -8776,7 +8769,7 @@ namespace sqlite_orm { using super::super; }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /* * Turn explicit columns for a CTE into types that the CTE backend understands */ @@ -9089,7 +9082,7 @@ namespace sqlite_orm { return {{std::forward(expressions)...}}; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #if SQLITE_VERSION_NUMBER >= 3035003 #ifdef SQLITE_ORM_WITH_CPP20_ALIASES /* @@ -10448,7 +10441,7 @@ namespace sqlite_orm { // #include "cte_types.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #endif @@ -10459,7 +10452,7 @@ namespace sqlite_orm { // #include "tuple_helper/tuple_fy.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { @@ -10767,8 +10760,7 @@ namespace sqlite_orm { * A function's arguments tuple */ template - class Tuple, + template class Tuple, template class ProjectOp = polyfill::type_identity_t> using function_arguments = typename function_traits::template arguments_tuple; @@ -11606,7 +11598,7 @@ namespace sqlite_orm { template struct column_result_t, void> : column_result_t {}; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct column_result_t>, void> { using table_type = storage_pick_table_t; @@ -11799,9 +11791,8 @@ namespace sqlite_orm { decltype(notnull) notnull_, decltype(dflt_value) dflt_value_, decltype(pk) pk_) : - cid(cid_), - name(std::move(name_)), type(std::move(type_)), notnull(notnull_), dflt_value(std::move(dflt_value_)), - pk(pk_) {} + cid(cid_), name(std::move(name_)), type(std::move(type_)), notnull(notnull_), + dflt_value(std::move(dflt_value_)), pk(pk_) {} #endif }; @@ -11822,9 +11813,8 @@ namespace sqlite_orm { decltype(dflt_value) dflt_value_, decltype(pk) pk_, decltype(hidden) hidden_) : - cid(cid_), - name(std::move(name_)), type(std::move(type_)), notnull(notnull_), dflt_value(std::move(dflt_value_)), - pk(pk_), hidden{hidden_} {} + cid(cid_), name(std::move(name_)), type(std::move(type_)), notnull(notnull_), + dflt_value(std::move(dflt_value_)), pk(pk_), hidden{hidden_} {} #endif }; } @@ -12063,7 +12053,7 @@ namespace sqlite_orm { check_if_is_template>, T>; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * A subselect mapper's CTE moniker, void otherwise. */ @@ -12091,7 +12081,7 @@ namespace sqlite_orm { */ template struct table_t : basic_table { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // this typename is used in contexts where it is known that the 'table' holds a subselect_mapper // instead of a regular object type using cte_mapper_type = O; @@ -12532,7 +12522,7 @@ namespace sqlite_orm { * Find column name by its type and member pointer. */ template = true> - const std::string* find_column_name(const DBOs& dbObjects, F O::*field) { + const std::string* find_column_name(const DBOs& dbObjects, F O::* field) { return pick_table(dbObjects).find_column_name(field); } @@ -12546,7 +12536,7 @@ namespace sqlite_orm { return cp.field; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Materialize column pointer: * 3. by moniker and alias_holder<>. @@ -12582,7 +12572,7 @@ namespace sqlite_orm { return pick_table(dbObjects).find_column_name(field); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Find column name by: * 3. by moniker and alias_holder<>. @@ -15268,7 +15258,7 @@ namespace sqlite_orm { } }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct ast_iterator> { using node_type = CTE; @@ -16947,8 +16937,8 @@ namespace sqlite_orm { transaction_guard_t(connection_ref connection_, std::function commit_func_, std::function rollback_func_) : - connection(std::move(connection_)), - commit_func(std::move(commit_func_)), rollback_func(std::move(rollback_func_)) {} + connection(std::move(connection_)), commit_func(std::move(commit_func_)), + rollback_func(std::move(rollback_func_)) {} transaction_guard_t(transaction_guard_t&& other) : commit_on_destroy(other.commit_on_destroy), connection(std::move(other.connection)), @@ -17373,9 +17363,9 @@ namespace sqlite_orm { xdestroy_fn_t destroy, sqlite_func_t func, memory_space udfMemorySpace) : - name{std::move(name)}, - argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, destroy{destroy}, func{func}, - finalAggregateCall{nullptr}, udfAllocator{}, udfMemorySpace{udfMemorySpace} {} + name{std::move(name)}, argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, + destroy{destroy}, func{func}, finalAggregateCall{nullptr}, udfAllocator{}, + udfMemorySpace{udfMemorySpace} {} udf_proxy(std::string name, int argumentsCount, @@ -17384,9 +17374,9 @@ namespace sqlite_orm { sqlite_func_t func, final_call_fn_t finalAggregateCall, memory_alloc udfAllocator) : - name{std::move(name)}, - argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, destroy{destroy}, func{func}, - finalAggregateCall{finalAggregateCall}, udfAllocator{udfAllocator}, udfMemorySpace{} {} + name{std::move(name)}, argumentsCount{argumentsCount}, constructAt{std::move(constructAt)}, + destroy{destroy}, func{func}, finalAggregateCall{finalAggregateCall}, udfAllocator{udfAllocator}, + udfMemorySpace{} {} ~udf_proxy() { // destruct @@ -18843,7 +18833,7 @@ namespace sqlite_orm { // #include "cte_column_names_collector.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #include // std::reference_wrapper @@ -18864,7 +18854,7 @@ namespace sqlite_orm { // #include "serializer_context.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) namespace sqlite_orm { namespace internal { // collecting column names utilizes the statement serializer @@ -19980,7 +19970,7 @@ namespace sqlite_orm { } }; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #if SQLITE_VERSION_NUMBER >= 3035003 #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template<> @@ -21748,7 +21738,7 @@ namespace sqlite_orm { // #include "cte_storage.h" -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include #include #include @@ -21890,7 +21880,7 @@ namespace sqlite_orm { namespace sqlite_orm { namespace internal { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) // F = field_type template field/getter template - auto extract_colref_expressions(const DBOs& /*dbObjects*/, F O::*col, std::index_sequence = {}) { + auto extract_colref_expressions(const DBOs& /*dbObjects*/, F O::* col, std::index_sequence = {}) { return std::make_tuple(col); } @@ -22407,7 +22397,7 @@ namespace sqlite_orm { return {this->db_objects, std::move(con), std::move(expression)}; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED requires(is_select_v) @@ -22482,7 +22472,7 @@ namespace sqlite_orm { protected: template - std::string group_concat_internal(F O::*m, std::unique_ptr y, Args&&... args) { + std::string group_concat_internal(F O::* m, std::unique_ptr y, Args&&... args) { this->assert_mapped_type(); std::vector rows; if(y) { @@ -22869,7 +22859,7 @@ namespace sqlite_orm { return this->execute(statement); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) /** * Using a CTE, select a single column into std::vector or multiple columns into std::vector>. */ @@ -23134,12 +23124,12 @@ namespace sqlite_orm { template [[deprecated("Use the more accurately named function `find_column_name()`")]] const std::string* - column_name(F O::*memberPointer) const { + column_name(F O::* memberPointer) const { return internal::find_column_name(this->db_objects, memberPointer); } template - const std::string* find_column_name(F O::*memberPointer) const { + const std::string* find_column_name(F O::* memberPointer) const { return internal::find_column_name(this->db_objects, memberPointer); } @@ -23387,7 +23377,7 @@ namespace sqlite_orm { using storage_base::table_exists; // now that it is in storage_base make it into overload set -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template, @@ -23521,7 +23511,7 @@ namespace sqlite_orm { perform_step(stmt); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template< class... CTEs, class E, @@ -23756,7 +23746,7 @@ namespace sqlite_orm { perform_step(stmt); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template auto execute(const prepared_statement_t, CTEs...>>& statement) { using ExprDBOs = decltype(db_objects_for_expression(this->db_objects, statement.expression)); @@ -24403,7 +24393,7 @@ namespace sqlite_orm { template struct node_tuple> : node_tuple {}; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template struct node_tuple> : node_tuple {}; diff --git a/tests/ast_iterator_tests.cpp b/tests/ast_iterator_tests.cpp index 159b53678..c56580bfd 100644 --- a/tests/ast_iterator_tests.cpp +++ b/tests/ast_iterator_tests.cpp @@ -330,7 +330,7 @@ TEST_CASE("ast_iterator") { iterate_ast(expression, lambda); } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("with ordinary") { using cte_1 = decltype(1_ctealias); auto expression = with(cte().as(select(1)), select(column(1_colalias))); diff --git a/tests/built_in_functions_tests/core_functions_tests.cpp b/tests/built_in_functions_tests/core_functions_tests.cpp index 3faf6623f..74d620a5f 100644 --- a/tests/built_in_functions_tests/core_functions_tests.cpp +++ b/tests/built_in_functions_tests/core_functions_tests.cpp @@ -540,8 +540,7 @@ TEST_CASE("ifnull") { decltype(fax) fax, std::string email, int supportRepId) : - id{id}, - firstName{std::move(firstName)}, lastName{std::move(lastName)}, company{std::move(company)}, + id{id}, firstName{std::move(firstName)}, lastName{std::move(lastName)}, company{std::move(company)}, address{std::move(address)}, city{std::move(city)}, state{std::move(state)}, country{std::move(country)}, postalCode{std::move(postalCode)}, phone{std::move(phone)}, fax{std::move(fax)}, email{std::move(email)}, supportRepId{supportRepId} {} diff --git a/tests/built_in_functions_tests/math_functions.cpp b/tests/built_in_functions_tests/math_functions.cpp index eb8ee7eea..856120736 100644 --- a/tests/built_in_functions_tests/math_functions.cpp +++ b/tests/built_in_functions_tests/math_functions.cpp @@ -25,442 +25,502 @@ TEST_CASE("math functions") { } }; #endif - SECTION("acos"){SECTION("simple"){auto rows = storage.select(sqlite_orm::acos(1)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("acos") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::acos(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::acos>(1)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::acos>(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("acosh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::acosh(1)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("acosh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::acosh(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::acosh>(1)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::acosh>(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("asin"){SECTION("simple"){auto rows = storage.select(sqlite_orm::asin(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("asin") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::asin(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::asin>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::asin>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("asinh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::asinh(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("asinh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::asinh(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::asinh>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::asinh>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("atan"){SECTION("simple"){auto rows = storage.select(sqlite_orm::atan(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("atan") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::atan(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::atan>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::atan>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("atan2"){SECTION("simple"){auto rows = storage.select(sqlite_orm::atan2(0, 1)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("atan2") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::atan2(0, 1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::atan2>(0, 1)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::atan2>(0, 1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("atanh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::atanh(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("atanh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::atanh(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::atanh>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::atanh>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("ceil"){SECTION("simple"){auto rows = storage.select(sqlite_orm::ceil(0.5)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("ceil") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::ceil(0.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::ceil>(0.5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::ceil>(0.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("ceiling"){SECTION("simple"){auto rows = storage.select(sqlite_orm::ceiling(0.5)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("ceiling") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::ceiling(0.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::ceiling>(0.5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::ceiling>(0.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("cos"){SECTION("simple"){auto rows = storage.select(sqlite_orm::cos(0)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("cos") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::cos(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::cos>(0)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::cos>(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("cosh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::cosh(0)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("cosh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::cosh(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::cosh>(0)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::cosh>(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("degrees"){SECTION("simple"){auto rows = storage.select(sqlite_orm::degrees(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("degrees") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::degrees(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::degrees>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::degrees>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("exp"){SECTION("simple"){auto rows = storage.select(sqlite_orm::exp(0)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("exp") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::exp(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::exp>(0)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::exp>(0)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("floor"){SECTION("simple"){auto rows = storage.select(sqlite_orm::floor(1.5)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("floor") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::floor(1.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::floor>(1.5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::floor>(1.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("ln"){SECTION("simple"){auto rows = storage.select(sqlite_orm::ln(1)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("ln") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::ln(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::ln>(1)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::ln>(1)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("log(x)"){SECTION("simple"){auto rows = storage.select(sqlite_orm::log(10)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); -} + } + SECTION("log(x)") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::log(10)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::log>(10)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::log>(10)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("log10"){SECTION("simple"){auto rows = storage.select(sqlite_orm::log10(10)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); -} + } + SECTION("log10") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::log10(10)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::log10>(10)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::log10>(10)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("log(b, x)"){SECTION("simple"){auto rows = storage.select(sqlite_orm::log(25, 625)); -decltype(rows) expected; -expected.push_back(2); -REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); -} + } + SECTION("log(b, x)") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::log(25, 625)); + decltype(rows) expected; + expected.push_back(2); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::log>(25, 625)); - decltype(rows) expected; - expected.push_back(2); - REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::log>(25, 625)); + decltype(rows) expected; + expected.push_back(2); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("log2"){SECTION("simple"){auto rows = storage.select(sqlite_orm::log2(4)); -decltype(rows) expected; -expected.push_back(2); -REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); -} + } + SECTION("log2") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::log2(4)); + decltype(rows) expected; + expected.push_back(2); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::log2>(4)); - decltype(rows) expected; - expected.push_back(2); - REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::log2>(4)); + decltype(rows) expected; + expected.push_back(2); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("mod"){SECTION("simple"){auto rows = storage.select(sqlite_orm::mod_f(6, 5)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("mod") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::mod_f(6, 5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::mod_f>(6, 5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::mod_f>(6, 5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("pi"){SECTION("simple"){auto rows = storage.select(sqlite_orm::pi()); -decltype(rows) expected; -expected.push_back(3.141592654); -REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); -} + } + SECTION("pi") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::pi()); + decltype(rows) expected; + expected.push_back(3.141592654); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), doubleComparator)); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::pi>()); - decltype(rows) expected; - expected.push_back(3.141592654); - REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::pi>()); + decltype(rows) expected; + expected.push_back(3.141592654); + REQUIRE(std::equal(rows.begin(), rows.end(), expected.begin(), optionalComparator)); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("pow"){SECTION("simple"){auto rows = storage.select(sqlite_orm::pow(2, 3)); -decltype(rows) expected; -expected.push_back(8); -REQUIRE(rows == expected); -} + } + SECTION("pow") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::pow(2, 3)); + decltype(rows) expected; + expected.push_back(8); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::pow>(2, 3)); - decltype(rows) expected; - expected.push_back(8); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::pow>(2, 3)); + decltype(rows) expected; + expected.push_back(8); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("power"){SECTION("simple"){auto rows = storage.select(sqlite_orm::power(2, 3)); -decltype(rows) expected; -expected.push_back(8); -REQUIRE(rows == expected); -} + } + SECTION("power") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::power(2, 3)); + decltype(rows) expected; + expected.push_back(8); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::power>(2, 3)); - decltype(rows) expected; - expected.push_back(8); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::power>(2, 3)); + decltype(rows) expected; + expected.push_back(8); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("radians"){SECTION("simple"){auto rows = storage.select(sqlite_orm::radians(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("radians") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::radians(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::radians>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::radians>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("sin"){SECTION("simple"){auto rows = storage.select(sqlite_orm::sin(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("sin") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::sin(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::sin>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::sin>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("sinh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::sinh(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("sinh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::sinh(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::sinh>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::sinh>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("sqrt"){SECTION("simple"){auto rows = storage.select(sqlite_orm::sqrt(1)); -decltype(rows) expected; -expected.push_back(1); -REQUIRE(rows == expected); -} + } + SECTION("sqrt") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::sqrt(1)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::sqrt>(1)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::sqrt>(1)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("tan"){SECTION("simple"){auto rows = storage.select(sqlite_orm::tan(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("tan") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::tan(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::tan>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::tan>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("tanh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::tanh(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("tanh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::tanh(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::tanh>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::tanh>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("tanh"){SECTION("simple"){auto rows = storage.select(sqlite_orm::tanh(0)); -decltype(rows) expected; -expected.push_back(0); -REQUIRE(rows == expected); -} + } + SECTION("tanh") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::tanh(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED -SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::tanh>(0)); - decltype(rows) expected; - expected.push_back(0); - REQUIRE(rows == expected); -} + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::tanh>(0)); + decltype(rows) expected; + expected.push_back(0); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} -SECTION("trunc") { - SECTION("simple") { - auto rows = storage.select(sqlite_orm::trunc(1.5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); } + SECTION("trunc") { + SECTION("simple") { + auto rows = storage.select(sqlite_orm::trunc(1.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED - SECTION("explicit type") { - auto rows = storage.select(sqlite_orm::trunc>(1.5)); - decltype(rows) expected; - expected.push_back(1); - REQUIRE(rows == expected); - } + SECTION("explicit type") { + auto rows = storage.select(sqlite_orm::trunc>(1.5)); + decltype(rows) expected; + expected.push_back(1); + REQUIRE(rows == expected); + } #endif // SQLITE_ORM_OPTIONAL_SUPPORTED -} + } } #endif // SQLITE_ENABLE_MATH_FUNCTIONS diff --git a/tests/catch_matchers.h b/tests/catch_matchers.h index d921c6b9d..4e816a62e 100644 --- a/tests/catch_matchers.h +++ b/tests/catch_matchers.h @@ -1,23 +1,23 @@ -#pragma once -#include -#include -#include - -class ErrorCodeExceptionMatcher : public Catch::Matchers::MatcherGenericBase { - public: - ErrorCodeExceptionMatcher(std::error_code errorCode) : errorCode(std::move(errorCode)) {} - - bool match(const std::system_error& systemError) const { - return systemError.code() == this->errorCode; - } - - protected: - std::string describe() const override { - std::stringstream ss; - ss << this->errorCode; - return ss.str(); - } - - private: - std::error_code errorCode; -}; +#pragma once +#include +#include +#include + +class ErrorCodeExceptionMatcher : public Catch::Matchers::MatcherGenericBase { + public: + ErrorCodeExceptionMatcher(std::error_code errorCode) : errorCode(std::move(errorCode)) {} + + bool match(const std::system_error& systemError) const { + return systemError.code() == this->errorCode; + } + + protected: + std::string describe() const override { + std::stringstream ss; + ss << this->errorCode; + return ss.str(); + } + + private: + std::error_code errorCode; +}; diff --git a/tests/constraints/foreign_key.cpp b/tests/constraints/foreign_key.cpp index 203f6ea14..b4fd703ba 100644 --- a/tests/constraints/foreign_key.cpp +++ b/tests/constraints/foreign_key.cpp @@ -72,7 +72,7 @@ TEST_CASE("Foreign key 2") { class test1 { public: // Constructors - test1(){}; + test1() {}; // Variables int id; @@ -83,7 +83,7 @@ TEST_CASE("Foreign key 2") { class test2 { public: // Constructors - test2(){}; + test2() {}; // Variables int id; diff --git a/tests/iterate.cpp b/tests/iterate.cpp index 50ac4ecaa..1c16ea7de 100644 --- a/tests/iterate.cpp +++ b/tests/iterate.cpp @@ -97,7 +97,7 @@ TEST_CASE("Iterate select statement") { } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES constexpr auto x = "x"_cte; std::input_iterator auto begin = diff --git a/tests/prepared_statement_tests/prepared_common.h b/tests/prepared_statement_tests/prepared_common.h index f45d30287..1d4f81927 100644 --- a/tests/prepared_statement_tests/prepared_common.h +++ b/tests/prepared_statement_tests/prepared_common.h @@ -36,9 +36,7 @@ namespace PreparedStatementTests { UserAndVisit() = default; UserAndVisit(decltype(UserAndVisit::userId) userId, decltype(UserAndVisit::visitId) visitId, - std::string description) : - userId{userId}, - visitId{visitId}, description{std::move(description)} {} + std::string description) : userId{userId}, visitId{visitId}, description{std::move(description)} {} #endif }; diff --git a/tests/statement_serializer_tests/aggregate_functions.cpp b/tests/statement_serializer_tests/aggregate_functions.cpp index 5ff1542f9..ade9ef86e 100644 --- a/tests/statement_serializer_tests/aggregate_functions.cpp +++ b/tests/statement_serializer_tests/aggregate_functions.cpp @@ -94,7 +94,7 @@ TEST_CASE("statement_serializer aggregate functions") { expected = R"(COUNT(*))"; } #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES SECTION("with CTE") { auto expression = count<1_ctealias>(); diff --git a/tests/statement_serializer_tests/alias_extractor.cpp b/tests/statement_serializer_tests/alias_extractor.cpp index cffad5663..e31450073 100644 --- a/tests/statement_serializer_tests/alias_extractor.cpp +++ b/tests/statement_serializer_tests/alias_extractor.cpp @@ -19,7 +19,7 @@ TEST_CASE("alias extractor") { REQUIRE(alias_extractor>::extract() == "a"); REQUIRE(alias_extractor>::as_alias() == "a"); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("cte moniker") { using cte_1 = decltype(1_ctealias); REQUIRE(alias_extractor::extract() == "1"); diff --git a/tests/statement_serializer_tests/column_names.cpp b/tests/statement_serializer_tests/column_names.cpp index 7df497473..b1963cf82 100644 --- a/tests/statement_serializer_tests/column_names.cpp +++ b/tests/statement_serializer_tests/column_names.cpp @@ -164,7 +164,7 @@ TEST_CASE("statement_serializer column names") { auto value = serialize(alias_column(&Object::id), context); REQUIRE(value == R"("a"."id")"); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES SECTION("cte") { auto dbObjects2 = diff --git a/tests/statement_serializer_tests/conditions.cpp b/tests/statement_serializer_tests/conditions.cpp index c4376324e..31a6db640 100644 --- a/tests/statement_serializer_tests/conditions.cpp +++ b/tests/statement_serializer_tests/conditions.cpp @@ -1,45 +1,45 @@ -#include -#include - -using namespace sqlite_orm; - -TEST_CASE("statement_serializer conditions") { - std::string value, expected; - - SECTION("using") { - struct User { - int64 id; - }; - - auto t1 = make_table("user", make_column("id", &User::id)); - auto storage = internal::db_objects_tuple{t1}; - using db_objects_tuple = decltype(storage); - - internal::serializer_context ctx{storage}; - - SECTION("using column") { - auto expression = using_(&User::id); - value = serialize(expression, ctx); - expected = R"(USING ("id"))"; - } - SECTION("using explicit column") { - auto expression = using_(column(&User::id)); - value = serialize(expression, ctx); - expected = R"(USING ("id"))"; - } - } - SECTION("order by") { - auto storage = internal::db_objects_tuple<>{}; - using db_objects_tuple = decltype(storage); - - internal::serializer_context ctx{storage}; - - SECTION("positional ordinal") { - auto expression = order_by(1); - value = serialize(expression, ctx); - expected = "ORDER BY 1"; - } - } - - REQUIRE(value == expected); -} +#include +#include + +using namespace sqlite_orm; + +TEST_CASE("statement_serializer conditions") { + std::string value, expected; + + SECTION("using") { + struct User { + int64 id; + }; + + auto t1 = make_table("user", make_column("id", &User::id)); + auto storage = internal::db_objects_tuple{t1}; + using db_objects_tuple = decltype(storage); + + internal::serializer_context ctx{storage}; + + SECTION("using column") { + auto expression = using_(&User::id); + value = serialize(expression, ctx); + expected = R"(USING ("id"))"; + } + SECTION("using explicit column") { + auto expression = using_(column(&User::id)); + value = serialize(expression, ctx); + expected = R"(USING ("id"))"; + } + } + SECTION("order by") { + auto storage = internal::db_objects_tuple<>{}; + using db_objects_tuple = decltype(storage); + + internal::serializer_context ctx{storage}; + + SECTION("positional ordinal") { + auto expression = order_by(1); + value = serialize(expression, ctx); + expected = "ORDER BY 1"; + } + } + + REQUIRE(value == expected); +} diff --git a/tests/statement_serializer_tests/select_constraints.cpp b/tests/statement_serializer_tests/select_constraints.cpp index 8aeb1c1c9..b0d05c119 100644 --- a/tests/statement_serializer_tests/select_constraints.cpp +++ b/tests/statement_serializer_tests/select_constraints.cpp @@ -92,7 +92,7 @@ TEST_CASE("statement_serializer select constraints") { } #endif } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("from CTE") { using cte_1 = decltype(1_ctealias); auto dbObjects2 = diff --git a/tests/statement_serializer_tests/statements/insert_replace.cpp b/tests/statement_serializer_tests/statements/insert_replace.cpp index b3882fe26..1a470b2ee 100644 --- a/tests/statement_serializer_tests/statements/insert_replace.cpp +++ b/tests/statement_serializer_tests/statements/insert_replace.cpp @@ -80,7 +80,7 @@ TEST_CASE("statement_serializer insert/replace") { expected = R"(REPLACE INTO "users" SELECT "users_backup"."id", "users_backup"."name" FROM "users_backup")"; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES SECTION("With clause") { constexpr orm_cte_moniker auto data = "data"_cte; @@ -374,7 +374,7 @@ TEST_CASE("statement_serializer insert/replace") { } } SECTION("With clause") { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES constexpr orm_cte_moniker auto data = "data"_cte; constexpr auto cteExpression = cte().as(select(asterisk())); diff --git a/tests/statement_serializer_tests/statements/remove_all.cpp b/tests/statement_serializer_tests/statements/remove_all.cpp index ba30b9c06..44c62a9d5 100644 --- a/tests/statement_serializer_tests/statements/remove_all.cpp +++ b/tests/statement_serializer_tests/statements/remove_all.cpp @@ -33,7 +33,7 @@ TEST_CASE("statement_serializer remove_all") { value = serialize(expression, context); expected = R"(DELETE FROM "users" WHERE ("id" = 1) LIMIT 1)"; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES SECTION("With clause") { constexpr orm_cte_moniker auto data = "data"_cte; diff --git a/tests/statement_serializer_tests/statements/update_all.cpp b/tests/statement_serializer_tests/statements/update_all.cpp index 006255c81..160e1c944 100644 --- a/tests/statement_serializer_tests/statements/update_all.cpp +++ b/tests/statement_serializer_tests/statements/update_all.cpp @@ -60,7 +60,7 @@ TEST_CASE("statement_serializer update_all") { expected = R"(UPDATE "contacts" SET "phone" = (SELECT "customers"."Phone" FROM "customers" WHERE ("customers"."CustomerId" = 1)) WHERE ("contact_id" = 1))"; } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES SECTION("With clause") { constexpr orm_cte_moniker auto data = "data"_cte; diff --git a/tests/static_tests/alias.cpp b/tests/static_tests/alias.cpp index 72ba688b6..cfa83bfda 100644 --- a/tests/static_tests/alias.cpp +++ b/tests/static_tests/alias.cpp @@ -84,7 +84,7 @@ TEST_CASE("aliases") { alias_column(&User::id)); runTest, column_pointer>>(d_alias->*&User::id); #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) runTest>(1_colalias); #ifdef SQLITE_ORM_WITH_CPP20_ALIASES using cte_1 = decltype(1_ctealias); diff --git a/tests/static_tests/column_expression_type.cpp b/tests/static_tests/column_expression_type.cpp index 2d2c3f39b..47c233089 100644 --- a/tests/static_tests/column_expression_type.cpp +++ b/tests/static_tests/column_expression_type.cpp @@ -54,7 +54,7 @@ TEST_CASE("column_expression_of_t") { runTest>(moniker->*&Org::id); runTest>(asterisk()); #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) using cte_1 = decltype(1_ctealias); auto dbObjects2 = internal::db_objects_cat(dbObjects, diff --git a/tests/static_tests/column_pointer.cpp b/tests/static_tests/column_pointer.cpp index 5c1eb6eb4..74cb0ce73 100644 --- a/tests/static_tests/column_pointer.cpp +++ b/tests/static_tests/column_pointer.cpp @@ -1,187 +1,187 @@ -#include -#include // std::is_same -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES -#include // same_as -#endif -#include - -using namespace sqlite_orm; -using internal::column_pointer; -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES -using internal::count_asterisk_t; -using internal::decay_table_ref_t; -using internal::get_all_optional_t; -using internal::get_all_pointer_t; -using internal::get_all_t; -using internal::get_optional_t; -using internal::get_pointer_t; -using internal::get_t; -using internal::is_recordset_alias_v; -using internal::is_table_alias_v; -using internal::mapped_view; -using internal::remove_all_t; -using internal::remove_t; -using internal::table_reference; -using internal::using_t; -using std::same_as; -#endif - -template -void do_assert() { - STATIC_REQUIRE(std::is_same::value); -} - -template -void runTest(const T& /*test*/) { - do_assert(); -} - -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES -template -concept field_callable = requires(C field) { - count(field); - avg(field); - max(field); - min(field); - sum(field); - total(field); - group_concat(field); -}; - -template -concept storage_field_callable = requires(S& storage, C field) { - { storage.count(field) } -> same_as; - { storage.avg(field) } -> same_as; - { storage.max(field) }; - { storage.min(field) }; - { storage.sum(field) }; - { storage.total(field) } -> same_as; - { storage.group_concat(field) } -> same_as; - { storage.group_concat(field, "") } -> same_as; - { storage.group_concat(field, std::string{}) } -> same_as; - { storage.group_concat(field, 42) } -> same_as; -}; - -template -concept refers_to_recordset_callable = requires { - { count() } -> same_as>>; -}; - -template> -concept refers_to_table_callable = requires { - { get_all() } -> same_as, std::vector>>; - { count() } -> same_as>>; -}; - -template> -concept table_reference_callable = requires { - { get(42) } -> same_as>; - { get_pointer
(42) } -> same_as>; - { get_optional
(42) } -> same_as>; - { get_all
() } -> same_as>>; - { get_all_pointer
() } -> same_as>>; - { get_all_optional
() } -> same_as>>; - { remove
(42) } -> same_as>; - { remove_all
() } -> same_as>; - { count
() } -> same_as>; -}; - -template> -concept storage_refers_to_table_callable = requires(S& storage) { - { storage.get_all() } -> same_as>; - { storage.count() } -> same_as; - { storage.iterate() } -> same_as>; -}; - -template> -concept storage_table_reference_callable = requires(S& storage) { - { storage.get
(42) } -> same_as; - { storage.get_pointer
(42) } -> same_as>; - { storage.get_optional
(42) } -> same_as>; - { storage.get_all
() } -> same_as>; - { storage.get_all_pointer
() } -> same_as>>; - { storage.get_all_optional
() } -> same_as>>; - { storage.remove
(42) } -> same_as; - { storage.remove_all
() } -> same_as; - { storage.count
() } -> same_as; - { storage.iterate
() } -> same_as>; -}; -#endif - -TEST_CASE("column pointers") { - struct User { - int id; - }; - struct DerivedUser : User {}; -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES - constexpr auto derived_user = c(); -#endif - - SECTION("table reference") { -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES - STATIC_REQUIRE(orm_table_reference); - STATIC_REQUIRE_FALSE(is_table_alias_v); - STATIC_REQUIRE_FALSE(is_recordset_alias_v); - STATIC_REQUIRE_FALSE(orm_table_alias); - STATIC_REQUIRE_FALSE(orm_recordset_alias); - runTest>(derived_user); - runTest(internal::auto_decay_table_ref_t{}); -#endif - } - SECTION("column pointer expressions") { - runTest>(column(&User::id)); - runTest>(column(&DerivedUser::id)); -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES - runTest>(derived_user->*&DerivedUser::id); - STATIC_REQUIRE(field_callable); - STATIC_REQUIRE(field_callable*&DerivedUser::id)>); - - using storage_type = decltype(make_storage( - "", - make_table("user", make_column("id", &User::id, primary_key())), - make_table("derived_user", make_column("id", &DerivedUser::id, primary_key())))); - - STATIC_REQUIRE(storage_field_callable); - STATIC_REQUIRE(storage_field_callable*&DerivedUser::id)>); -#endif - } -#ifdef SQLITE_ORM_WITH_CPP20_ALIASES - SECTION("table reference expressions") { - runTest>(make_table("derived_user")); - runTest>(from()); - runTest>(asterisk()); - runTest>(object()); - runTest>(count()); - runTest>(get(42)); - runTest>>(get_all()); - runTest>>( - left_join(using_(derived_user->*&DerivedUser::id))); - runTest>>( - join(using_(derived_user->*&DerivedUser::id))); - runTest>>( - left_outer_join(using_(derived_user->*&DerivedUser::id))); - runTest>>( - inner_join(using_(derived_user->*&DerivedUser::id))); - - STATIC_REQUIRE(refers_to_recordset_callable); - STATIC_REQUIRE(refers_to_table_callable); - STATIC_REQUIRE(table_reference_callable); - STATIC_REQUIRE(refers_to_recordset_callable); - STATIC_REQUIRE(refers_to_table_callable); - STATIC_REQUIRE(table_reference_callable); - STATIC_REQUIRE(refers_to_recordset_callable); - STATIC_REQUIRE(refers_to_table_callable); - - using storage_type = decltype(make_storage( - "", - make_sqlite_schema_table(), - make_table("derived_user", make_column("id", &DerivedUser::id, primary_key())))); - - STATIC_REQUIRE(storage_refers_to_table_callable); - STATIC_REQUIRE(storage_table_reference_callable); - STATIC_REQUIRE(storage_refers_to_table_callable); - STATIC_REQUIRE(storage_table_reference_callable); - STATIC_REQUIRE(storage_refers_to_table_callable); - } -#endif -} +#include +#include // std::is_same +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +#include // same_as +#endif +#include + +using namespace sqlite_orm; +using internal::column_pointer; +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +using internal::count_asterisk_t; +using internal::decay_table_ref_t; +using internal::get_all_optional_t; +using internal::get_all_pointer_t; +using internal::get_all_t; +using internal::get_optional_t; +using internal::get_pointer_t; +using internal::get_t; +using internal::is_recordset_alias_v; +using internal::is_table_alias_v; +using internal::mapped_view; +using internal::remove_all_t; +using internal::remove_t; +using internal::table_reference; +using internal::using_t; +using std::same_as; +#endif + +template +void do_assert() { + STATIC_REQUIRE(std::is_same::value); +} + +template +void runTest(const T& /*test*/) { + do_assert(); +} + +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES +template +concept field_callable = requires(C field) { + count(field); + avg(field); + max(field); + min(field); + sum(field); + total(field); + group_concat(field); +}; + +template +concept storage_field_callable = requires(S& storage, C field) { + { storage.count(field) } -> same_as; + { storage.avg(field) } -> same_as; + { storage.max(field) }; + { storage.min(field) }; + { storage.sum(field) }; + { storage.total(field) } -> same_as; + { storage.group_concat(field) } -> same_as; + { storage.group_concat(field, "") } -> same_as; + { storage.group_concat(field, std::string{}) } -> same_as; + { storage.group_concat(field, 42) } -> same_as; +}; + +template +concept refers_to_recordset_callable = requires { + { count() } -> same_as>>; +}; + +template> +concept refers_to_table_callable = requires { + { get_all() } -> same_as, std::vector>>; + { count() } -> same_as>>; +}; + +template> +concept table_reference_callable = requires { + { get
(42) } -> same_as>; + { get_pointer
(42) } -> same_as>; + { get_optional
(42) } -> same_as>; + { get_all
() } -> same_as>>; + { get_all_pointer
() } -> same_as>>; + { get_all_optional
() } -> same_as>>; + { remove
(42) } -> same_as>; + { remove_all
() } -> same_as>; + { count
() } -> same_as>; +}; + +template> +concept storage_refers_to_table_callable = requires(S& storage) { + { storage.get_all() } -> same_as>; + { storage.count() } -> same_as; + { storage.iterate() } -> same_as>; +}; + +template> +concept storage_table_reference_callable = requires(S& storage) { + { storage.get
(42) } -> same_as; + { storage.get_pointer
(42) } -> same_as>; + { storage.get_optional
(42) } -> same_as>; + { storage.get_all
() } -> same_as>; + { storage.get_all_pointer
() } -> same_as>>; + { storage.get_all_optional
() } -> same_as>>; + { storage.remove
(42) } -> same_as; + { storage.remove_all
() } -> same_as; + { storage.count
() } -> same_as; + { storage.iterate
() } -> same_as>; +}; +#endif + +TEST_CASE("column pointers") { + struct User { + int id; + }; + struct DerivedUser : User {}; +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES + constexpr auto derived_user = c(); +#endif + + SECTION("table reference") { +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES + STATIC_REQUIRE(orm_table_reference); + STATIC_REQUIRE_FALSE(is_table_alias_v); + STATIC_REQUIRE_FALSE(is_recordset_alias_v); + STATIC_REQUIRE_FALSE(orm_table_alias); + STATIC_REQUIRE_FALSE(orm_recordset_alias); + runTest>(derived_user); + runTest(internal::auto_decay_table_ref_t{}); +#endif + } + SECTION("column pointer expressions") { + runTest>(column(&User::id)); + runTest>(column(&DerivedUser::id)); +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES + runTest>(derived_user->*&DerivedUser::id); + STATIC_REQUIRE(field_callable); + STATIC_REQUIRE(field_callable*&DerivedUser::id)>); + + using storage_type = decltype(make_storage( + "", + make_table("user", make_column("id", &User::id, primary_key())), + make_table("derived_user", make_column("id", &DerivedUser::id, primary_key())))); + + STATIC_REQUIRE(storage_field_callable); + STATIC_REQUIRE(storage_field_callable*&DerivedUser::id)>); +#endif + } +#ifdef SQLITE_ORM_WITH_CPP20_ALIASES + SECTION("table reference expressions") { + runTest>(make_table("derived_user")); + runTest>(from()); + runTest>(asterisk()); + runTest>(object()); + runTest>(count()); + runTest>(get(42)); + runTest>>(get_all()); + runTest>>( + left_join(using_(derived_user->*&DerivedUser::id))); + runTest>>( + join(using_(derived_user->*&DerivedUser::id))); + runTest>>( + left_outer_join(using_(derived_user->*&DerivedUser::id))); + runTest>>( + inner_join(using_(derived_user->*&DerivedUser::id))); + + STATIC_REQUIRE(refers_to_recordset_callable); + STATIC_REQUIRE(refers_to_table_callable); + STATIC_REQUIRE(table_reference_callable); + STATIC_REQUIRE(refers_to_recordset_callable); + STATIC_REQUIRE(refers_to_table_callable); + STATIC_REQUIRE(table_reference_callable); + STATIC_REQUIRE(refers_to_recordset_callable); + STATIC_REQUIRE(refers_to_table_callable); + + using storage_type = decltype(make_storage( + "", + make_sqlite_schema_table(), + make_table("derived_user", make_column("id", &DerivedUser::id, primary_key())))); + + STATIC_REQUIRE(storage_refers_to_table_callable); + STATIC_REQUIRE(storage_table_reference_callable); + STATIC_REQUIRE(storage_refers_to_table_callable); + STATIC_REQUIRE(storage_table_reference_callable); + STATIC_REQUIRE(storage_refers_to_table_callable); + } +#endif +} diff --git a/tests/static_tests/column_result_t.cpp b/tests/static_tests/column_result_t.cpp index cbfef385f..5f154bc73 100644 --- a/tests/static_tests/column_result_t.cpp +++ b/tests/static_tests/column_result_t.cpp @@ -137,7 +137,7 @@ TEST_CASE("column_result_of_t") { columns(struct_(asterisk()), struct_(asterisk()))); runTest(union_all(select(1), select(2))); runTest(union_all(select(1ll), select(2))); -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) using cte_1 = decltype(1_ctealias); // note: even though used with the CTE, &User::id doesn't need to be mapped into the CTE to make column results work; // this is because the result type is taken from the member pointer just because we can't look it up in the storage definition diff --git a/tests/static_tests/cte.cpp b/tests/static_tests/cte.cpp index b55231f6c..b069ce4fb 100644 --- a/tests/static_tests/cte.cpp +++ b/tests/static_tests/cte.cpp @@ -1,5 +1,5 @@ #include -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #include // std::is_same, std::is_constructible #include // std::ignore #include // std::string diff --git a/tests/static_tests/iterator_t.cpp b/tests/static_tests/iterator_t.cpp index 5902c925e..554692cf5 100644 --- a/tests/static_tests/iterator_t.cpp +++ b/tests/static_tests/iterator_t.cpp @@ -77,7 +77,7 @@ concept storage_iterate_mapped = requires(S& storage_type) { }; #endif -#if(defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED)) && \ +#if (defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED)) && \ defined(SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED) template concept can_iterate_result_set = requires(Iter it) { @@ -131,7 +131,9 @@ TEST_CASE("can view and iterate mapped") { STATIC_REQUIRE(std::is_same::value); STATIC_REQUIRE(std::is_same::value); // copyable (partially, as it is a rather extensive concept) - { STATIC_REQUIRE(std::is_copy_constructible::value); } + { + STATIC_REQUIRE(std::is_copy_constructible::value); + } } // equality_comparable (sentinel) { @@ -143,7 +145,9 @@ TEST_CASE("can view and iterate mapped") { STATIC_REQUIRE(std::is_same::difference_type, ptrdiff_t>::value); } // semiregular (actually sentinel_for, but the other concepts were verified above) - { STATIC_REQUIRE(std::is_default_constructible::value); } + { + STATIC_REQUIRE(std::is_default_constructible::value); + } STATIC_REQUIRE(std::is_same::pointer, Object*>::value); // note: should actually be only present for contiguous iterators STATIC_REQUIRE(std::is_same()), Object*>::value); @@ -154,7 +158,7 @@ TEST_CASE("can view and iterate mapped") { #endif } -#if(defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED)) && \ +#if (defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED)) && \ defined(SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED) TEST_CASE("can view and iterate result set") { struct Object {}; @@ -184,7 +188,7 @@ TEST_CASE("can view and iterate result set") { storage_iterate_result_set())), table_reference>); #endif -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) #ifdef SQLITE_ORM_WITH_CPP20_ALIASES constexpr orm_cte_moniker auto x = "x"_cte; constexpr orm_column_alias auto i = "i"_col; diff --git a/tests/static_tests/node_tuple.cpp b/tests/static_tests/node_tuple.cpp index 4a9a07bc6..7109cbf72 100644 --- a/tests/static_tests/node_tuple.cpp +++ b/tests/static_tests/node_tuple.cpp @@ -271,7 +271,7 @@ TEST_CASE("Node tuple") { using Expected = tuple; static_assert(is_same::value, "count(*)"); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("count(*) cte") { auto node = count(); using Node = decltype(node); @@ -997,7 +997,7 @@ TEST_CASE("Node tuple") { using ExpectedTuple = tuple; STATIC_REQUIRE(std::is_same::value); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("with ordinary") { using cte_1 = decltype(1_ctealias); auto expression = with(1_ctealias().as(select(1)), select(column(1_colalias))); diff --git a/tests/static_tests/operators_adl.cpp b/tests/static_tests/operators_adl.cpp index 111358ab2..300d50ce0 100644 --- a/tests/static_tests/operators_adl.cpp +++ b/tests/static_tests/operators_adl.cpp @@ -125,7 +125,7 @@ void runTests(E expression) { } TEST_CASE("inline namespace literals expressions") { -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) constexpr auto col1 = 1_colalias; constexpr auto cte1 = 1_ctealias; #ifdef SQLITE_ORM_WITH_CPP20_ALIASES @@ -149,13 +149,13 @@ TEST_CASE("ADL and pointer-to-member expressions") { }; constexpr auto user_table = c(); constexpr auto u_alias = "u"_alias.for_(); -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) constexpr auto cte = "1"_cte; #endif user_table->*&User::id; u_alias->*&User::id; -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) cte->*&User::id; #endif } diff --git a/tests/static_tests/static_tests_storage_traits.h b/tests/static_tests/static_tests_storage_traits.h index 8c3ad7092..453cf2955 100644 --- a/tests/static_tests/static_tests_storage_traits.h +++ b/tests/static_tests/static_tests_storage_traits.h @@ -1,124 +1,124 @@ -#pragma once +#pragma once /* * All symbols used to be in dev/storage_traits.h up to sqlite_orm 1.7. * Because they were not used, they were moved to unit tests, * and for simplicitly the namespace sqlite_orm::internal::storage_traits was kept. - */ - -#include // std::integral_constant - -#include - -namespace sqlite_orm { - - namespace internal { - - template - using source_type_t = typename T::source_type; - - namespace storage_traits { - - template - struct storage_columns_count_impl - : std::integral_constant>::value> {}; - - template<> - struct storage_columns_count_impl : std::integral_constant {}; - + */ + +#include // std::integral_constant + +#include + +namespace sqlite_orm { + + namespace internal { + + template + using source_type_t = typename T::source_type; + + namespace storage_traits { + + template + struct storage_columns_count_impl + : std::integral_constant>::value> {}; + + template<> + struct storage_columns_count_impl : std::integral_constant {}; + /** * S - storage_t * Lookup - mapped or not mapped data type - */ - template - struct storage_columns_count - : storage_columns_count_impl> {}; - + */ + template + struct storage_columns_count + : storage_columns_count_impl> {}; + /** * Table A `table_t<>` * Lookup is object type which is the reference target (e.g. foreign_key(&Visit::userId).references(&User::id) has Lookup = User) - */ - template - struct table_foreign_keys_count - : count_filtered_tuple, - check_if_is_type::template fn, - filter_tuple_sequence_t, is_foreign_key>, - target_type_t> {}; - + */ + template + struct table_foreign_keys_count + : count_filtered_tuple, + check_if_is_type::template fn, + filter_tuple_sequence_t, is_foreign_key>, + target_type_t> {}; + /** * DBOs - db_objects_tuple * Lookup - type mapped to storage - */ - template - struct storage_foreign_keys_count_impl : std::integral_constant {}; - -#ifdef SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED - template - struct storage_foreign_keys_count_impl, Lookup> { - static constexpr int value = (table_foreign_keys_count::value + ...); - }; -#else - template - struct storage_foreign_keys_count_impl, Lookup> { - static constexpr int value = table_foreign_keys_count::value + - storage_foreign_keys_count_impl, Lookup>::value; - }; -#endif - + */ + template + struct storage_foreign_keys_count_impl : std::integral_constant {}; + +#ifdef SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED + template + struct storage_foreign_keys_count_impl, Lookup> { + static constexpr int value = (table_foreign_keys_count::value + ...); + }; +#else + template + struct storage_foreign_keys_count_impl, Lookup> { + static constexpr int value = table_foreign_keys_count::value + + storage_foreign_keys_count_impl, Lookup>::value; + }; +#endif + /** * S - storage class * Lookup - type mapped to storage * This class tells how many types mapped to DBOs have foreign keys to Lookup - */ - template - struct storage_foreign_keys_count : storage_foreign_keys_count_impl {}; - - template - using table_foreign_keys_t = - filter_tuple_t, - check_if_is_type::template fn, - target_type_t, - filter_tuple_sequence_t, is_foreign_key>>; - + */ + template + struct storage_foreign_keys_count : storage_foreign_keys_count_impl {}; + + template + using table_foreign_keys_t = + filter_tuple_t, + check_if_is_type::template fn, + target_type_t, + filter_tuple_sequence_t, is_foreign_key>>; + /* * Implementation note: must be a struct instead of an alias template because the foreign keys tuple * must be hoisted into a named alias, otherwise type replacement may fail for legacy compilers * if an alias template has a dependent expression in it [SQLITE_ORM_BROKEN_VARIADIC_PACK_EXPANSION]. - */ - template - struct table_fk_references { - using foreign_keys = table_foreign_keys_t; - - using type = transform_tuple_t; - }; - + */ + template + struct table_fk_references { + using foreign_keys = table_foreign_keys_t; + + using type = transform_tuple_t; + }; + /** * DBOs - db_objects_tuple * Lookup - type mapped to storage - */ - template - struct storage_fk_references_impl; - - template - struct storage_foreign_keys_impl; - - template - struct storage_fk_references_impl, Lookup> - : conc_tuple::type...> {}; - - template - struct storage_foreign_keys_impl, Lookup> - : conc_tuple...> {}; - + */ + template + struct storage_fk_references_impl; + + template + struct storage_foreign_keys_impl; + + template + struct storage_fk_references_impl, Lookup> + : conc_tuple::type...> {}; + + template + struct storage_foreign_keys_impl, Lookup> + : conc_tuple...> {}; + /** * S - storage class * Lookup - type mapped to storage * type holds `std::tuple` with types that has references to Lookup as foreign keys - */ - template - struct storage_fk_references : storage_fk_references_impl {}; - - template - struct storage_foreign_keys : storage_foreign_keys_impl {}; - } - } -} + */ + template + struct storage_fk_references : storage_fk_references_impl {}; + + template + struct storage_foreign_keys : storage_foreign_keys_impl {}; + } + } +} diff --git a/tests/storage_tests.cpp b/tests/storage_tests.cpp index b241d78e7..68cd66135 100644 --- a/tests/storage_tests.cpp +++ b/tests/storage_tests.cpp @@ -520,7 +520,7 @@ TEST_CASE("last insert rowid") { } } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) TEST_CASE("With clause") { using Catch::Matchers::Equals; diff --git a/tests/table_name_collector.cpp b/tests/table_name_collector.cpp index a89896962..d4a838c17 100644 --- a/tests/table_name_collector.cpp +++ b/tests/table_name_collector.cpp @@ -49,7 +49,7 @@ TEST_CASE("table name collector") { REQUIRE(collector.table_names == expected); } -#if(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) +#if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) SECTION("from CTE") { auto dbObjects2 = internal::db_objects_cat(dbObjects, internal::make_cte_table(dbObjects, 1_ctealias().as(select(1)))); diff --git a/tests/tests5.cpp b/tests/tests5.cpp index a4ce1bf28..4f26251d1 100644 --- a/tests/tests5.cpp +++ b/tests/tests5.cpp @@ -267,7 +267,7 @@ TEST_CASE("issue822") { public: A() = default; A(const uint8_t& address, const uint8_t& type, const uint8_t& idx, std::shared_ptr value) : - address(address), type(type), idx(idx), value(std::move(value)){}; + address(address), type(type), idx(idx), value(std::move(value)) {}; const uint8_t& getAddress() const { return this->address; From 0b2d4d495308d5dc65d093b59481e6cc6b48fa24 Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Fri, 24 Jan 2025 20:27:47 +0200 Subject: [PATCH 2/2] Updated clang-formatting styles We decided to insert a space after control statements and after a requires clause. --- .clang-format | 6 +- dev/alias.h | 16 +- dev/arg_values.h | 8 +- dev/ast_iterator.h | 2 +- dev/backup.h | 4 +- dev/carray.h | 2 +- dev/column_names_getter.h | 20 +- dev/column_pointer.h | 8 +- dev/connection_holder.h | 10 +- dev/constraints.h | 16 +- dev/core_functions.h | 2 +- dev/cte_column_names_collector.h | 36 +- dev/cte_moniker.h | 8 +- dev/cte_storage.h | 14 +- dev/error_code.h | 2 +- dev/field_printer.h | 6 +- dev/function.h | 16 +- dev/functional/mpl.h | 4 +- dev/functional/static_magic.h | 6 +- dev/get_prepared_statement.h | 8 +- dev/implementations/storage_definitions.h | 32 +- dev/implementations/table_definitions.h | 6 +- dev/journal_mode.h | 8 +- dev/locking_mode.h | 8 +- dev/mapped_iterator.h | 4 +- dev/order_by_serializer.h | 12 +- dev/pointer_value.h | 4 +- dev/pragma.h | 8 +- dev/prepared_statement.h | 6 +- dev/row_extractor.h | 56 +- dev/schema/table.h | 15 +- dev/select_constraints.h | 22 +- dev/serializing_util.h | 32 +- dev/statement_binder.h | 16 +- dev/statement_serializer.h | 170 ++-- dev/storage.h | 88 +- dev/storage_base.h | 96 +- dev/sync_schema_result.h | 2 +- dev/table_name_collector.h | 2 +- dev/transaction_guard.h | 4 +- dev/tuple_helper/tuple_iteration.h | 4 +- dev/udf_proxy.h | 10 +- dev/util.h | 16 +- dev/xdestroy_handling.h | 8 +- examples/any.cpp | 28 +- examples/blob_binding.cpp | 4 +- examples/case.cpp | 6 +- examples/check.cpp | 6 +- examples/chrono_binding.cpp | 6 +- examples/column_aliases.cpp | 8 +- examples/common_table_expressions.cpp | 32 +- examples/composite_key.cpp | 2 +- examples/core_functions.cpp | 28 +- examples/cross_join.cpp | 2 +- examples/custom_aliases.cpp | 2 +- examples/distinct.cpp | 6 +- examples/enum_binding.cpp | 14 +- examples/except_intersection.cpp | 4 +- examples/exists.cpp | 8 +- examples/foreign_key.cpp | 28 +- examples/generated_column.cpp | 4 +- examples/group_by.cpp | 8 +- examples/having.cpp | 4 +- examples/index.cpp | 2 +- examples/insert.cpp | 4 +- examples/iteration.cpp | 8 +- examples/key_value.cpp | 2 +- examples/left_and_inner_join.cpp | 36 +- examples/multi_table_select.cpp | 4 +- examples/natural_join.cpp | 4 +- examples/nullable_enum_binding.cpp | 20 +- examples/pointer_passing_interface.cpp | 8 +- examples/prepared_statement.cpp | 14 +- examples/private_class_members.cpp | 2 +- examples/select.cpp | 24 +- examples/self_join.cpp | 8 +- examples/subentities.cpp | 8 +- examples/subquery.cpp | 16 +- examples/triggers.cpp | 6 +- examples/union.cpp | 4 +- examples/unique.cpp | 2 +- examples/update.cpp | 6 +- examples/user_defined_functions.cpp | 22 +- include/sqlite_orm/sqlite_orm.h | 817 +++++++++--------- tests/backup_tests.cpp | 8 +- .../core_functions_tests.cpp | 2 +- .../math_functions.cpp | 4 +- tests/get_all_custom_containers.cpp | 4 +- tests/iterate.cpp | 4 +- tests/json.cpp | 8 +- tests/operators/arithmetic_operators.cpp | 18 +- tests/operators/glob.cpp | 2 +- tests/pointer_passing_interface.cpp | 4 +- tests/pragma_tests.cpp | 10 +- tests/prepared_statement_tests/insert.cpp | 4 +- .../prepared_statement_tests/insert_range.cpp | 4 +- tests/prepared_statement_tests/select.cpp | 4 +- tests/row_extractor.cpp | 10 +- tests/row_id.cpp | 2 +- tests/select_constraints_tests.cpp | 2 +- .../statement_serializer_tests/bindables.cpp | 2 +- tests/static_tests/function_static_tests.cpp | 4 +- tests/storage_non_crud_tests.cpp | 10 +- tests/storage_tests.cpp | 2 +- tests/sync_schema_tests.cpp | 18 +- tests/tests.cpp | 8 +- tests/tests3.cpp | 10 +- tests/tests5.cpp | 2 +- tests/transaction_tests.cpp | 2 +- tests/unique_cases/issue663.cpp | 4 +- tests/user_defined_functions.cpp | 8 +- 111 files changed, 1103 insertions(+), 1097 deletions(-) diff --git a/.clang-format b/.clang-format index 409ef848c..ccd4b5c73 100644 --- a/.clang-format +++ b/.clang-format @@ -104,7 +104,11 @@ SpaceBeforeAssignmentOperators: true SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true -SpaceBeforeParens: Never +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterRequiresInClause: true + AfterRequiresInExpression: false SpaceBeforeRangeBasedForLoopColon: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 diff --git a/dev/alias.h b/dev/alias.h index 01b852701..c3a1154ea 100644 --- a/dev/alias.h +++ b/dev/alias.h @@ -172,7 +172,7 @@ namespace sqlite_orm { template SQLITE_ORM_CONSTEVAL auto n_to_colalias() { constexpr column_alias<'1' + n % 10, C...> colalias{}; - if constexpr(n > 10) { + if constexpr (n > 10) { return n_to_colalias(); } else { return colalias; @@ -244,16 +244,16 @@ namespace sqlite_orm { * select(alias_column(&User::id)) */ template - requires(!orm_cte_moniker>) + requires (!orm_cte_moniker>) constexpr auto alias_column(C field) { using namespace ::sqlite_orm::internal; using A = decltype(als); using aliased_type = type_t; static_assert(is_field_of_v, "Column must be from aliased table"); - if constexpr(is_column_pointer_v) { + if constexpr (is_column_pointer_v) { return alias_column_t{std::move(field)}; - } else if constexpr(std::is_same_v, aliased_type>) { + } else if constexpr (std::is_same_v, aliased_type>) { return alias_column_t{field}; } else { // wrap in column_pointer @@ -275,7 +275,7 @@ namespace sqlite_orm { * select(als->*&User::id) */ template - requires(!orm_cte_moniker>) + requires (!orm_cte_moniker>) constexpr auto operator->*(const A& /*tableAlias*/, F field) { return alias_column(std::move(field)); } @@ -294,7 +294,7 @@ namespace sqlite_orm { using namespace ::sqlite_orm::internal; using cte_moniker_t = type_t; - if constexpr(is_column_pointer_v) { + if constexpr (is_column_pointer_v) { static_assert(std::is_same, cte_moniker_t>::value, "Column pointer must match aliased CTE"); return alias_column_t{c}; @@ -312,7 +312,7 @@ namespace sqlite_orm { * because recordset aliases are derived from `sqlite_orm::alias_tag` */ template - requires(orm_cte_moniker>) + requires (orm_cte_moniker>) constexpr auto operator->*(const A& /*tableAlias*/, C c) { return alias_column(std::move(c)); } @@ -321,7 +321,7 @@ namespace sqlite_orm { * Create a column reference to an aliased CTE column. */ template - requires(orm_cte_moniker>) + requires (orm_cte_moniker>) constexpr auto alias_column(C c) { using A = std::remove_const_t; return alias_column(std::move(c)); diff --git a/dev/arg_values.h b/dev/arg_values.h index 515a1b12f..0e8260790 100644 --- a/dev/arg_values.h +++ b/dev/arg_values.h @@ -63,7 +63,7 @@ namespace sqlite_orm { iterator& operator++() { ++this->index; - if(this->index < int(this->container.size())) { + if (this->index < int(this->container.size())) { this->currentValue = this->container[this->index]; } else { this->currentValue = {}; @@ -74,7 +74,7 @@ namespace sqlite_orm { iterator operator++(int) { auto res = *this; ++this->index; - if(this->index < int(this->container.size())) { + if (this->index < int(this->container.size())) { this->currentValue = this->container[this->index]; } else { this->currentValue = {}; @@ -83,7 +83,7 @@ namespace sqlite_orm { } arg_value operator*() const { - if(this->index < int(this->container.size()) && this->index >= 0) { + if (this->index < int(this->container.size()) && this->index >= 0) { return this->currentValue; } else { throw std::system_error{orm_error_code::index_is_out_of_bounds}; @@ -121,7 +121,7 @@ namespace sqlite_orm { } arg_value operator[](int index) const { - if(index < this->argsCount && index >= 0) { + if (index < this->argsCount && index >= 0) { sqlite3_value* value = this->values[index]; return {value}; } else { diff --git a/dev/ast_iterator.h b/dev/ast_iterator.h index 7d55996ad..d90dc7e18 100644 --- a/dev/ast_iterator.h +++ b/dev/ast_iterator.h @@ -210,7 +210,7 @@ namespace sqlite_orm { template void operator()(const node_type& vec, L& lambda) const { - for(auto& i: vec) { + for (auto& i: vec) { iterate_ast(i, lambda); } } diff --git a/dev/backup.h b/dev/backup.h index 73b62250e..562632208 100644 --- a/dev/backup.h +++ b/dev/backup.h @@ -27,7 +27,7 @@ namespace sqlite_orm { std::unique_ptr holder_) : handle(sqlite3_backup_init(to_.get(), zDestName.c_str(), from_.get(), zSourceName.c_str())), holder(std::move(holder_)), to(to_), from(from_) { - if(!this->handle) { + if (!this->handle) { throw std::system_error{orm_error_code::failed_to_init_a_backup}; } } @@ -37,7 +37,7 @@ namespace sqlite_orm { from(other.from) {} ~backup_t() { - if(this->handle) { + if (this->handle) { (void)sqlite3_backup_finish(this->handle); } } diff --git a/dev/carray.h b/dev/carray.h index f0c7ab73a..a16d50f9b 100644 --- a/dev/carray.h +++ b/dev/carray.h @@ -126,7 +126,7 @@ namespace sqlite_orm { template struct note_value_fn { P operator()(P&& value, carray_pointer_arg

pv) const { - if(P* observer = pv) { + if (P* observer = pv) { *observer = value; } return std::move(value); diff --git a/dev/column_names_getter.h b/dev/column_names_getter.h index 1792dad73..72fa7c1c6 100644 --- a/dev/column_names_getter.h +++ b/dev/column_names_getter.h @@ -28,16 +28,16 @@ namespace sqlite_orm { std::vector& collect_table_column_names(std::vector& collectedExpressions, bool definedOrder, const Ctx& context) { - if(definedOrder) { + if (definedOrder) { auto& table = pick_table>(context.db_objects); collectedExpressions.reserve(collectedExpressions.size() + table.template count_of()); table.for_each_column([qualified = !context.skip_table_name, &tableName = table.name, &collectedExpressions](const column_identifier& column) { - if(is_alias::value) { + if (is_alias::value) { collectedExpressions.push_back(quote_identifier(alias_extractor::extract()) + "." + quote_identifier(column.name)); - } else if(qualified) { + } else if (qualified) { collectedExpressions.push_back(quote_identifier(tableName) + "." + quote_identifier(column.name)); } else { @@ -46,9 +46,9 @@ namespace sqlite_orm { }); } else { collectedExpressions.reserve(collectedExpressions.size() + 1); - if(is_alias::value) { + if (is_alias::value) { collectedExpressions.push_back(quote_identifier(alias_extractor::extract()) + ".*"); - } else if(!context.skip_table_name) { + } else if (!context.skip_table_name) { const basic_table& table = pick_table>(context.db_objects); collectedExpressions.push_back(quote_identifier(table.name) + ".*"); } else { @@ -68,7 +68,7 @@ namespace sqlite_orm { template std::vector& operator()(const E& t, const Ctx& context) { auto columnExpression = serialize(t, context); - if(columnExpression.empty()) { + if (columnExpression.empty()) { throw std::system_error{orm_error_code::column_not_found}; } this->collectedExpressions.reserve(this->collectedExpressions.size() + 1); @@ -98,8 +98,8 @@ namespace sqlite_orm { (*this)(colExpr, context); }); // note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order - if(tuple_has_template::columns_type, asterisk_t>::value && - this->collectedExpressions.capacity() > this->collectedExpressions.size()) { + if (tuple_has_template::columns_type, asterisk_t>::value && + this->collectedExpressions.capacity() > this->collectedExpressions.size()) { this->collectedExpressions.shrink_to_fit(); } return this->collectedExpressions; @@ -112,8 +112,8 @@ namespace sqlite_orm { (*this)(colExpr, context); }); // note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order - if(tuple_has_template::columns_type, asterisk_t>::value && - this->collectedExpressions.capacity() > this->collectedExpressions.size()) { + if (tuple_has_template::columns_type, asterisk_t>::value && + this->collectedExpressions.capacity() > this->collectedExpressions.size()) { this->collectedExpressions.shrink_to_fit(); } return this->collectedExpressions; diff --git a/dev/column_pointer.h b/dev/column_pointer.h index e33efb1ea..dcbe11340 100644 --- a/dev/column_pointer.h +++ b/dev/column_pointer.h @@ -81,7 +81,7 @@ namespace sqlite_orm { * Make a table reference. */ template - requires(!orm_recordset_alias) + requires (!orm_recordset_alias) consteval internal::table_reference column() { return {}; } @@ -90,7 +90,7 @@ namespace sqlite_orm { * Make a table reference. */ template - requires(!orm_recordset_alias) + requires (!orm_recordset_alias) consteval internal::table_reference c() { return {}; } @@ -115,10 +115,10 @@ namespace sqlite_orm { static_assert(is_cte_moniker_v, "`Moniker' must be a CTE moniker"); - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { static_assert(is_column_alias_v>); return column_pointer{{}}; - } else if constexpr(is_column_alias_v) { + } else if constexpr (is_column_alias_v) { return column_pointer>{{}}; } else { return column_pointer{std::move(field)}; diff --git a/dev/connection_holder.h b/dev/connection_holder.h index 77d277fbc..11e6dd0a7 100644 --- a/dev/connection_holder.h +++ b/dev/connection_holder.h @@ -15,18 +15,18 @@ namespace sqlite_orm { connection_holder(std::string filename_) : filename(std::move(filename_)) {} void retain() { - if(1 == ++this->_retain_count) { + if (1 == ++this->_retain_count) { auto rc = sqlite3_open(this->filename.c_str(), &this->db); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } } void release() { - if(0 == --this->_retain_count) { + if (0 == --this->_retain_count) { auto rc = sqlite3_close(this->db); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -58,7 +58,7 @@ namespace sqlite_orm { // rebind connection reference connection_ref& operator=(const connection_ref& other) { - if(other.holder != this->holder) { + if (other.holder != this->holder) { this->holder->release(); this->holder = other.holder; this->holder->retain(); diff --git a/dev/constraints.h b/dev/constraints.h index e9cf651ca..7eb4a1cda 100644 --- a/dev/constraints.h +++ b/dev/constraints.h @@ -204,7 +204,7 @@ namespace sqlite_orm { }; inline std::ostream& operator<<(std::ostream& os, foreign_key_action action) { - switch(action) { + switch (action) { case foreign_key_action::no_action: os << "NO ACTION"; break; @@ -230,7 +230,7 @@ namespace sqlite_orm { const bool update; // true if update and false if delete operator std::string() const { - if(this->update) { + if (this->update) { return "ON UPDATE"; } else { return "ON DELETE"; @@ -254,7 +254,7 @@ namespace sqlite_orm { foreign_key_type no_action() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::no_action; } else { res.on_delete._action = foreign_key_action::no_action; @@ -264,7 +264,7 @@ namespace sqlite_orm { foreign_key_type restrict_() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::restrict_; } else { res.on_delete._action = foreign_key_action::restrict_; @@ -274,7 +274,7 @@ namespace sqlite_orm { foreign_key_type set_null() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::set_null; } else { res.on_delete._action = foreign_key_action::set_null; @@ -284,7 +284,7 @@ namespace sqlite_orm { foreign_key_type set_default() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::set_default; } else { res.on_delete._action = foreign_key_action::set_default; @@ -294,7 +294,7 @@ namespace sqlite_orm { foreign_key_type cascade() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::cascade; } else { res.on_delete._action = foreign_key_action::cascade; @@ -395,7 +395,7 @@ namespace sqlite_orm { } static std::string string_from_collate_argument(collate_argument argument) { - switch(argument) { + switch (argument) { case collate_argument::binary: return "BINARY"; case collate_argument::nocase: diff --git a/dev/core_functions.h b/dev/core_functions.h index 918135ca6..eeefd42b5 100644 --- a/dev/core_functions.h +++ b/dev/core_functions.h @@ -1710,7 +1710,7 @@ namespace sqlite_orm { internal::field_type_or_type_t>>, bool> = true> auto nullif(X x, Y y) { - if constexpr(std::is_void_v) { + if constexpr (std::is_void_v) { using F = internal::built_in_function_t< std::optional, internal::field_type_or_type_t>>, internal::nullif_string, diff --git a/dev/cte_column_names_collector.h b/dev/cte_column_names_collector.h index a8904275c..c03e2a9fa 100644 --- a/dev/cte_column_names_collector.h +++ b/dev/cte_column_names_collector.h @@ -23,12 +23,12 @@ namespace sqlite_orm { auto serialize(const T& t, const C& context); inline void unquote_identifier(std::string& identifier) { - if(!identifier.empty()) { + if (!identifier.empty()) { constexpr char quoteChar = '"'; constexpr char sqlEscaped[] = {quoteChar, quoteChar}; identifier.erase(identifier.end() - 1); identifier.erase(identifier.begin()); - for(size_t pos = 0; (pos = identifier.find(sqlEscaped, pos, 2)) != identifier.npos; ++pos) { + for (size_t pos = 0; (pos = identifier.find(sqlEscaped, pos, 2)) != identifier.npos; ++pos) { identifier.erase(pos, 1); } } @@ -36,7 +36,7 @@ namespace sqlite_orm { inline void unquote_or_erase(std::string& name) { constexpr char quoteChar = '"'; - if(name.front() == quoteChar) { + if (name.front() == quoteChar) { unquote_identifier(name); } else { // unaliased expression - see 3. below @@ -56,7 +56,7 @@ namespace sqlite_orm { auto newContext = context; newContext.skip_table_name = true; std::string columnName = serialize(t, newContext); - if(columnName.empty()) { + if (columnName.empty()) { throw std::system_error{orm_error_code::column_not_found}; } unquote_or_erase(columnName); @@ -134,11 +134,11 @@ namespace sqlite_orm { iterate_tuple(cols.columns, [&columnNames, &newContext](auto& m) { using value_type = polyfill::remove_cvref_t; - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { columnNames.push_back(alias_extractor>::extract()); } else { std::string columnName = serialize(m, newContext); - if(!columnName.empty()) { + if (!columnName.empty()) { columnNames.push_back(std::move(columnName)); } else { throw std::system_error{orm_error_code::column_not_found}; @@ -157,8 +157,8 @@ namespace sqlite_orm { std::vector columnNames = get_cte_column_names(sel.col, context); // 2. override column names from cte expression - if(size_t n = std::tuple_size_v) { - if(n != columnNames.size()) { + if (size_t n = std::tuple_size_v) { + if (n != columnNames.size()) { throw std::system_error{orm_error_code::column_not_found}; } @@ -166,24 +166,24 @@ namespace sqlite_orm { iterate_tuple(explicitColRefs, [&idx, &columnNames, &context](auto& colRef) { using ColRef = polyfill::remove_cvref_t; - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { columnNames[idx] = alias_extractor>::extract(); - } else if constexpr(std::is_member_pointer::value) { + } else if constexpr (std::is_member_pointer::value) { using O = table_type_of_t; - if(auto* columnName = find_column_name(context.db_objects, colRef)) { + if (auto* columnName = find_column_name(context.db_objects, colRef)) { columnNames[idx] = *columnName; } else { // relaxed: allow any member pointer as column reference columnNames[idx] = typeid(ColRef).name(); } - } else if constexpr(polyfill::is_specialization_of_v) { + } else if constexpr (polyfill::is_specialization_of_v) { columnNames[idx] = colRef.name; - } else if constexpr(std::is_same_v) { - if(!colRef.empty()) { + } else if constexpr (std::is_same_v) { + if (!colRef.empty()) { columnNames[idx] = colRef; } - } else if constexpr(std::is_same_v>) { - if(columnNames[idx].empty()) { + } else if constexpr (std::is_same_v>) { + if (columnNames[idx].empty()) { columnNames[idx] = std::to_string(idx + 1); } } else { @@ -195,8 +195,8 @@ namespace sqlite_orm { // 3. fill in blanks with numerical column identifiers { - for(size_t i = 0, n = columnNames.size(); i < n; ++i) { - if(columnNames[i].empty()) { + for (size_t i = 0, n = columnNames.size(); i < n; ++i) { + if (columnNames[i].empty()) { columnNames[i] = std::to_string(i + 1); } } diff --git a/dev/cte_moniker.h b/dev/cte_moniker.h index 03e7dcc8e..1f104a01b 100644 --- a/dev/cte_moniker.h +++ b/dev/cte_moniker.h @@ -46,10 +46,10 @@ namespace sqlite_orm { */ #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires((is_column_alias_v || std::is_member_pointer_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((is_column_alias_v || std::is_member_pointer_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto operator()(ExplicitCols... explicitColumns) const; #else template) { + if constexpr (polyfill::is_specialization_of_v) { return explicitColRef; - } else if constexpr(std::is_member_pointer::value) { + } else if constexpr (std::is_member_pointer::value) { return explicitColRef; - } else if constexpr(std::is_base_of_v) { + } else if constexpr (std::is_base_of_v) { return explicitColRef.member_pointer; - } else if constexpr(std::is_same_v) { + } else if constexpr (std::is_same_v) { return subselectColRef; - } else if constexpr(std::is_same_v>) { + } else if constexpr (std::is_same_v>) { return subselectColRef; } else { static_assert(polyfill::always_false_v, "Invalid explicit column reference specified"); @@ -235,7 +235,7 @@ namespace sqlite_orm { const SubselectColRefs& subselectColRefs, [[maybe_unused]] const ExplicitColRefs& explicitColRefs, std::index_sequence) { - if constexpr(std::tuple_size_v != 0) { + if constexpr (std::tuple_size_v != 0) { static_assert( (!is_builtin_numeric_column_alias_v< alias_holder_type_or_none_t>> && @@ -302,7 +302,7 @@ namespace sqlite_orm { std::index_sequence) { auto tbl = make_cte_table(dbObjects, get(cte)); - if constexpr(sizeof...(In) > 0) { + if constexpr (sizeof...(In) > 0) { return make_recursive_cte_db_objects( // Because CTEs can depend on their predecessor we recursively pass in a new set of DBOs db_objects_cat(dbObjects, std::move(tbl)), diff --git a/dev/error_code.h b/dev/error_code.h index 58568621d..a76fd9264 100644 --- a/dev/error_code.h +++ b/dev/error_code.h @@ -59,7 +59,7 @@ namespace sqlite_orm { } std::string message(int c) const override final { - switch(static_cast(c)) { + switch (static_cast(c)) { case orm_error_code::not_found: return "Not found"; case orm_error_code::type_is_not_mapped_to_storage: diff --git a/dev/field_printer.h b/dev/field_printer.h index 5cab14456..f9971c62d 100644 --- a/dev/field_printer.h +++ b/dev/field_printer.h @@ -99,7 +99,7 @@ namespace sqlite_orm { std::string operator()(const std::vector& t) const { std::stringstream ss; ss << std::hex; - for(auto c: t) { + for (auto c: t) { ss << c; } return ss.str(); @@ -139,7 +139,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; std::string operator()(const T& t) const { - if(t) { + if (t) { return field_printer()(*t); } else { return field_printer{}(nullptr); @@ -156,7 +156,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; std::string operator()(const T& t) const { - if(t.has_value()) { + if (t.has_value()) { return field_printer()(*t); } else { return field_printer{}(std::nullopt); diff --git a/dev/function.h b/dev/function.h index a0b4a29db..cffff9732 100644 --- a/dev/function.h +++ b/dev/function.h @@ -146,7 +146,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires(std::is_function_v) + requires (std::is_function_v) struct callable_arguments_impl { using args_tuple = function_arguments; using return_type = std::decay_t>; @@ -177,7 +177,7 @@ namespace sqlite_orm { * Bundle of type and name of a traditional sqlite_orm user-defined function. */ template - requires(requires { UDF::name(); }) + requires (requires { UDF::name(); }) struct udf_holder #else /* @@ -404,7 +404,7 @@ namespace sqlite_orm { * Return original `udf` if stateless or a copy of it otherwise */ constexpr decltype(auto) callable() const { - if constexpr(stateless) { + if constexpr (stateless) { return (this->udf); } else { // non-const copy @@ -446,7 +446,7 @@ namespace sqlite_orm { * From a classic function object instance. */ template - requires(orm_classic_function_object && (stateless || std::copy_constructible)) + requires (orm_classic_function_object && (stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(F callable) const { using Sig = function_signature_type_t; // detect whether overloaded call operator can be picked using `Sig` @@ -458,7 +458,7 @@ namespace sqlite_orm { * From a function object instance, picking the overloaded call operator. */ template - requires((stateless || std::copy_constructible)) + requires ((stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(F callable) const { // detect whether overloaded call operator can be picked using `Sig` using call_operator_type = decltype(static_cast(&F::operator())); @@ -469,7 +469,7 @@ namespace sqlite_orm { * From a classic function object type. */ template - requires(stateless || std::copy_constructible) + requires (stateless || std::copy_constructible) [[nodiscard]] consteval auto quote(Args&&... constructorArgs) const { using Sig = function_signature_type_t; return quoted_scalar_function{this->cstr, std::forward(constructorArgs)...}; @@ -479,7 +479,7 @@ namespace sqlite_orm { * From a function object type, picking the overloaded call operator. */ template - requires((stateless || std::copy_constructible)) + requires ((stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(Args&&... constructorArgs) const { // detect whether overloaded call operator can be picked using `Sig` using call_operator_type = decltype(static_cast(&F::operator())); @@ -505,7 +505,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_WITH_CPP20_ALIASES - requires(orm_scalar_udf || orm_aggregate_udf) + requires (orm_scalar_udf || orm_aggregate_udf) #endif SQLITE_ORM_INLINE_VAR constexpr internal::function func{}; diff --git a/dev/functional/mpl.h b/dev/functional/mpl.h index 6da008aa0..4c02b1244 100644 --- a/dev/functional/mpl.h +++ b/dev/functional/mpl.h @@ -337,7 +337,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED constexpr size_t find_first_true_helper(std::initializer_list values) { size_t i = 0; - for(auto first = values.begin(); first != values.end() && !*first; ++first) { + for (auto first = values.begin(); first != values.end() && !*first; ++first) { ++i; } return i; @@ -345,7 +345,7 @@ namespace sqlite_orm { constexpr size_t count_true_helper(std::initializer_list values) { size_t n = 0; - for(auto first = values.begin(); first != values.end(); ++first) { + for (auto first = values.begin(); first != values.end(); ++first) { n += *first; } return n; diff --git a/dev/functional/static_magic.h b/dev/functional/static_magic.h index c736d4769..a033067a0 100644 --- a/dev/functional/static_magic.h +++ b/dev/functional/static_magic.h @@ -26,7 +26,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED template decltype(auto) static_if([[maybe_unused]] T&& trueFn, [[maybe_unused]] F&& falseFn) { - if constexpr(B) { + if constexpr (B) { return std::forward(trueFn); } else { return std::forward(falseFn); @@ -35,7 +35,7 @@ namespace sqlite_orm { template decltype(auto) static_if([[maybe_unused]] T&& trueFn) { - if constexpr(B) { + if constexpr (B) { return std::forward(trueFn); } else { return empty_callable<>; @@ -44,7 +44,7 @@ namespace sqlite_orm { template void call_if_constexpr([[maybe_unused]] L&& lambda, [[maybe_unused]] Args&&... args) { - if constexpr(B) { + if constexpr (B) { lambda(std::forward(args)...); } } diff --git a/dev/get_prepared_statement.h b/dev/get_prepared_statement.h index 2f7d0a246..73f0adf37 100644 --- a/dev/get_prepared_statement.h +++ b/dev/get_prepared_statement.h @@ -133,10 +133,10 @@ namespace sqlite_orm { const result_type* result = nullptr; internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable { using node_type = polyfill::remove_cvref_t; - if(internal::is_bindable::value) { + if (internal::is_bindable::value) { ++index; } - if(index == N) { + if (index == N) { internal::call_if_constexpr::value>( [](auto& r, auto& n) { r = &n; @@ -159,10 +159,10 @@ namespace sqlite_orm { internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable { using node_type = polyfill::remove_cvref_t; - if(internal::is_bindable::value) { + if (internal::is_bindable::value) { ++index; } - if(index == N) { + if (index == N) { internal::call_if_constexpr::value>( [](auto& r, auto& n) { r = const_cast>(&n); diff --git a/dev/implementations/storage_definitions.h b/dev/implementations/storage_definitions.h index 80d777a21..cdb820b59 100644 --- a/dev/implementations/storage_definitions.h +++ b/dev/implementations/storage_definitions.h @@ -24,11 +24,11 @@ namespace sqlite_orm { template template> sync_schema_result storage_t::sync_table(const Table& table, sqlite3* db, bool preserve) { - if(std::is_same, sqlite_master>::value) { + if (std::is_same, sqlite_master>::value) { return sync_schema_result::already_in_sync; } #ifdef SQLITE_ENABLE_DBSTAT_VTAB - if(std::is_same, dbstat>::value) { + if (std::is_same, dbstat>::value) { return sync_schema_result::already_in_sync; } #endif // SQLITE_ENABLE_DBSTAT_VTAB @@ -36,14 +36,14 @@ namespace sqlite_orm { bool attempt_to_preserve = true; auto schema_stat = this->schema_status(table, db, preserve, &attempt_to_preserve); - if(schema_stat != sync_schema_result::already_in_sync) { - if(schema_stat == sync_schema_result::new_table_created) { + if (schema_stat != sync_schema_result::already_in_sync) { + if (schema_stat == sync_schema_result::new_table_created) { this->create_table(db, table.name, table); res = sync_schema_result::new_table_created; } else { - if(schema_stat == sync_schema_result::old_columns_removed || - schema_stat == sync_schema_result::new_columns_added || - schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { + if (schema_stat == sync_schema_result::old_columns_removed || + schema_stat == sync_schema_result::new_columns_added || + schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { // get table info provided in `make_table` call.. auto storageTableInfo = table.get_table_info(); @@ -56,9 +56,9 @@ namespace sqlite_orm { this->calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo); - if(schema_stat == sync_schema_result::old_columns_removed) { + if (schema_stat == sync_schema_result::old_columns_removed) { #if SQLITE_VERSION_NUMBER >= 3035000 // DROP COLUMN feature exists (v3.35.0) - for(auto& tableInfo: dbTableInfo) { + for (auto& tableInfo: dbTableInfo) { this->drop_column(db, table.name, tableInfo.name); } res = sync_schema_result::old_columns_removed; @@ -69,10 +69,10 @@ namespace sqlite_orm { #endif } - if(schema_stat == sync_schema_result::new_columns_added) { - for(const table_xinfo* colInfo: columnsToAdd) { + if (schema_stat == sync_schema_result::new_columns_added) { + for (const table_xinfo* colInfo: columnsToAdd) { table.for_each_column([this, colInfo, &tableName = table.name, db](auto& column) { - if(column.name != colInfo->name) { + if (column.name != colInfo->name) { return; } this->add_column(db, tableName, column); @@ -81,7 +81,7 @@ namespace sqlite_orm { res = sync_schema_result::new_columns_added; } - if(schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { + if (schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { auto storageTableInfo = table.get_table_info(); this->add_generated_cols(columnsToAdd, storageTableInfo); @@ -90,7 +90,7 @@ namespace sqlite_orm { this->backup_table(db, table, columnsToAdd); res = sync_schema_result::new_columns_added_and_old_columns_removed; } - } else if(schema_stat == sync_schema_result::dropped_and_recreated) { + } else if (schema_stat == sync_schema_result::dropped_and_recreated) { // now get current table info from db using `PRAGMA table_xinfo` query.. auto dbTableInfo = this->pragma.table_xinfo(table.name); // should include generated columns auto storageTableInfo = table.get_table_info(); @@ -102,7 +102,7 @@ namespace sqlite_orm { this->add_generated_cols(columnsToAdd, storageTableInfo); - if(preserve && attempt_to_preserve) { + if (preserve && attempt_to_preserve) { this->backup_table(db, table, columnsToAdd); } else { this->drop_create_with_loss(db, table); @@ -135,7 +135,7 @@ namespace sqlite_orm { return columnName == tableInfo->name; }); #endif - if(columnToIgnoreIt == columnsToIgnore.end()) { + if (columnToIgnoreIt == columnsToIgnore.end()) { columnNames.push_back(cref(columnName)); } }); diff --git a/dev/implementations/table_definitions.h b/dev/implementations/table_definitions.h index 91ae4ba4e..c474df26c 100644 --- a/dev/implementations/table_definitions.h +++ b/dev/implementations/table_definitions.h @@ -24,7 +24,7 @@ namespace sqlite_orm { this->for_each_column([&res](auto& column) { using field_type = field_type_t>; std::string dft; - if(auto d = column.default_value()) { + if (auto d = column.default_value()) { dft = std::move(*d); } using constraints_tuple = decltype(column.constraints); @@ -43,7 +43,7 @@ namespace sqlite_orm { column.template is()); }); auto compositeKeyColumnNames = this->composite_key_columns_names(); - for(size_t i = 0; i < compositeKeyColumnNames.size(); ++i) { + for (size_t i = 0; i < compositeKeyColumnNames.size(); ++i) { const std::string& columnName = compositeKeyColumnNames[i]; #if __cpp_lib_ranges >= 201911L auto it = std::ranges::find(res, columnName, &table_xinfo::name); @@ -52,7 +52,7 @@ namespace sqlite_orm { return ti.name == columnName; }); #endif - if(it != res.end()) { + if (it != res.end()) { it->pk = static_cast(i + 1); } } diff --git a/dev/journal_mode.h b/dev/journal_mode.h index fb3727397..1c8c21424 100644 --- a/dev/journal_mode.h +++ b/dev/journal_mode.h @@ -63,16 +63,16 @@ namespace sqlite_orm { std::ranges::transform(string, string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - if(auto found = std::ranges::find(journalModes, string, journal_mode_to_string); - found != journalModes.end()) SQLITE_ORM_CPP_LIKELY { + if (auto found = std::ranges::find(journalModes, string, journal_mode_to_string); + found != journalModes.end()) SQLITE_ORM_CPP_LIKELY { return {true, *found}; } #else std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - for(auto journalMode: journalModes) { - if(journal_mode_to_string(journalMode) == string) { + for (auto journalMode: journalModes) { + if (journal_mode_to_string(journalMode) == string) { return {true, journalMode}; } } diff --git a/dev/locking_mode.h b/dev/locking_mode.h index a45f8ec9b..55ba6ac1f 100644 --- a/dev/locking_mode.h +++ b/dev/locking_mode.h @@ -37,16 +37,16 @@ namespace sqlite_orm { std::ranges::transform(string, string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - if(auto found = std::ranges::find(lockingModes, string, locking_mode_to_string); - found != lockingModes.end()) SQLITE_ORM_CPP_LIKELY { + if (auto found = std::ranges::find(lockingModes, string, locking_mode_to_string); + found != lockingModes.end()) SQLITE_ORM_CPP_LIKELY { return {true, *found}; } #else std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - for(auto lockingMode: lockingModes) { - if(locking_mode_to_string(lockingMode) == string) { + for (auto lockingMode: lockingModes) { + if (locking_mode_to_string(lockingMode) == string) { return {true, lockingMode}; } } diff --git a/dev/mapped_iterator.h b/dev/mapped_iterator.h index 82a23ed3d..e35c0d6d1 100644 --- a/dev/mapped_iterator.h +++ b/dev/mapped_iterator.h @@ -58,7 +58,7 @@ namespace sqlite_orm { void step() { perform_step(this->stmt.get(), std::bind(&mapped_iterator::extract_object, this)); - if(!this->current) { + if (!this->current) { this->stmt.reset(); } } @@ -82,7 +82,7 @@ namespace sqlite_orm { mapped_iterator& operator=(mapped_iterator&&) = default; value_type& operator*() const { - if(!this->stmt) SQLITE_ORM_CPP_UNLIKELY { + if (!this->stmt) SQLITE_ORM_CPP_UNLIKELY { throw std::system_error{orm_error_code::trying_to_dereference_null_iterator}; } return *this->current; diff --git a/dev/order_by_serializer.h b/dev/order_by_serializer.h index f591cda0d..bc2d418ac 100644 --- a/dev/order_by_serializer.h +++ b/dev/order_by_serializer.h @@ -27,10 +27,10 @@ namespace sqlite_orm { newContext.skip_table_name = false; ss << serialize(orderBy.expression, newContext); - if(!orderBy._collate_argument.empty()) { + if (!orderBy._collate_argument.empty()) { ss << " COLLATE " << orderBy._collate_argument; } - switch(orderBy.asc_desc) { + switch (orderBy.asc_desc) { case 1: ss << " ASC"; break; @@ -51,16 +51,16 @@ namespace sqlite_orm { std::stringstream ss; ss << static_cast(orderBy) << " "; int index = 0; - for(const dynamic_order_by_entry_t& entry: orderBy) { - if(index > 0) { + for (const dynamic_order_by_entry_t& entry: orderBy) { + if (index > 0) { ss << ", "; } ss << entry.name; - if(!entry._collate_argument.empty()) { + if (!entry._collate_argument.empty()) { ss << " COLLATE " << entry._collate_argument; } - switch(entry.asc_desc) { + switch (entry.asc_desc) { case 1: ss << " ASC"; break; diff --git a/dev/pointer_value.h b/dev/pointer_value.h index 9b21294da..dd4a9b26f 100644 --- a/dev/pointer_value.h +++ b/dev/pointer_value.h @@ -136,8 +136,8 @@ namespace sqlite_orm { p_{std::exchange(other.p_, nullptr)}, d_{std::move(other.d_)} {} ~pointer_binding() { - if(p_) { - if(auto xDestroy = get_xdestroy()) { + if (p_) { + if (auto xDestroy = get_xdestroy()) { // note: C-casting `P* -> void*` like statement_binder> xDestroy((void*)p_); } diff --git a/dev/pragma.h b/dev/pragma.h index 7bc1db362..b0f35f8ab 100644 --- a/dev/pragma.h +++ b/dev/pragma.h @@ -32,7 +32,7 @@ namespace sqlite_orm { auto& res = *(std::vector*)data; res.reserve(argc); const auto rowExtractor = column_text_extractor(); - for(int i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { auto rowString = rowExtractor.extract(argv[i]); res.push_back(std::move(rowString)); } @@ -165,7 +165,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char**) -> int { auto& res = *(std::vector*)data; - if(argc) { + if (argc) { auto index = 0; auto cid = atoi(argv[index++]); std::string name = argv[index++]; @@ -202,7 +202,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char**) -> int { auto& res = *(std::vector*)data; - if(argc) { + if (argc) { auto index = 0; auto cid = atoi(argv[index++]); std::string name = argv[index++]; @@ -259,7 +259,7 @@ namespace sqlite_orm { void set_pragma_impl(const std::string& query, sqlite3* db = nullptr) { auto con = this->get_connection(); - if(db == nullptr) { + if (db == nullptr) { db = con.get(); } perform_void_exec(db, query); diff --git a/dev/prepared_statement.h b/dev/prepared_statement.h index 5b7ebb69f..e3dfdebd4 100644 --- a/dev/prepared_statement.h +++ b/dev/prepared_statement.h @@ -38,7 +38,7 @@ namespace sqlite_orm { std::string sql() const { // note: sqlite3 internally checks for null before calling // sqlite3_normalized_sql() or sqlite3_expanded_sql(), so check here, too, even if superfluous - if(const char* sql = sqlite3_sql(this->stmt)) { + if (const char* sql = sqlite3_sql(this->stmt)) { return sql; } else { return {}; @@ -49,7 +49,7 @@ namespace sqlite_orm { std::string expanded_sql() const { // note: must check return value due to SQLITE_OMIT_TRACE using char_ptr = std::unique_ptr>; - if(char_ptr sql{sqlite3_expanded_sql(this->stmt)}) { + if (char_ptr sql{sqlite3_expanded_sql(this->stmt)}) { return sql.get(); } else { return {}; @@ -58,7 +58,7 @@ namespace sqlite_orm { #endif #if SQLITE_VERSION_NUMBER >= 3026000 and defined(SQLITE_ENABLE_NORMALIZE) std::string normalized_sql() const { - if(const char* sql = sqlite3_normalized_sql(this->stmt)) { + if (const char* sql = sqlite3_normalized_sql(this->stmt)) { return sql; } else { return {}; diff --git a/dev/row_extractor.h b/dev/row_extractor.h index 21fcabf73..757344e1c 100644 --- a/dev/row_extractor.h +++ b/dev/row_extractor.h @@ -88,7 +88,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif row_extractor column_text_extractor() { return {}; @@ -99,7 +99,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif row_extractor row_value_extractor() { return {}; @@ -110,7 +110,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif row_extractor boxed_value_extractor() { return {}; @@ -120,7 +120,7 @@ namespace sqlite_orm { template int extract_single_value(void* data, int argc, char** argv, char**) { auto& res = *(R*)data; - if(argc) { + if (argc) { const auto rowExtractor = internal::column_text_extractor(); res = rowExtractor.extract(argv[0]); } @@ -217,7 +217,7 @@ namespace sqlite_orm { template struct row_extractor::value>> { T extract(const char* columnText) const { - if(columnText) { + if (columnText) { return columnText; } else { return {}; @@ -225,7 +225,7 @@ namespace sqlite_orm { } T extract(sqlite3_stmt* stmt, int columnIndex) const { - if(auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex)) { + if (auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex)) { return cStr; } else { return {}; @@ -233,7 +233,7 @@ namespace sqlite_orm { } T extract(sqlite3_value* value) const { - if(auto cStr = (const char*)sqlite3_value_text(value)) { + if (auto cStr = (const char*)sqlite3_value_text(value)) { return cStr; } else { return {}; @@ -247,7 +247,7 @@ namespace sqlite_orm { template<> struct row_extractor { std::wstring extract(const char* columnText) const { - if(columnText) { + if (columnText) { std::wstring_convert> converter; return converter.from_bytes(columnText); } else { @@ -257,7 +257,7 @@ namespace sqlite_orm { std::wstring extract(sqlite3_stmt* stmt, int columnIndex) const { auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex); - if(cStr) { + if (cStr) { std::wstring_convert> converter; return converter.from_bytes(cStr); } else { @@ -266,7 +266,7 @@ namespace sqlite_orm { } std::wstring extract(sqlite3_value* value) const { - if(auto cStr = (const wchar_t*)sqlite3_value_text16(value)) { + if (auto cStr = (const wchar_t*)sqlite3_value_text16(value)) { return cStr; } else { return {}; @@ -281,10 +281,10 @@ namespace sqlite_orm { V extract(const char* columnText) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif { - if(columnText) { + if (columnText) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(columnText)); } else { @@ -294,11 +294,11 @@ namespace sqlite_orm { V extract(sqlite3_stmt* stmt, int columnIndex) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif { auto type = sqlite3_column_type(stmt, columnIndex); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(stmt, columnIndex)); } else { @@ -308,11 +308,11 @@ namespace sqlite_orm { V extract(sqlite3_value* value) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif { auto type = sqlite3_value_type(value); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(value)); } else { @@ -328,10 +328,10 @@ namespace sqlite_orm { V extract(const char* columnText) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif { - if(columnText) { + if (columnText) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(columnText)); } else { @@ -341,11 +341,11 @@ namespace sqlite_orm { V extract(sqlite3_stmt* stmt, int columnIndex) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif { auto type = sqlite3_column_type(stmt, columnIndex); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(stmt, columnIndex)); } else { @@ -355,11 +355,11 @@ namespace sqlite_orm { V extract(sqlite3_value* value) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif { auto type = sqlite3_value_type(value); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(value)); } else { @@ -411,9 +411,9 @@ namespace sqlite_orm { template<> struct row_extractor { locking_mode extract(const char* columnText) const { - if(columnText) { + if (columnText) { auto resultPair = internal::locking_mode_from_string(columnText); - if(resultPair.first) { + if (resultPair.first) { return resultPair.second; } else { throw std::system_error{orm_error_code::incorrect_locking_mode_string}; @@ -437,9 +437,9 @@ namespace sqlite_orm { template<> struct row_extractor { journal_mode extract(const char* columnText) const { - if(columnText) { + if (columnText) { auto resultPair = internal::journal_mode_from_string(columnText); - if(resultPair.first) { + if (resultPair.first) { return resultPair.second; } else { throw std::system_error{orm_error_code::incorrect_journal_mode_string}; @@ -472,8 +472,8 @@ namespace sqlite_orm { */ template auto make_row_extractor([[maybe_unused]] const DBOs& dbObjects) { - if constexpr(polyfill::is_specialization_of_v || - polyfill::is_specialization_of_v || is_table_reference_v) { + if constexpr (polyfill::is_specialization_of_v || + polyfill::is_specialization_of_v || is_table_reference_v) { return struct_extractor{dbObjects}; } else { return row_value_extractor(); diff --git a/dev/schema/table.h b/dev/schema/table.h index f344417fb..5e4ca9bf7 100644 --- a/dev/schema/table.h +++ b/dev/schema/table.h @@ -141,7 +141,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with_field_type{}, call_as_template_base([&res, &memberPointer, &object](const auto& column) { - if(compare_any(column.setter, memberPointer)) { + if (compare_any(column.setter, memberPointer)) { res = &polyfill::invoke(column.member_pointer, object); } })); @@ -155,7 +155,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with{}, [&result, &name](auto& column) { - if(column.name != name) { + if (column.name != name) { return; } using generated_op_index_sequence = @@ -190,7 +190,7 @@ namespace sqlite_orm { std::vector primary_key_column_names() const { using pkcol_index_sequence = col_index_sequence_with; - if(pkcol_index_sequence::size() > 0) { + if (pkcol_index_sequence::size() > 0) { return create_from_tuple>(this->elements, pkcol_index_sequence{}, &column_identifier::name); @@ -215,8 +215,8 @@ namespace sqlite_orm { std::vector composite_key_columns_names(const primary_key_t& primaryKey) const { return create_from_tuple>(primaryKey.columns, [this, empty = std::string{}](auto& memberPointer) { - if(const std::string* columnName = - this->find_column_name(memberPointer)) { + if (const std::string* columnName = + this->find_column_name(memberPointer)) { return *columnName; } else { return empty; @@ -235,7 +235,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with_field_type{}, [&res, m](auto& c) { - if(compare_any(c.member_pointer, m) || compare_any(c.setter, m)) { + if (compare_any(c.member_pointer, m) || compare_any(c.setter, m)) { res = &c.name; } }); @@ -400,7 +400,8 @@ namespace sqlite_orm { check_if_is_type>::template fn, member_field_type_t>; iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) { - if(compare_any(memberPointer, column.member_pointer) || compare_any(memberPointer, column.setter)) { + if (compare_any(memberPointer, column.member_pointer) || + compare_any(memberPointer, column.setter)) { res = true; } }); diff --git a/dev/select_constraints.h b/dev/select_constraints.h index 8c2d1c142..9bd7108aa 100644 --- a/dev/select_constraints.h +++ b/dev/select_constraints.h @@ -167,7 +167,7 @@ namespace sqlite_orm { #endif operator std::string() const { - if(!this->all) { + if (!this->all) { return "UNION"; } else { return "UNION ALL"; @@ -316,7 +316,7 @@ namespace sqlite_orm { with_t(bool recursiveIndicated, cte_type cte, expression_type expression) : recursiveIndicated{recursiveIndicated}, cte{std::move(cte)}, expression{std::move(expression)} { - if constexpr(is_select_v) { + if constexpr (is_select_v) { this->expression.highest_level = true; } } @@ -592,11 +592,11 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires((internal::is_column_alias_v || std::is_member_pointer_v || - internal::is_column_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((internal::is_column_alias_v || std::is_member_pointer_v || + internal::is_column_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto cte(ExplicitCols... explicitColumns) { using namespace ::sqlite_orm::internal; static_assert((!is_builtin_numeric_column_alias_v && ...), @@ -612,10 +612,10 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template template - requires((is_column_alias_v || std::is_member_pointer_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((is_column_alias_v || std::is_member_pointer_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto cte_moniker::operator()(ExplicitCols... explicitColumns) const { return cte>(std::forward(explicitColumns)...); } diff --git a/dev/serializing_util.h b/dev/serializing_util.h index eba2f42fb..f35fecd96 100644 --- a/dev/serializing_util.h +++ b/dev/serializing_util.h @@ -29,10 +29,10 @@ namespace sqlite_orm { std::string serialize_order_by(const T&, const Ctx&); inline void stream_sql_escaped(std::ostream& os, serialize_arg_type str, char char2Escape) { - for(size_t offset = 0, next; true; offset = next + 1) { + for (size_t offset = 0, next; true; offset = next + 1) { next = str.find(char2Escape, offset); - if(next == str.npos) SQLITE_ORM_CPP_LIKELY { + if (next == str.npos) SQLITE_ORM_CPP_LIKELY { os.write(str.data() + offset, str.size() - offset); break; } @@ -53,7 +53,7 @@ namespace sqlite_orm { // note: In practice, escaping double quotes in identifiers is arguably overkill, // but since the SQLite grammar allows it, it's better to be safe than sorry. - if(!qualifier.empty()) { + if (!qualifier.empty()) { ss << quoteChar; stream_sql_escaped(ss, qualifier, quoteChar); ss << qualified; @@ -63,7 +63,7 @@ namespace sqlite_orm { stream_sql_escaped(ss, identifier, quoteChar); ss << quoteChar; } - if(!alias.empty()) { + if (!alias.empty()) { ss << aliased; stream_sql_escaped(ss, alias, quoteChar); ss << quoteChar; @@ -190,7 +190,7 @@ namespace sqlite_orm { auto& context = std::get<3>(tpl); iterate_tuple(args, [&ss, &opString, &context, first = true](auto& arg) mutable { - if(!std::exchange(first, false)) { + if (!std::exchange(first, false)) { ss << ' ' << opString << ' '; } ss << serialize(arg, context); @@ -224,7 +224,7 @@ namespace sqlite_orm { static constexpr std::array sep = {", ", ""}; bool first = true; - for(auto& argument: args) { + for (auto& argument: args) { ss << sep[std::exchange(first, false)] << serialize(argument, context); } return ss; @@ -237,7 +237,7 @@ namespace sqlite_orm { const auto& strings = std::get<1>(tpl); static constexpr std::array sep = {", ", ""}; - for(size_t i = 0, first = true; i < strings.size(); ++i) { + for (size_t i = 0, first = true; i < strings.size(); ++i) { ss << sep[std::exchange(first, false)] << strings[i]; } return ss; @@ -267,7 +267,7 @@ namespace sqlite_orm { static constexpr std::array sep = {", ", ""}; bool first = true; - for(auto& identifier: identifiers) { + for (auto& identifier: identifiers) { ss << sep[std::exchange(first, false)]; stream_identifier(ss, identifier); } @@ -281,7 +281,7 @@ namespace sqlite_orm { const size_t& columnsCount = std::get<1>(tpl); const ptrdiff_t& valuesCount = std::get<2>(tpl); - if(!valuesCount || !columnsCount) { + if (!valuesCount || !columnsCount) { return ss; } @@ -289,10 +289,10 @@ namespace sqlite_orm { result.reserve((1 + (columnsCount * 1) + (columnsCount * 2 - 2) + 1) * valuesCount + (valuesCount * 2 - 2)); static constexpr std::array sep = {", ", ""}; - for(ptrdiff_t i = 0, first = true; i < valuesCount; ++i) { + for (ptrdiff_t i = 0, first = true; i < valuesCount; ++i) { result += sep[std::exchange(first, false)]; result += "("; - for(size_t i = 0, first = true; i < columnsCount; ++i) { + for (size_t i = 0, first = true; i < columnsCount; ++i) { result += sep[std::exchange(first, false)]; result += "?"; } @@ -350,7 +350,7 @@ namespace sqlite_orm { table.template for_each_column_excluding(call_as_template_base( [&ss, &excluded, &context, &object, first = true](auto& column) mutable { - if(excluded(column)) { + if (excluded(column)) { return; } @@ -371,7 +371,7 @@ namespace sqlite_orm { iterate_tuple(columns, [&ss, &context, first = true](auto& colRef) mutable { const std::string* columnName = find_column_name(context.db_objects, colRef); - if(!columnName) { + if (!columnName) { throw std::system_error{orm_error_code::column_not_found}; } @@ -413,12 +413,12 @@ namespace sqlite_orm { ss << ' ' << serialize(constraint, context); }); // add implicit null constraint - if(!context.fts5_columns) { + if (!context.fts5_columns) { constexpr bool hasExplicitNullableConstraint = mpl::invoke_t, check_if_has_type>, constraints_tuple>::value; - if SQLITE_ORM_CONSTEXPR_IF(!hasExplicitNullableConstraint) { - if(isNotNull) { + if SQLITE_ORM_CONSTEXPR_IF (!hasExplicitNullableConstraint) { + if (isNotNull) { ss << " NOT NULL"; } else { ss << " NULL"; diff --git a/dev/statement_binder.h b/dev/statement_binder.h index a3a979c47..a96f60f22 100644 --- a/dev/statement_binder.h +++ b/dev/statement_binder.h @@ -237,7 +237,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; int bind(sqlite3_stmt* stmt, int index, const V& value) const { - if(value) { + if (value) { return statement_binder().bind(stmt, index, *value); } else { return statement_binder().bind(stmt, index, nullptr); @@ -251,7 +251,7 @@ namespace sqlite_orm { template<> struct statement_binder, void> { int bind(sqlite3_stmt* stmt, int index, const std::vector& value) const { - if(!value.empty()) { + if (!value.empty()) { return sqlite3_bind_blob(stmt, index, (const void*)&value.front(), int(value.size()), SQLITE_TRANSIENT); } else { return sqlite3_bind_blob(stmt, index, "", 0, SQLITE_TRANSIENT); @@ -259,7 +259,7 @@ namespace sqlite_orm { } void result(sqlite3_context* context, const std::vector& value) const { - if(!value.empty()) { + if (!value.empty()) { sqlite3_result_blob(context, (const void*)&value.front(), int(value.size()), nullptr); } else { sqlite3_result_blob(context, "", 0, nullptr); @@ -275,7 +275,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; int bind(sqlite3_stmt* stmt, int index, const V& value) const { - if(value) { + if (value) { return statement_binder().bind(stmt, index, *value); } else { return statement_binder().bind(stmt, index, std::nullopt); @@ -295,7 +295,7 @@ namespace sqlite_orm { template = true> void operator()(const T& t) { int rc = statement_binder{}.bind(this->stmt, this->index++, t); - if(SQLITE_OK != rc) { + if (SQLITE_OK != rc) { throw_translated_sqlite_error(this->stmt); } } @@ -313,7 +313,7 @@ namespace sqlite_orm { template void operator()(const T* value) { - if(!value) { + if (!value) { throw std::system_error{orm_error_code::value_is_null}; } (*this)(*value); @@ -349,14 +349,14 @@ namespace sqlite_orm { template void bind(const T& t, size_t idx) const { int rc = statement_binder{}.bind(this->stmt, int(idx + 1), t); - if(SQLITE_OK != rc) { + if (SQLITE_OK != rc) { throw_translated_sqlite_error(this->stmt); } } template void bind(const T* value, size_t idx) const { - if(!value) { + if (!value) { throw std::system_error{orm_error_code::value_is_null}; } (*this)(*value, idx); diff --git a/dev/statement_serializer.h b/dev/statement_serializer.h index 1946f76d8..869a5c250 100644 --- a/dev/statement_serializer.h +++ b/dev/statement_serializer.h @@ -75,7 +75,7 @@ namespace sqlite_orm { template std::string operator()(const T& statement, const Ctx& context) const { - if(context.replace_bindable_with_question) { + if (context.replace_bindable_with_question) { return "?"; } else { return this->do_serialize(statement); @@ -157,7 +157,7 @@ namespace sqlite_orm { std::stringstream ss; ss << "CREATE TABLE " << streaming_identifier(tableName) << " (" << streaming_expressions_tuple(statement.elements, context) << ")"; - if(statement_type::is_without_rowid_v) { + if (statement_type::is_without_rowid_v) { ss << " WITHOUT ROWID"; } return ss.str(); @@ -249,7 +249,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "excluded."; - if(auto* columnName = find_column_name(context.db_objects, statement.expression)) { + if (auto* columnName = find_column_name(context.db_objects, statement.expression)) { ss << streaming_identifier(*columnName); } else { throw std::system_error{orm_error_code::column_not_found}; @@ -327,16 +327,16 @@ namespace sqlite_orm { using value_type = polyfill::remove_cvref_t; auto needParenthesis = std::is_member_pointer::value; ss << ' '; - if(needParenthesis) { + if (needParenthesis) { ss << '('; } ss << serialize(value, context); - if(needParenthesis) { + if (needParenthesis) { ss << ')'; } }); ss << ' ' << "DO"; - if(std::tuple_size::value == 0) { + if (std::tuple_size::value == 0) { ss << " NOTHING"; } else { auto updateContext = context; @@ -395,7 +395,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& c, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(alias_extractor::extract()) << "."; } auto newContext = context; @@ -414,7 +414,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& e, const Ctx& context) const { std::stringstream ss; - if(auto* columnName = find_column_name(context.db_objects, e)) { + if (auto* columnName = find_column_name(context.db_objects, e)) { ss << streaming_identifier( !context.skip_table_name ? lookup_table_name>(context.db_objects) : "", *columnName, @@ -473,7 +473,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -488,7 +488,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -503,7 +503,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -649,7 +649,7 @@ namespace sqlite_orm { std::stringstream ss; ss << "WITH"; - if(c.recursiveIndicated) { + if (c.recursiveIndicated) { ss << " RECURSIVE"; } ss << " " << serialize(c.cte, tupleContext); @@ -736,11 +736,11 @@ namespace sqlite_orm { std::stringstream ss; ss << expression.serialize(); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << "("; } ss << serialize(get_from_expression(expression.argument), subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << ")"; } return ss.str(); @@ -762,11 +762,11 @@ namespace sqlite_orm { std::stringstream ss; ss << static_cast(expression) << " "; - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << "("; } ss << serialize(get_from_expression(expression.c), subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << ")"; } return ss.str(); @@ -791,19 +791,19 @@ namespace sqlite_orm { is_binary_operator>::value; std::stringstream ss; - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeLeft) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeLeft) { ss << "("; } ss << serialize(statement.lhs, subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeLeft) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeLeft) { ss << ")"; } ss << " " << statement.serialize() << " "; - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeRight) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeRight) { ss << "("; } ss << serialize(statement.rhs, subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeRight) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeRight) { ss << ")"; } return ss.str(); @@ -848,19 +848,19 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; } ss << " "; - if(is_compound_operator::value) { + if (is_compound_operator::value) { ss << '('; } auto newContext = context; newContext.use_parentheses = true; ss << serialize(statement.argument, newContext); - if(is_compound_operator::value) { + if (is_compound_operator::value) { ss << ')'; } return ss.str(); @@ -879,7 +879,7 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; @@ -898,7 +898,7 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; @@ -907,11 +907,11 @@ namespace sqlite_orm { using args_type = std::tuple; constexpr bool theOnlySelect = std::tuple_size::value == 1 && is_select>::value; - if(!theOnlySelect) { + if (!theOnlySelect) { ss << "("; } ss << streaming_expressions_tuple(statement.argument, context); - if(!theOnlySelect) { + if (!theOnlySelect) { ss << ")"; } return ss.str(); @@ -985,7 +985,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case conflict_clause_t::rollback: return "ROLLBACK"; case conflict_clause_t::abort: @@ -1039,7 +1039,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "PRIMARY KEY"; - switch(statement.options.asc_option) { + switch (statement.options.asc_option) { case statement_type::order_by::ascending: ss << " ASC"; break; @@ -1049,12 +1049,12 @@ namespace sqlite_orm { default: break; } - if(statement.options.conflict_clause_is_on) { + if (statement.options.conflict_clause_is_on) { ss << " ON CONFLICT " << serialize(statement.options.conflict_clause, context); } using columns_tuple = typename statement_type::columns_tuple; const size_t columnsCount = std::tuple_size::value; - if(columnsCount) { + if (columnsCount) { ss << "(" << streaming_mapped_columns_expressions(statement.columns, context) << ")"; } return ss.str(); @@ -1071,7 +1071,7 @@ namespace sqlite_orm { ss << static_cast(c); using columns_tuple = typename statement_type::columns_tuple; const size_t columnsCount = std::tuple_size::value; - if(columnsCount) { + if (columnsCount) { ss << "(" << streaming_mapped_columns_expressions(c.columns, context) << ")"; } return ss.str(); @@ -1179,10 +1179,10 @@ namespace sqlite_orm { ss << streaming_identifier(refTableName); } ss << "(" << streaming_mapped_columns_expressions(fk.references, context) << ")"; - if(fk.on_update) { + if (fk.on_update) { ss << ' ' << static_cast(fk.on_update) << " " << fk.on_update._action; } - if(fk.on_delete) { + if (fk.on_delete) { ss << ' ' << static_cast(fk.on_delete) << " " << fk.on_delete._action; } return ss.str(); @@ -1209,12 +1209,12 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(statement.full) { + if (statement.full) { ss << "GENERATED ALWAYS "; } ss << "AS ("; ss << serialize(statement.expression, context) << ")"; - switch(statement.storage) { + switch (statement.storage) { case basic_generated_always::storage_type::not_specified: //.. break; @@ -1237,7 +1237,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& column, const Ctx& context) const { std::stringstream ss; ss << streaming_identifier(column.name); - if(!context.fts5_columns) { + if (!context.fts5_columns) { ss << " " << type_printer>>().print(); } ss << streaming_column_constraints( @@ -1326,7 +1326,7 @@ namespace sqlite_orm { ss << "UPDATE " << streaming_identifier(table.name) << " SET "; table.template for_each_column_excluding>( [&table, &ss, &context, &object = get_ref(statement.object), first = true](auto& column) mutable { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -1337,7 +1337,7 @@ namespace sqlite_orm { ss << " WHERE "; table.for_each_column( [&table, &context, &ss, &object = get_ref(statement.object), first = true](auto& column) mutable { - if(!column.template is() && !exists_in_composite_primary_key(table, column)) { + if (!column.template is() && !exists_in_composite_primary_key(table, column)) { return; } @@ -1358,8 +1358,8 @@ namespace sqlite_orm { std::stringstream ss; ss << "SET "; int index = 0; - for(const dynamic_set_entry& entry: statement) { - if(index > 0) { + for (const dynamic_set_entry& entry: statement) { + if (index > 0) { ss << ", "; } ss << entry.serialized_value; @@ -1418,7 +1418,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { const auto& tableNames = collect_table_names(statement.set, context); - if(tableNames.empty()) { + if (tableNames.empty()) { throw std::system_error{orm_error_code::no_tables_specified}; } const std::string& tableName = tableNames.begin()->first; @@ -1445,7 +1445,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( [&table, &columnNames](auto& column) { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -1455,13 +1455,13 @@ namespace sqlite_orm { std::stringstream ss; ss << "INSERT INTO " << streaming_identifier(table.name) << " "; - if(columnNamesCount) { + if (columnNamesCount) { ss << "(" << streaming_identifiers(columnNames) << ")"; } else { ss << "DEFAULT"; } ss << " VALUES"; - if(columnNamesCount) { + if (columnNamesCount) { ss << " (" << streaming_field_values_excluding( mpl::conjunction>, @@ -1503,11 +1503,11 @@ namespace sqlite_orm { subCtx.use_parentheses = true; std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << streaming_serialized(get_column_names(statement, subCtx)); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -1523,7 +1523,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(is_insert_raw::value) { + if (is_insert_raw::value) { ss << "INSERT"; } else { ss << "REPLACE"; @@ -1531,12 +1531,12 @@ namespace sqlite_orm { iterate_tuple(statement.args, [&context, &ss](auto& value) { using value_type = polyfill::remove_cvref_t; ss << ' '; - if(is_columns::value) { + if (is_columns::value) { auto newContext = context; newContext.skip_table_name = true; newContext.use_parentheses = true; ss << serialize(value, newContext); - } else if(is_values::value || is_select::value) { + } else if (is_values::value || is_select::value) { auto newContext = context; newContext.use_parentheses = false; ss << serialize(value, newContext); @@ -1565,7 +1565,7 @@ namespace sqlite_orm { }); table.for_each_primary_key_column([&table, &ss, &idsStrings, index = 0](auto& memberPointer) mutable { auto* columnName = table.find_column_name(memberPointer); - if(!columnName) { + if (!columnName) { throw std::system_error{orm_error_code::column_not_found}; } @@ -1611,7 +1611,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( [&table, &columnNames](auto& column) { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -1622,15 +1622,15 @@ namespace sqlite_orm { std::stringstream ss; ss << "INSERT INTO " << streaming_identifier(table.name) << " "; - if(columnNamesCount) { + if (columnNamesCount) { ss << "(" << streaming_identifiers(columnNames) << ")"; } else { ss << "DEFAULT"; } ss << " VALUES "; - if(columnNamesCount) { + if (columnNamesCount) { ss << streaming_values_placeholders(columnNamesCount, valuesCount); - } else if(valuesCount != 1) { + } else if (valuesCount != 1) { throw std::system_error{orm_error_code::cannot_use_default_value}; } return ss.str(); @@ -1692,12 +1692,12 @@ namespace sqlite_orm { << streaming_identifier(table.name) << " WHERE "; auto primaryKeyColumnNames = table.primary_key_column_names(); - if(primaryKeyColumnNames.empty()) { + if (primaryKeyColumnNames.empty()) { throw std::system_error{orm_error_code::table_has_no_primary_key_column}; } - for(size_t i = 0; i < primaryKeyColumnNames.size(); ++i) { - if(i > 0) { + for (size_t i = 0; i < primaryKeyColumnNames.size(); ++i) { + if (i > 0) { ss << " AND "; } ss << streaming_identifier(primaryKeyColumnNames[i]) << " = ?"; @@ -1731,7 +1731,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case conflict_action::replace: return "REPLACE"; case conflict_action::abort: @@ -1783,19 +1783,19 @@ namespace sqlite_orm { subCtx.use_parentheses = true; std::stringstream ss; - if(!is_compound_operator::value) { - if(!sel.highest_level && context.use_parentheses) { + if (!is_compound_operator::value) { + if (!sel.highest_level && context.use_parentheses) { ss << "("; } ss << "SELECT "; } - if(get_distinct(sel.col)) { + if (get_distinct(sel.col)) { ss << static_cast(distinct(0)) << " "; } ss << streaming_serialized(get_column_names(sel.col, subCtx)); using conditions_tuple = typename statement_type::conditions_type; constexpr bool hasExplicitFrom = tuple_has::value; - if(!hasExplicitFrom) { + if (!hasExplicitFrom) { auto tableNames = collect_table_names(sel, context); using joins_index_sequence = filter_tuple_sequence_t; // deduplicate table names of constrained join statements @@ -1807,13 +1807,13 @@ namespace sqlite_orm { alias_extractor::as_alias()}; tableNames.erase(tableNameWithAlias); }); - if(!tableNames.empty() && !is_compound_operator::value) { + if (!tableNames.empty() && !is_compound_operator::value) { ss << " FROM " << streaming_identifiers(tableNames); } } ss << streaming_conditions_tuple(sel.conditions, context); - if(!is_compound_operator::value) { - if(!sel.highest_level && context.use_parentheses) { + if (!is_compound_operator::value) { + if (!sel.highest_level && context.use_parentheses) { ss << ")"; } } @@ -1829,11 +1829,11 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << serialize(statement.column_or_expression, context); - if(!statement._collation_name.empty()) { + if (!statement._collation_name.empty()) { ss << " COLLATE " << statement._collation_name; } - if(statement._order) { - switch(statement._order) { + if (statement._order) { + switch (statement._order) { case -1: ss << " DESC"; break; @@ -1887,7 +1887,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "CREATE "; - if(statement.unique) { + if (statement.unique) { ss << "UNIQUE "; } using indexed_type = typename statement_type::table_mapped_type; @@ -1897,7 +1897,7 @@ namespace sqlite_orm { std::string whereString; iterate_tuple(statement.elements, [&columnNames, &context, &whereString](auto& value) { using value_type = polyfill::remove_cvref_t; - if(!is_where::value) { + if (!is_where::value) { auto newContext = context; newContext.use_parentheses = false; auto whereString = serialize(value, newContext); @@ -1908,7 +1908,7 @@ namespace sqlite_orm { } }); ss << " (" << streaming_serialized(columnNames) << ")"; - if(!whereString.empty()) { + if (!whereString.empty()) { ss << ' ' << whereString; } return ss.str(); @@ -1971,7 +1971,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { - switch(statement.type) { + switch (statement.type) { case raise_t::type_t::ignore: return "RAISE(IGNORE)"; @@ -1994,7 +1994,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case trigger_timing::trigger_before: return "BEFORE"; case trigger_timing::trigger_after: @@ -2012,7 +2012,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case trigger_type::trigger_delete: return "DELETE"; case trigger_type::trigger_insert: @@ -2061,7 +2061,7 @@ namespace sqlite_orm { ss << serialize(statement.type_base, context); ss << " ON " << streaming_identifier(lookup_table_name(context.db_objects)); - if(statement.do_for_each_row) { + if (statement.do_for_each_row) { ss << " FOR EACH ROW"; } statement.container_when.apply([&ss, &context](auto& value) { @@ -2085,7 +2085,7 @@ namespace sqlite_orm { ss << " BEGIN "; iterate_tuple(statement.elements, [&ss, &context](auto& element) { using element_type = polyfill::remove_cvref_t; - if(is_select::value) { + if (is_select::value) { auto newContext = context; newContext.use_parentheses = false; ss << serialize(element, newContext); @@ -2237,8 +2237,8 @@ namespace sqlite_orm { newContext.skip_table_name = false; std::stringstream ss; ss << static_cast(limt) << " "; - if(HO) { - if(OI) { + if (HO) { + if (OI) { limt.off.apply([&newContext, &ss](auto& value) { ss << serialize(value, newContext); }); @@ -2286,11 +2286,11 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << streaming_expressions_tuple(statement, context); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -2304,7 +2304,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << "VALUES "; @@ -2313,7 +2313,7 @@ namespace sqlite_orm { tupleContext.use_parentheses = true; ss << streaming_expressions_tuple(statement.tuple, tupleContext); } - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -2327,11 +2327,11 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << "VALUES " << streaming_dynamic_expressions(statement.vector, context); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); diff --git a/dev/storage.h b/dev/storage.h index 63485101b..144283a97 100644 --- a/dev/storage.h +++ b/dev/storage.h @@ -159,18 +159,18 @@ namespace sqlite_orm { // here we copy source table to another with a name with '_backup' suffix, but in case table with such // a name already exists we append suffix 1, then 2, etc until we find a free name.. auto backupTableName = table.name + "_backup"; - if(this->table_exists(db, backupTableName)) { + if (this->table_exists(db, backupTableName)) { int suffix = 1; do { std::stringstream ss; ss << suffix << std::flush; auto anotherBackupTableName = backupTableName + ss.str(); - if(!this->table_exists(db, anotherBackupTableName)) { + if (!this->table_exists(db, anotherBackupTableName)) { backupTableName = std::move(anotherBackupTableName); break; } ++suffix; - } while(true); + } while (true); } this->create_table(db, backupTableName, table); @@ -261,7 +261,7 @@ namespace sqlite_orm { #if defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED - requires(is_select_v) #endif result_set_view iterate(Select expression) { expression.highest_level = true; @@ -272,7 +272,7 @@ namespace sqlite_orm { #if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED - requires(is_select_v) + requires (is_select_v) #endif result_set_view, db_objects_type> iterate(with_t expression) { auto con = this->get_connection(); @@ -347,12 +347,12 @@ namespace sqlite_orm { std::string group_concat_internal(F O::* m, std::unique_ptr y, Args&&... args) { this->assert_mapped_type(); std::vector rows; - if(y) { + if (y) { rows = this->select(sqlite_orm::group_concat(m, std::move(*y)), std::forward(args)...); } else { rows = this->select(sqlite_orm::group_concat(m), std::forward(args)...); } - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -530,7 +530,7 @@ namespace sqlite_orm { using R = mapped_type_proxy_t; this->assert_mapped_type(); auto rows = this->select(sqlite_orm::count(), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -556,7 +556,7 @@ namespace sqlite_orm { int count(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::count(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -575,7 +575,7 @@ namespace sqlite_orm { double avg(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::avg(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -625,7 +625,7 @@ namespace sqlite_orm { bool> = true> std::string group_concat(F field, const char* y, Args&&... args) { std::unique_ptr str; - if(y) { + if (y) { str = std::make_unique(y); } else { str = std::make_unique(); @@ -646,7 +646,7 @@ namespace sqlite_orm { std::unique_ptr max(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::max(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -666,7 +666,7 @@ namespace sqlite_orm { std::unique_ptr min(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::min(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -687,8 +687,8 @@ namespace sqlite_orm { this->assert_mapped_type>(); std::vector> rows = this->select(sqlite_orm::sum(std::move(field)), std::forward(args)...); - if(!rows.empty()) { - if(rows.front()) { + if (!rows.empty()) { + if (rows.front()) { return std::make_unique(std::move(*rows.front())); } else { return {}; @@ -711,7 +711,7 @@ namespace sqlite_orm { double total(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::total(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -829,7 +829,7 @@ namespace sqlite_orm { void replace_range(It from, It to, Projection project = {}) { using O = std::decay_t; this->assert_mapped_type(); - if(from == to) { + if (from == to) { return; } @@ -841,7 +841,7 @@ namespace sqlite_orm { template void replace_range(It from, It to, Projection project = {}) { this->assert_mapped_type(); - if(from == to) { + if (from == to) { return; } @@ -950,7 +950,7 @@ namespace sqlite_orm { using O = std::decay_t(), *std::declval()))>; this->assert_mapped_type(); this->assert_insertable_type(); - if(from == to) { + if (from == to) { return; } auto statement = @@ -962,7 +962,7 @@ namespace sqlite_orm { void insert_range(It from, It to, Projection project = {}) { this->assert_mapped_type(); this->assert_insertable_type(); - if(from == to) { + if (from == to) { return; } auto statement = @@ -1026,7 +1026,7 @@ namespace sqlite_orm { sqlite3* db, bool preserve, bool* attempt_to_preserve) { - if(attempt_to_preserve) { + if (attempt_to_preserve) { *attempt_to_preserve = true; } @@ -1035,7 +1035,7 @@ namespace sqlite_orm { // first let's see if table with such name exists.. auto gottaCreateTable = !this->table_exists(db, table.name); - if(!gottaCreateTable) { + if (!gottaCreateTable) { // get table info provided in `make_table` call.. auto storageTableInfo = table.get_table_info(); @@ -1043,15 +1043,15 @@ namespace sqlite_orm { // this vector will contain pointers to columns that gotta be added.. std::vector columnsToAdd; - if(calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo)) { + if (calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo)) { gottaCreateTable = true; } - if(!gottaCreateTable) { // if all storage columns are equal to actual db columns but there are + if (!gottaCreateTable) { // if all storage columns are equal to actual db columns but there are // excess columns at the db.. - if(!dbTableInfo.empty()) { + if (!dbTableInfo.empty()) { // extra table columns than storage columns - if(!preserve) { + if (!preserve) { #if SQLITE_VERSION_NUMBER >= 3035000 // DROP COLUMN feature exists (v3.35.0) res = sync_schema_result::old_columns_removed; #else @@ -1062,33 +1062,33 @@ namespace sqlite_orm { } } } - if(gottaCreateTable) { + if (gottaCreateTable) { res = sync_schema_result::dropped_and_recreated; } else { - if(!columnsToAdd.empty()) { + if (!columnsToAdd.empty()) { // extra storage columns than table columns - for(const table_xinfo* colInfo: columnsToAdd) { + for (const table_xinfo* colInfo: columnsToAdd) { const basic_generated_always::storage_type* generatedStorageType = table.find_column_generated_storage_type(colInfo->name); - if(generatedStorageType) { - if(*generatedStorageType == basic_generated_always::storage_type::stored) { + if (generatedStorageType) { + if (*generatedStorageType == basic_generated_always::storage_type::stored) { gottaCreateTable = true; break; } // fallback cause VIRTUAL can be added } else { - if(colInfo->notnull && colInfo->dflt_value.empty()) { + if (colInfo->notnull && colInfo->dflt_value.empty()) { gottaCreateTable = true; // no matter if preserve is true or false, there is no way to preserve data, so we wont try! - if(attempt_to_preserve) { + if (attempt_to_preserve) { *attempt_to_preserve = false; }; break; } } } - if(!gottaCreateTable) { - if(res == sync_schema_result::old_columns_removed) { + if (!gottaCreateTable) { + if (res == sync_schema_result::old_columns_removed) { res = sync_schema_result::new_columns_added_and_old_columns_removed; } else { res = sync_schema_result::new_columns_added; @@ -1097,7 +1097,7 @@ namespace sqlite_orm { res = sync_schema_result::dropped_and_recreated; } } else { - if(res != sync_schema_result::old_columns_removed) { + if (res != sync_schema_result::old_columns_removed) { res = sync_schema_result::already_in_sync; } } @@ -1473,7 +1473,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( call_as_template_base([&table, &bindValue, &object](auto& column) { - if(!exists_in_composite_primary_key(table, column)) { + if (!exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } })); @@ -1523,12 +1523,12 @@ namespace sqlite_orm { auto& object = get_object(statement.expression); table.template for_each_column_excluding>( call_as_template_base([&table, &bindValue, &object](auto& column) { - if(!exists_in_composite_primary_key(table, column)) { + if (!exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } })); table.for_each_column([&table, &bindValue, &object](auto& column) { - if(column.template is() || exists_in_composite_primary_key(table, column)) { + if (column.template is() || exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } }); @@ -1578,14 +1578,14 @@ namespace sqlite_orm { object_from_column_builder builder{res.emplace(), stmt}; table.for_each_column(builder); }); - if(!res.has_value()) { + if (!res.has_value()) { throw std::system_error{orm_error_code::not_found}; } return std::move(res).value(); #else auto& table = this->get_table(); auto stepRes = sqlite3_step(stmt); - switch(stepRes) { + switch (stepRes) { case SQLITE_ROW: { T res; object_from_column_builder builder{res, stmt}; @@ -1649,7 +1649,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif @@ -1670,7 +1670,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif @@ -1692,7 +1692,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif diff --git a/dev/storage_base.h b/dev/storage_base.h index 78e4f1412..49c60124e 100644 --- a/dev/storage_base.h +++ b/dev/storage_base.h @@ -169,7 +169,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char** /*azColName*/) -> int { auto& res = *(bool*)data; - if(argc) { + if (argc) { res = !!atoi(argv[0]); } return 0; @@ -181,8 +181,8 @@ namespace sqlite_orm { void add_generated_cols(std::vector& columnsToAdd, const std::vector& storageTableInfo) { // iterate through storage columns - for(const table_xinfo& storageColumnInfo: storageTableInfo) { - if(storageColumnInfo.hidden) { + for (const table_xinfo& storageColumnInfo: storageTableInfo) { + if (storageColumnInfo.hidden) { columnsToAdd.push_back(&storageColumnInfo); } } @@ -269,8 +269,8 @@ namespace sqlite_orm { "SELECT name FROM sqlite_master WHERE type='table'", [](void* data, int argc, char** argv, char** /*columnName*/) -> int { auto& tableNames_ = *(data_t*)data; - for(int i = 0; i < argc; ++i) { - if(argv[i]) { + for (int i = 0; i < argc; ++i) { + if (argv[i]) { tableNames_.emplace_back(argv[i]); } } @@ -293,7 +293,7 @@ namespace sqlite_orm { void open_forever() { this->isOpenedForever = true; this->connection->retain(); - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } } @@ -390,7 +390,7 @@ namespace sqlite_orm { nullptr, std::pair{nullptr, null_xdestroy_f}); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_scalar_function(db, this->scalarFunctions.back()); } @@ -524,24 +524,24 @@ namespace sqlite_orm { void create_collation(const std::string& name, collating_function f) { const auto functionExists = bool(f); collating_function* function = nullptr; - if(functionExists) { + if (functionExists) { function = &(collatingFunctions[name] = std::move(f)); } // create collations if db is open - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); int rc = sqlite3_create_collation(db, name.c_str(), SQLITE_UTF8, function, functionExists ? collate_callback : nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } - if(!functionExists) { + if (!functionExists) { collatingFunctions.erase(name); } } @@ -573,7 +573,7 @@ namespace sqlite_orm { sqlite3* db = this->connection->get(); perform_void_exec(db, "COMMIT"); this->connection->release(); - if(this->connection->retain_count() < 0) { + if (this->connection->retain_count() < 0) { throw std::system_error{orm_error_code::no_active_transaction}; } } @@ -582,7 +582,7 @@ namespace sqlite_orm { sqlite3* db = this->connection->get(); perform_void_exec(db, "ROLLBACK"); this->connection->release(); - if(this->connection->retain_count() < 0) { + if (this->connection->retain_count() < 0) { throw std::system_error{orm_error_code::no_active_transaction}; } } @@ -650,8 +650,8 @@ namespace sqlite_orm { int busy_handler(std::function handler) { _busy_handler = std::move(handler); - if(this->is_opened()) { - if(_busy_handler) { + if (this->is_opened()) { + if (_busy_handler) { return sqlite3_busy_handler(this->connection->get(), busy_handler_callback, this); } else { return sqlite3_busy_handler(this->connection->get(), nullptr, nullptr); @@ -668,7 +668,7 @@ namespace sqlite_orm { inMemory(filename.empty() || filename == ":memory:"), connection(std::make_unique(std::move(filename))), cachedForeignKeysCount(foreignKeysCount) { - if(this->inMemory) { + if (this->inMemory) { this->connection->retain(); this->on_open_internal(this->connection->get()); } @@ -679,24 +679,24 @@ namespace sqlite_orm { limit(std::bind(&storage_base::get_connection, this)), inMemory(other.inMemory), connection(std::make_unique(other.connection->filename)), cachedForeignKeysCount(other.cachedForeignKeysCount) { - if(this->inMemory) { + if (this->inMemory) { this->connection->retain(); this->on_open_internal(this->connection->get()); } } ~storage_base() { - if(this->isOpenedForever) { + if (this->isOpenedForever) { this->connection->release(); } - if(this->inMemory) { + if (this->inMemory) { this->connection->release(); } } void begin_transaction_internal(const std::string& query) { this->connection->retain(); - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } sqlite3* db = this->connection->get(); @@ -705,7 +705,7 @@ namespace sqlite_orm { connection_ref get_connection() { connection_ref res{*this->connection}; - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } return res; @@ -728,42 +728,42 @@ namespace sqlite_orm { void on_open_internal(sqlite3* db) { #if SQLITE_VERSION_NUMBER >= 3006019 - if(this->cachedForeignKeysCount) { + if (this->cachedForeignKeysCount) { this->foreign_keys(db, true); } #endif - if(this->pragma.synchronous_ != -1) { + if (this->pragma.synchronous_ != -1) { this->pragma.synchronous(this->pragma.synchronous_); } - if(this->pragma.journal_mode_ != -1) { + if (this->pragma.journal_mode_ != -1) { this->pragma.set_pragma("journal_mode", static_cast(this->pragma.journal_mode_), db); } - for(auto& p: this->collatingFunctions) { + for (auto& p: this->collatingFunctions) { int rc = sqlite3_create_collation(db, p.first.c_str(), SQLITE_UTF8, &p.second, collate_callback); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } - for(auto& p: this->limit.limits) { + for (auto& p: this->limit.limits) { sqlite3_limit(db, p.first, p.second); } - if(_busy_handler) { + if (_busy_handler) { sqlite3_busy_handler(this->connection->get(), busy_handler_callback, this); } - for(auto& udfProxy: this->scalarFunctions) { + for (auto& udfProxy: this->scalarFunctions) { try_to_create_scalar_function(db, udfProxy); } - for(auto& udfProxy: this->aggregateFunctions) { + for (auto& udfProxy: this->aggregateFunctions) { try_to_create_aggregate_function(db, udfProxy); } - if(this->on_open) { + if (this->on_open) { this->on_open(db); } } @@ -777,7 +777,7 @@ namespace sqlite_orm { : int(std::tuple_size::value); using is_stateless = std::is_empty; auto udfMemorySpace = preallocate_udf_memory(); - if SQLITE_ORM_CONSTEXPR_IF(is_stateless::value) { + if SQLITE_ORM_CONSTEXPR_IF (is_stateless::value) { constructAt(udfMemorySpace.first); } this->scalarFunctions.emplace_back( @@ -795,7 +795,7 @@ namespace sqlite_orm { }, udfMemorySpace); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_scalar_function(db, this->scalarFunctions.back()); } @@ -820,7 +820,7 @@ namespace sqlite_orm { F* udfPointer; try { udfPointer = proxy_get_aggregate_step_udf(context, argsCount); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc&) { sqlite3_result_error_nomem(context); return; } @@ -843,7 +843,7 @@ namespace sqlite_orm { }, obtain_udf_allocator()); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_aggregate_function(db, this->aggregateFunctions.back()); } @@ -857,8 +857,8 @@ namespace sqlite_orm { return udfProxy.name == name; }); #endif - if(it != functions.end()) { - if(this->connection->retain_count() > 0) { + if (it != functions.end()) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); int rc = sqlite3_create_function_v2(db, name.c_str(), @@ -869,7 +869,7 @@ namespace sqlite_orm { nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -889,7 +889,7 @@ namespace sqlite_orm { nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -903,7 +903,7 @@ namespace sqlite_orm { nullptr, udfProxy.func, aggregate_function_final_callback); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(rc); } } @@ -929,7 +929,7 @@ namespace sqlite_orm { void drop_table_internal(sqlite3* db, const std::string& tableName, bool ifExists) { std::stringstream ss; ss << "DROP TABLE"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << streaming_identifier(tableName) << std::flush; @@ -939,7 +939,7 @@ namespace sqlite_orm { void drop_index_internal(const std::string& indexName, bool ifExists) { std::stringstream ss; ss << "DROP INDEX"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << quote_identifier(indexName) << std::flush; @@ -949,7 +949,7 @@ namespace sqlite_orm { void drop_trigger_internal(const std::string& triggerName, bool ifExists) { std::stringstream ss; ss << "DROP TRIGGER"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << quote_identifier(triggerName) << std::flush; @@ -964,7 +964,7 @@ namespace sqlite_orm { static int busy_handler_callback(void* selfPointer, int triesCount) { auto& storage = *static_cast(selfPointer); - if(storage._busy_handler) { + if (storage._busy_handler) { return storage._busy_handler(triesCount); } else { return 0; @@ -977,8 +977,8 @@ namespace sqlite_orm { bool notEqual = false; // iterate through storage columns - for(size_t storageColumnInfoIndex = 0; storageColumnInfoIndex < storageTableInfo.size(); - ++storageColumnInfoIndex) { + for (size_t storageColumnInfoIndex = 0; storageColumnInfoIndex < storageTableInfo.size(); + ++storageColumnInfoIndex) { // get storage's column info table_xinfo& storageColumnInfo = storageTableInfo[storageColumnInfoIndex]; @@ -992,7 +992,7 @@ namespace sqlite_orm { return ti.name == columnName; }); #endif - if(dbColumnInfoIt != dbTableInfo.end()) { + if (dbColumnInfoIt != dbTableInfo.end()) { auto& dbColumnInfo = *dbColumnInfoIt; auto columnsAreEqual = dbColumnInfo.name == storageColumnInfo.name && @@ -1000,7 +1000,7 @@ namespace sqlite_orm { (!dbColumnInfo.dflt_value.empty()) == (!storageColumnInfo.dflt_value.empty()) && dbColumnInfo.pk == storageColumnInfo.pk && (dbColumnInfo.hidden == 0) == (storageColumnInfo.hidden == 0); - if(!columnsAreEqual) { + if (!columnsAreEqual) { notEqual = true; break; } diff --git a/dev/sync_schema_result.h b/dev/sync_schema_result.h index e4df5cc96..5de9a6db9 100644 --- a/dev/sync_schema_result.h +++ b/dev/sync_schema_result.h @@ -42,7 +42,7 @@ namespace sqlite_orm { }; inline std::ostream& operator<<(std::ostream& os, sync_schema_result value) { - switch(value) { + switch (value) { case sync_schema_result::new_table_created: return os << "new table created"; case sync_schema_result::already_in_sync: diff --git a/dev/table_name_collector.h b/dev/table_name_collector.h index 47429675f..c5d7990fa 100644 --- a/dev/table_name_collector.h +++ b/dev/table_name_collector.h @@ -56,7 +56,7 @@ namespace sqlite_orm { template void operator()(const count_asterisk_t&) { auto tableName = lookup_table_name(this->db_objects); - if(!tableName.empty()) { + if (!tableName.empty()) { this->table_names.emplace(std::move(tableName), ""); } } diff --git a/dev/transaction_guard.h b/dev/transaction_guard.h index d83fad5c6..2065e4fb8 100644 --- a/dev/transaction_guard.h +++ b/dev/transaction_guard.h @@ -39,8 +39,8 @@ namespace sqlite_orm { } ~transaction_guard_t() noexcept(false) { - if(this->gotta_fire) { - if(this->commit_on_destroy) { + if (this->gotta_fire) { + if (this->commit_on_destroy) { this->commit_func(); } else { this->rollback_func(); diff --git a/dev/tuple_helper/tuple_iteration.h b/dev/tuple_helper/tuple_iteration.h index e696cc9a9..8859abe08 100644 --- a/dev/tuple_helper/tuple_iteration.h +++ b/dev/tuple_helper/tuple_iteration.h @@ -9,7 +9,7 @@ namespace sqlite_orm { #if defined(SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED) && defined(SQLITE_ORM_IF_CONSTEXPR_SUPPORTED) template constexpr void iterate_tuple(Tpl& tpl, std::index_sequence, L&& lambda) { - if constexpr(reversed) { + if constexpr (reversed) { // nifty fold expression trick: make use of guaranteed right-to-left evaluation order when folding over operator= int sink; // note: `(void)` cast silences warning 'expression result unused' @@ -24,7 +24,7 @@ namespace sqlite_orm { template void iterate_tuple(Tpl& tpl, std::index_sequence, L&& lambda) { - if SQLITE_ORM_CONSTEXPR_IF(reversed) { + if SQLITE_ORM_CONSTEXPR_IF (reversed) { iterate_tuple(tpl, std::index_sequence{}, std::forward(lambda)); lambda(std::get(tpl)); } else { diff --git a/dev/udf_proxy.h b/dev/udf_proxy.h index 31cfd140c..bd14a5023 100644 --- a/dev/udf_proxy.h +++ b/dev/udf_proxy.h @@ -111,11 +111,11 @@ namespace sqlite_orm { ~udf_proxy() { // destruct - if(/*bool aprioriConstructed = */ !constructAt && destroy) { + if (/*bool aprioriConstructed = */ !constructAt && destroy) { destroy(udfMemorySpace.first); } // deallocate - if(udfMemorySpace.second) { + if (udfMemorySpace.second) { udfMemorySpace.second(udfMemorySpace.first); } } @@ -159,12 +159,12 @@ namespace sqlite_orm { inline void* ensure_aggregate_udf(sqlite3_context* context, udf_proxy* proxy, int argsCount) { // reserve memory for storing a void pointer (which is the `udfHandle`, i.e. address of the aggregate function object) void* ctxMemory = sqlite3_aggregate_context(context, sizeof(void*)); - if(!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { + if (!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { throw std::bad_alloc(); } void*& udfHandle = *static_cast(ctxMemory); - if(udfHandle) SQLITE_ORM_CPP_LIKELY { + if (udfHandle) SQLITE_ORM_CPP_LIKELY { return udfHandle; } else { assert_args_count(proxy, argsCount); @@ -220,7 +220,7 @@ namespace sqlite_orm { try { // note: it is possible that the 'step' function was never called udfHandle = ensure_aggregate_udf(context, proxy, -1); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc&) { sqlite3_result_error_nomem(context); return; } diff --git a/dev/util.h b/dev/util.h index f162eeda9..e4ed10689 100644 --- a/dev/util.h +++ b/dev/util.h @@ -14,7 +14,7 @@ namespace sqlite_orm { * @param char2Escape The character to escape */ inline std::string sql_escape(std::string str, char char2Escape) { - for(size_t pos = 0; (pos = str.find(char2Escape, pos)) != str.npos; pos += 2) { + for (size_t pos = 0; (pos = str.find(char2Escape, pos)) != str.npos; pos += 2) { str.replace(pos, 1, 2, char2Escape); } @@ -58,7 +58,7 @@ namespace sqlite_orm { // note: query is deliberately taken by value, such that it is thrown away early inline sqlite3_stmt* prepare_stmt(sqlite3* db, std::string query) { sqlite3_stmt* stmt; - if(sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { + if (sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { throw_translated_sqlite_error(db); } return stmt; @@ -66,7 +66,7 @@ namespace sqlite_orm { inline void perform_void_exec(sqlite3* db, const std::string& query) { int rc = sqlite3_exec(db, query.c_str(), nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -76,7 +76,7 @@ namespace sqlite_orm { int (*callback)(void* data, int argc, char** argv, char**), void* user_data) { int rc = sqlite3_exec(db, query, callback, user_data, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -91,14 +91,14 @@ namespace sqlite_orm { template void perform_step(sqlite3_stmt* stmt) { int rc = sqlite3_step(stmt); - if(rc != expected) { + if (rc != expected) { throw_translated_sqlite_error(stmt); } } template void perform_step(sqlite3_stmt* stmt, L&& lambda) { - switch(int rc = sqlite3_step(stmt)) { + switch (int rc = sqlite3_step(stmt)) { case SQLITE_ROW: { lambda(stmt); } break; @@ -114,7 +114,7 @@ namespace sqlite_orm { void perform_steps(sqlite3_stmt* stmt, L&& lambda) { int rc; do { - switch(rc = sqlite3_step(stmt)) { + switch (rc = sqlite3_step(stmt)) { case SQLITE_ROW: { lambda(stmt); } break; @@ -124,7 +124,7 @@ namespace sqlite_orm { throw_translated_sqlite_error(stmt); } } - } while(rc != SQLITE_DONE); + } while (rc != SQLITE_DONE); } } } diff --git a/dev/xdestroy_handling.h b/dev/xdestroy_handling.h index 4d73977c4..0865080c9 100644 --- a/dev/xdestroy_handling.h +++ b/dev/xdestroy_handling.h @@ -117,7 +117,7 @@ namespace sqlite_orm { * it doesn't check so explicitly, but a compiler error will occur. */ template - requires(!integral_fp_c) + requires (!integral_fp_c) void xdestroy_proxy(void* p) noexcept { // C-casting `void* -> P*` like statement_binder> auto o = (P*)p; @@ -182,7 +182,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D, P* = nullptr) noexcept - requires(internal::is_unusable_for_xdestroy) + requires (internal::is_unusable_for_xdestroy) { static_assert(polyfill::always_false_v, "A function pointer, which is not of type xdestroy_fn_t, is prohibited."); @@ -203,7 +203,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D, P* = nullptr) noexcept - requires(internal::needs_xdestroy_proxy) + requires (internal::needs_xdestroy_proxy) { return internal::xdestroy_proxy; } @@ -224,7 +224,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D d, P* = nullptr) noexcept - requires(internal::yields_xdestroy) + requires (internal::yields_xdestroy) { return d; } diff --git a/examples/any.cpp b/examples/any.cpp index f49ba9559..4355766fd 100644 --- a/examples/any.cpp +++ b/examples/any.cpp @@ -28,7 +28,7 @@ namespace sqlite_orm { struct row_extractor { std::any extract(sqlite3_stmt* stmt, int columnIndex) const { const int type = sqlite3_column_type(stmt, columnIndex); - switch(type) { + switch (type) { case SQLITE_NULL: return std::nullopt; case SQLITE_INTEGER: @@ -52,7 +52,7 @@ namespace sqlite_orm { std::any extract(sqlite3_value* value) const { const int type = sqlite3_value_type(value); - switch(type) { + switch (type) { case SQLITE_NULL: return std::nullopt; case SQLITE_INTEGER: @@ -78,18 +78,18 @@ namespace sqlite_orm { template<> struct statement_binder { int bind(sqlite3_stmt* stmt, int index, const std::any& value) const { - if(!value.has_value()) { + if (!value.has_value()) { return sqlite3_bind_null(stmt, index); } - if(value.type() == typeid(int)) { + if (value.type() == typeid(int)) { return sqlite3_bind_int(stmt, index, std::any_cast(value)); - } else if(value.type() == typeid(double)) { + } else if (value.type() == typeid(double)) { return sqlite3_bind_double(stmt, index, std::any_cast(value)); - } else if(value.type() == typeid(std::string)) { + } else if (value.type() == typeid(std::string)) { const auto& text = std::any_cast(value); return sqlite3_bind_text(stmt, index, text.c_str(), static_cast(text.size()), SQLITE_TRANSIENT); - } else if(value.type() == typeid(std::vector)) { + } else if (value.type() == typeid(std::vector)) { const auto& blob = std::any_cast>(value); return sqlite3_bind_blob(stmt, index, blob.data(), static_cast(blob.size()), SQLITE_TRANSIENT); } @@ -104,21 +104,21 @@ namespace sqlite_orm { template<> struct field_printer { std::string operator()(const std::any& value) const { - if(!value.has_value()) { + if (!value.has_value()) { return "NULL"; } - if(value.type() == typeid(int)) { + if (value.type() == typeid(int)) { return std::to_string(std::any_cast(value)); - } else if(value.type() == typeid(double)) { + } else if (value.type() == typeid(double)) { return std::to_string(std::any_cast(value)); - } else if(value.type() == typeid(std::string)) { + } else if (value.type() == typeid(std::string)) { return std::any_cast(value); - } else if(value.type() == typeid(std::vector)) { + } else if (value.type() == typeid(std::vector)) { const auto& blob = std::any_cast>(value); std::ostringstream oss; oss << "0x"; - for(unsigned char c: blob) { + for (unsigned char c: blob) { oss << std::hex << std::setw(2) << std::setfill('0') << static_cast(c); } return oss.str(); @@ -147,7 +147,7 @@ int main() { Value{4, std::any{std::vector{'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!'}}}); cout << "Test:" << endl; - for(auto& test: storage.iterate()) { + for (auto& test: storage.iterate()) { cout << storage.dump(test) << endl; } cout << endl; diff --git a/examples/blob_binding.cpp b/examples/blob_binding.cpp index a4caaf8e1..fbd29219f 100644 --- a/examples/blob_binding.cpp +++ b/examples/blob_binding.cpp @@ -132,7 +132,7 @@ int main() { auto allZones = storage.get_all(); cout << "zones count = " << allZones.size() << ":" << endl; // zones count = 1: - for(auto& zone: allZones) { + for (auto& zone: allZones) { cout << "zone = " << storage.dump(zone) << endl; // zone = { id : '1', rect : '{ x = 10, y = 10, width = 200, height = 300 }' } } @@ -141,7 +141,7 @@ int main() { cout << endl; allZones = storage.get_all(); cout << "zones count = " << allZones.size() << ":" << endl; // zones count = 1: - for(auto& zone: allZones) { + for (auto& zone: allZones) { cout << "zone = " << storage.dump(zone) << endl; // zone = { id : '1', rect : '{ x = 20, y = 20, width = 500, height = 600 }' } } diff --git a/examples/case.cpp b/examples/case.cpp index 8d288e82a..d40810afe 100644 --- a/examples/case.cpp +++ b/examples/case.cpp @@ -40,7 +40,7 @@ int main() { }); // list all students - for(auto& student: storage.iterate()) { + for (auto& student: storage.iterate()) { cout << storage.dump(student) << endl; } cout << endl; @@ -66,7 +66,7 @@ int main() { .when(greater_or_equal(&Student::marks, 50), then("C")) .else_("Sorry!! Failed") .end())); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << ' ' << std::get<1>(row) << ' ' << std::get<2>(row) << ' ' << std::get<3>(row) << endl; } @@ -100,7 +100,7 @@ int main() { .when(greater_or_equal(&Student::marks, 50), then("C")) .else_("Sorry!! Failed") .end()))); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << ' ' << std::get<1>(row) << ' ' << std::get<2>(row) << ' ' << std::get<3>(row) << endl; } diff --git a/examples/check.cpp b/examples/check.cpp index c19456db2..7233862ff 100644 --- a/examples/check.cpp +++ b/examples/check.cpp @@ -54,20 +54,20 @@ int main() { try { storage.insert(Contact{0, "John", "Doe", {}, "408123456"}); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } storage.insert(Contact{0, "John", "Doe", {}, "(408)-123-456"}); try { storage.insert(Product{0, "New Product", 900, 1000}); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } try { storage.insert(Product{0, "New XFactor", 1000, -10}); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } diff --git a/examples/chrono_binding.cpp b/examples/chrono_binding.cpp index 65b500d73..8307b18a9 100644 --- a/examples/chrono_binding.cpp +++ b/examples/chrono_binding.cpp @@ -50,7 +50,7 @@ static std::optional sysDaysFromString(const std::string& std::stringstream ss{s}; std::chrono::sys_days tt; ss >> std::chrono::parse("%F"s, tt); - if(!ss.fail()) { + if (!ss.fail()) { return {tt}; } return std::nullopt; @@ -109,11 +109,11 @@ namespace sqlite_orm { template<> struct row_extractor { std::chrono::sys_days extract(const char* columnText) const { - if(!columnText) { + if (!columnText) { throw std::runtime_error("incorrect date string (nullptr)"); } - if(auto sd = sysDaysFromString(columnText)) { + if (auto sd = sysDaysFromString(columnText)) { return sd.value(); } else { throw std::runtime_error("incorrect date string (" + std::string(columnText) + ")"); diff --git a/examples/column_aliases.cpp b/examples/column_aliases.cpp index 5b70d1a9a..8fdb55cc1 100644 --- a/examples/column_aliases.cpp +++ b/examples/column_aliases.cpp @@ -53,7 +53,7 @@ void marvel_hero_ordered_by_o_pos() { auto rows = storage.select(columns(&MarvelHero::name, as(instr(&MarvelHero::abilities, "o"))), where(greater_than(get(), 0)), order_by(get())); - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << '\n'; } } @@ -68,7 +68,7 @@ void marvel_hero_ordered_by_o_pos() { auto rows = storage.select(columns(&MarvelHero::name, as(instr(&MarvelHero::abilities, "o"))), where(i > 0), order_by(i)); - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << '\n'; } } @@ -79,7 +79,7 @@ void marvel_hero_ordered_by_o_pos() { // FROM marvel // ORDER BY 2 auto rows = storage.select(columns(&MarvelHero::name, instr(&MarvelHero::abilities, "o")), order_by(2)); - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << '\n'; } } @@ -114,7 +114,7 @@ int main() { try { marvel_hero_ordered_by_o_pos(); cpp20_column_pointer(); - } catch(const system_error& e) { + } catch (const system_error& e) { cout << "[" << e.code() << "] " << e.what(); } diff --git a/examples/common_table_expressions.cpp b/examples/common_table_expressions.cpp index 36efcb1d4..27f1dd4c0 100644 --- a/examples/common_table_expressions.cpp +++ b/examples/common_table_expressions.cpp @@ -54,7 +54,7 @@ void all_integers_between(int from, int end) { cout << "Integer range (where-clause) [" << from << ", " << end << "]" "\n"; - for(int n: storage.execute(stmt)) { + for (int n: storage.execute(stmt)) { cout << n << ", "; } cout << endl; @@ -88,7 +88,7 @@ void all_integers_between(int from, int end) { cout << "Integer range (limit-clause) [" << from << ", " << end << "]" "\n"; - for(int n: storage.execute(stmt)) { + for (int n: storage.execute(stmt)) { cout << n << ", "; } cout << endl; @@ -113,7 +113,7 @@ void all_integers_between(int from, int end) { cout << "Integer range (limit-clause) [" << from << ", " << end << "]" "\n"; - for(int n: storage.execute(stmt)) { + for (int n: storage.execute(stmt)) { cout << n << ", "; } cout << endl; @@ -185,7 +185,7 @@ void supervisor_chain() { auto stmt = storage.prepare(ast); auto results = storage.execute(stmt); cout << "Hierarchy chain of Fred:\n"; - for(const string& name: results) { + for (const string& name: results) { cout << name << ", "; } cout << endl; @@ -387,7 +387,7 @@ void family_tree() { auto results = storage.execute(stmt); cout << "Living ancestor's of Alice:\n"; - for(const string& name: results) { + for (const string& name: results) { cout << name << '\n'; } cout << endl; @@ -472,7 +472,7 @@ void depth_or_breadth_first() { auto results = storage.execute(stmt); cout << "List of organization members, breadth-first:\n"; - for(const string& name: results) { + for (const string& name: results) { cout << name << '\n'; } } @@ -516,7 +516,7 @@ void depth_or_breadth_first() { auto results = storage.execute(stmt); cout << "List of organization members, depth-first:\n"; - for(const string& name: results) { + for (const string& name: results) { cout << name << '\n'; } } @@ -572,7 +572,7 @@ void select_from_subselect() { auto results = storage.execute(stmt); cout << "List of employees with a salary less than 5000:\n"; - for(auto& result: results) { + for (auto& result: results) { cout << get<0>(result) << '\n'; } cout << endl; @@ -673,7 +673,7 @@ void apfelmaennchen() { auto results = storage.execute(stmt); cout << "Apfelmaennchen (Mandelbrot set):\n"; - for(const string& rowString: results) { + for (const string& rowString: results) { cout << rowString << '\n'; } cout << endl; @@ -750,7 +750,7 @@ void sudoku() { auto results = storage.execute(stmt); cout << "Sudoku solution:\n"; - for(const string& answer: results) { + for (const string& answer: results) { cout << answer << '\n'; } cout << endl; @@ -963,15 +963,15 @@ void neevek_issue_222() { auto results = storage.execute(stmt); cout << "User Retention:\n"; - for(const char* colName: {"register_date", "ndays", "retention", "user_count"}) { + for (const char* colName: {"register_date", "ndays", "retention", "user_count"}) { cout << " " << std::setw(13) << colName; } cout << '\n'; - for(int i = 0; i < 4; ++i) { + for (int i = 0; i < 4; ++i) { cout << std::setfill(' ') << " " << std::setw(13) << std::setfill('_') << ""; } cout << std::setfill(' ') << '\n'; - for(auto& result: results) { + for (auto& result: results) { cout << " " << std::setw(13) << *get<0>(result); cout << " " << std::setw(13) << get<1>(result); cout << " " << std::setw(13) << get<2>(result); @@ -1044,11 +1044,11 @@ void greatest_n_per_group() { auto results = storage.execute(stmt); cout << "most recent (successful) result per item:\n"; - for(const char* colName: {"id", "item_id", "timestamp", "flag"}) { + for (const char* colName: {"id", "item_id", "timestamp", "flag"}) { cout << "\t" << colName; } cout << '\n'; - for(auto& result: results) { + for (auto& result: results) { cout << "\t" << result.result_id << "\t" << result.item_id << "\t" << result.timestamp << "\t" << result.flag << '\n'; } @@ -1072,7 +1072,7 @@ int main() { greatest_n_per_group(); show_optimization_fence(); show_mapping_and_backreferencing(); - } catch(const system_error& e) { + } catch (const system_error& e) { cout << "[" << e.code() << "] " << e.what(); } #endif diff --git a/examples/composite_key.cpp b/examples/composite_key.cpp index 2335bbfbd..345734d46 100644 --- a/examples/composite_key.cpp +++ b/examples/composite_key.cpp @@ -60,7 +60,7 @@ int main() { try { // 2 and 'Drake' values will be ignored cause they are primary keys storage.insert(User{2, "Drake", "Singer"}); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << "exception = " << e.what() << endl; } storage.replace(User{2, "The Weeknd", "Singer"}); diff --git a/examples/core_functions.cpp b/examples/core_functions.cpp index 4e81a8610..ce6dc4149 100644 --- a/examples/core_functions.cpp +++ b/examples/core_functions.cpp @@ -896,7 +896,7 @@ int main(int, char** argv) { // FROM marvel auto nameLengths = storage.select(length(&MarvelHero::name)); // nameLengths is std::vector cout << "nameLengths.size = " << nameLengths.size() << endl; - for(auto& len: nameLengths) { + for (auto& len: nameLengths) { cout << len << " "; } cout << endl; @@ -907,7 +907,7 @@ int main(int, char** argv) { columns(&MarvelHero::name, length(&MarvelHero::name))); // namesWithLengths is std::vector> cout << "namesWithLengths.size = " << namesWithLengths.size() << endl; - for(auto& row: namesWithLengths) { + for (auto& row: namesWithLengths) { cout << "LENGTH(" << std::get<0>(row) << ") = " << std::get<1>(row) << endl; } @@ -917,7 +917,7 @@ int main(int, char** argv) { auto namesWithLengthGreaterThan5 = storage.select(&MarvelHero::name, where(length(&MarvelHero::name) > 5)); // std::vector cout << "namesWithLengthGreaterThan5.size = " << namesWithLengthGreaterThan5.size() << endl; - for(auto& name: namesWithLengthGreaterThan5) { + for (auto& name: namesWithLengthGreaterThan5) { cout << "name = " << name << endl; } @@ -933,8 +933,8 @@ int main(int, char** argv) { // FROM marvel auto absPoints = storage.select(abs(&MarvelHero::points)); // std::vector> cout << "absPoints: "; - for(auto& value: absPoints) { - if(value) { + for (auto& value: absPoints) { + if (value) { cout << *value; } else { cout << "null"; @@ -948,7 +948,7 @@ int main(int, char** argv) { // WHERE ABS(points) < 5 auto namesByAbs = storage.select(&MarvelHero::name, where(abs(&MarvelHero::points) < 5)); cout << "namesByAbs.size = " << namesByAbs.size() << endl; - for(auto& name: namesByAbs) { + for (auto& name: namesByAbs) { cout << name << endl; } cout << endl; @@ -963,7 +963,7 @@ int main(int, char** argv) { // FROM marvel auto lowerNames = storage.select(lower(&MarvelHero::name)); cout << "lowerNames.size = " << lowerNames.size() << endl; - for(auto& name: lowerNames) { + for (auto& name: lowerNames) { cout << name << endl; } cout << endl; @@ -972,7 +972,7 @@ int main(int, char** argv) { // FROM marvel auto upperAbilities = storage.select(upper(&MarvelHero::abilities)); cout << "upperAbilities.size = " << upperAbilities.size() << endl; - for(auto& abilities: upperAbilities) { + for (auto& abilities: upperAbilities) { cout << abilities << endl; } cout << endl; @@ -1006,7 +1006,7 @@ int main(int, char** argv) { // FROM marvel auto emails = storage.select(lower(&MarvelHero::name) || c("@marvel.com")); cout << "emails.size = " << emails.size() << endl; - for(auto& email: emails) { + for (auto& email: emails) { cout << email << endl; } cout << endl; @@ -1030,12 +1030,12 @@ int main(int, char** argv) { #if SQLITE_VERSION_NUMBER >= 3007016 // SELECT RANDOM() - for(auto i = 0; i < 10; ++i) { + for (auto i = 0; i < 10; ++i) { cout << "RANDOM() = " << storage.select(sqlite_orm::random()).front() << endl; } // SELECT * FROM marvel ORDER BY RANDOM() - for(auto& hero: storage.iterate(order_by(sqlite_orm::random()))) { + for (auto& hero: storage.iterate(order_by(sqlite_orm::random()))) { cout << "hero = " << storage.dump(hero) << endl; } #endif @@ -1148,7 +1148,7 @@ int main(int, char** argv) { auto rows = storage.select(columns(&MarvelHero::name, as(instr(&MarvelHero::abilities, "o"))), where(greater_than(get(), 0)), order_by(get())); - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << endl; } cout << endl; @@ -1166,7 +1166,7 @@ int main(int, char** argv) { // SET phone = REPLACE(phone, '410', '+1-410') storage.update_all(set(c(&Contact::phone) = replace(&Contact::phone, "410", "+1-410"))); cout << "Contacts:" << endl; - for(auto& contact: storage.iterate()) { + for (auto& contact: storage.iterate()) { cout << storage.dump(contact) << endl; } @@ -1213,7 +1213,7 @@ int main(int, char** argv) { ifnull(&Customer::fax, "Call:" || c(&Customer::phone))), order_by(&Customer::firstName)); cout << "rows count: " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << endl; } cout << endl; diff --git a/examples/cross_join.cpp b/examples/cross_join.cpp index 28b2853ed..0bacac604 100644 --- a/examples/cross_join.cpp +++ b/examples/cross_join.cpp @@ -77,7 +77,7 @@ int main(int, char**) { order_by(&Suit::suit)); // cards is vector> cout << "cards count = " << cards.size() << endl; - for(auto card: cards) { + for (auto card: cards) { cout << std::get<0>(card) << '\t' << std::get<1>(card) << endl; } cout << endl; diff --git a/examples/custom_aliases.cpp b/examples/custom_aliases.cpp index cacc49433..fcd44189f 100644 --- a/examples/custom_aliases.cpp +++ b/examples/custom_aliases.cpp @@ -96,7 +96,7 @@ int main(int, char** argv) { cout << "ID" << '\t' << "NAME" << '\t' << "AGE" << '\t' << "DEPT" << endl; cout << "----------" << '\t' << "----------" << '\t' << "----------" << '\t' << "----------" << endl; - for(auto& row: simpleRows) { + for (auto& row: simpleRows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } diff --git a/examples/distinct.cpp b/examples/distinct.cpp index 3848e1a86..fec1b8bed 100644 --- a/examples/distinct.cpp +++ b/examples/distinct.cpp @@ -117,7 +117,7 @@ int main(int, char**) { auto pureNames = storage.select(&Employee::name); cout << "NAME" << endl; cout << "----------" << endl; - for(auto& name: pureNames) { + for (auto& name: pureNames) { cout << name << endl; } cout << endl; @@ -127,7 +127,7 @@ int main(int, char**) { auto distinctNames = storage.select(distinct(&Employee::name)); cout << "NAME" << endl; cout << "----------" << endl; - for(auto& name: distinctNames) { + for (auto& name: distinctNames) { cout << name << endl; } cout << endl; @@ -136,7 +136,7 @@ int main(int, char**) { auto severalColumns = storage.select(distinct(columns(&Employee::address, &Employee::name))); cout << "ADDRESS" << '\t' << "NAME" << endl; cout << "----------" << endl; - for(auto& t: severalColumns) { + for (auto& t: severalColumns) { cout << std::get<0>(t) << '\t' << std::get<1>(t) << endl; } return 0; diff --git a/examples/enum_binding.cpp b/examples/enum_binding.cpp index 4982d4cf8..70984f9a4 100644 --- a/examples/enum_binding.cpp +++ b/examples/enum_binding.cpp @@ -28,7 +28,7 @@ struct SuperHero { // also we need transform functions to make string from enum.. std::string GenderToString(Gender gender) { - switch(gender) { + switch (gender) { case Gender::Female: return "female"; case Gender::Male: @@ -47,9 +47,9 @@ std::string GenderToString(Gender gender) { * (for example BETTER_ENUM https://github.com/aantron/better-enums) */ std::unique_ptr GenderFromString(const std::string& s) { - if(s == "female") { + if (s == "female") { return std::make_unique(Gender::Female); - } else if(s == "male") { + } else if (s == "male") { return std::make_unique(Gender::Male); } return nullptr; @@ -109,7 +109,7 @@ namespace sqlite_orm { template<> struct row_extractor { Gender extract(const char* columnText) const { - if(auto gender = GenderFromString(columnText)) { + if (auto gender = GenderFromString(columnText)) { return *gender; } else { throw std::runtime_error("incorrect gender string (" + std::string(columnText) + ")"); @@ -150,7 +150,7 @@ int main(int /* argc*/, char** /*argv*/) { // print all superheros cout << "allSuperHeros = " << allSuperHeros.size() << endl; - for(auto& superHero: allSuperHeros) { + for (auto& superHero: allSuperHeros) { cout << storage.dump(superHero) << endl; } @@ -161,7 +161,7 @@ int main(int /* argc*/, char** /*argv*/) { auto males = storage.get_all(where(c(&SuperHero::gender) == Gender::Male)); cout << "males = " << males.size() << endl; assert(males.size() == 2); - for(auto& superHero: males) { + for (auto& superHero: males) { cout << storage.dump(superHero) << endl; } @@ -169,7 +169,7 @@ int main(int /* argc*/, char** /*argv*/) { auto females = storage.get_all(where(c(&SuperHero::gender) == Gender::Female)); assert(females.size() == 1); cout << "females = " << females.size() << endl; - for(auto& superHero: females) { + for (auto& superHero: females) { cout << storage.dump(superHero) << endl; } diff --git a/examples/except_intersection.cpp b/examples/except_intersection.cpp index c409ce17c..7b3f3bd65 100644 --- a/examples/except_intersection.cpp +++ b/examples/except_intersection.cpp @@ -78,7 +78,7 @@ int main() { // FROM emp_master auto rows = storage.select(except(select(&DeptMaster::deptId), select(&EmpMaster::deptId))); cout << "rows count = " << rows.size() << endl; - for(auto id: rows) { + for (auto id: rows) { cout << id << endl; } } @@ -90,7 +90,7 @@ int main() { // FROM emp_master auto rows = storage.select(intersect(select(&DeptMaster::deptId), select(&EmpMaster::deptId))); cout << "rows count = " << rows.size() << endl; - for(auto id: rows) { + for (auto id: rows) { cout << id << endl; } } diff --git a/examples/exists.cpp b/examples/exists.cpp index 56815a401..ed8ad9ae9 100644 --- a/examples/exists.cpp +++ b/examples/exists.cpp @@ -421,7 +421,7 @@ int main(int, char**) { order_by(&Agent::comission)); cout << "AGENT_CODE AGENT_NAME WORKING_AREA COMMISSION" << endl; cout << "---------- ---------------------------------------- ------------ ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -442,7 +442,7 @@ int main(int, char**) { group_by(&Customer::grade).having(greater_than(count(), 2)))))); cout << "CUST_CODE CUST_NAME CUST_CITY GRADE" << endl; cout << "---------- ---------- ----------------------------------- ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -460,7 +460,7 @@ int main(int, char**) { from(), where(not exists(select(&Customer::agentCode, where(is_equal(&Customer::paymentAmt, 1400)))))); cout << "AGENT_CODE ORD_NUM ORD_AMOUNT CUST_CODE" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -523,7 +523,7 @@ int main(int, char**) { #endif auto rows = storage.execute(statement); cout << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << '\t' << std::get<4>(row) << endl; } diff --git a/examples/foreign_key.cpp b/examples/foreign_key.cpp index 3574bbabb..ec7c92e9e 100644 --- a/examples/foreign_key.cpp +++ b/examples/foreign_key.cpp @@ -43,7 +43,7 @@ int main() { make_column("trackartist", &Track::trackArtist), foreign_key(&Track::trackArtist).references(&Artist::artistId))); auto syncSchemaRes = storage.sync_schema(); - for(auto& p: syncSchemaRes) { + for (auto& p: syncSchemaRes) { cout << p.first << " " << p.second << endl; } @@ -62,7 +62,7 @@ int main() { // does not correspond to row in the artist table. storage.replace(Track{14, "Mr. Bojangles", std::make_unique(3)}); assert(0); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } @@ -77,7 +77,7 @@ int main() { storage.update_all(set(assign(&Track::trackArtist, 3)), where(is_equal(&Track::trackName, "Mr. Bojangles"))); assert(0); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } @@ -97,7 +97,7 @@ int main() { // the track table contains a row that refer to it. storage.remove_all(where(is_equal(&Artist::artistName, "Frank Sinatra"))); assert(0); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } @@ -111,7 +111,7 @@ int main() { // exists records in the track table that refer to it. storage.update_all(set(assign(&Artist::artistId, 4)), where(is_equal(&Artist::artistName, "Dean Martin"))); assert(0); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } @@ -132,7 +132,7 @@ int main() { make_column("trackartist", &Track::trackArtist), foreign_key(&Track::trackArtist).references(&Artist::artistId).on_update.cascade())); auto syncSchemaRes = storage.sync_schema(); - for(auto& p: syncSchemaRes) { + for (auto& p: syncSchemaRes) { cout << p.first << " " << p.second << endl; } @@ -155,15 +155,15 @@ int main() { storage.update_all(set(c(&Artist::artistId) = 100), where(c(&Artist::artistName) == "Dean Martin")); cout << "artists:" << endl; - for(auto& artist: storage.iterate()) { + for (auto& artist: storage.iterate()) { cout << artist.artistId << '\t' << artist.artistName << endl; } cout << endl; cout << "tracks:" << endl; - for(auto& track: storage.iterate()) { + for (auto& track: storage.iterate()) { cout << track.trackId << '\t' << track.trackName << '\t'; - if(track.trackArtist) { + if (track.trackArtist) { cout << *track.trackArtist; } else { cout << "null"; @@ -184,7 +184,7 @@ int main() { make_column("trackartist", &Track::trackArtist, default_value(0)), foreign_key(&Track::trackArtist).references(&Artist::artistId).on_delete.set_default())); auto syncSchemaRes = storage.sync_schema(); - for(auto& p: syncSchemaRes) { + for (auto& p: syncSchemaRes) { cout << p.first << " " << p.second << endl; } @@ -203,7 +203,7 @@ int main() { try { storage.remove_all(where(c(&Artist::artistName) == "Sammy Davis Jr.")); assert(0); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } @@ -216,15 +216,15 @@ int main() { storage.remove_all(where(c(&Artist::artistName) == "Sammy Davis Jr.")); cout << "artists:" << endl; - for(auto& artist: storage.iterate()) { + for (auto& artist: storage.iterate()) { cout << artist.artistId << '\t' << artist.artistName << endl; } cout << endl; cout << "tracks:" << endl; - for(auto& track: storage.iterate()) { + for (auto& track: storage.iterate()) { cout << track.trackId << '\t' << track.trackName << '\t'; - if(track.trackArtist) { + if (track.trackArtist) { cout << *track.trackArtist; } else { cout << "null"; diff --git a/examples/generated_column.cpp b/examples/generated_column.cpp index 7a3a0ef35..7626cec3f 100644 --- a/examples/generated_column.cpp +++ b/examples/generated_column.cpp @@ -48,7 +48,7 @@ int main() { storage.replace(Product{5, "Bandage", 70, 120.00f}); cout << "Products:" << endl; - for(auto& product: storage.iterate()) { + for (auto& product: storage.iterate()) { cout << storage.dump(product) << endl; } cout << endl; @@ -58,7 +58,7 @@ int main() { storage.update_all(set(c(&Product::quantity) = 5), where(c(&Product::id) == 1)); cout << "Products after update:" << endl; - for(auto& product: storage.iterate()) { + for (auto& product: storage.iterate()) { cout << storage.dump(product) << endl; } cout << endl; diff --git a/examples/group_by.cpp b/examples/group_by.cpp index 8be912278..5b58d06e9 100644 --- a/examples/group_by.cpp +++ b/examples/group_by.cpp @@ -43,7 +43,7 @@ int main(int, char**) { // FROM COMPANY // GROUP BY NAME; auto salaryName = storage.select(columns(&Employee::name, sum(&Employee::salary)), group_by(&Employee::name)); - for(auto& t: salaryName) { + for (auto& t: salaryName) { cout << std::get<0>(t) << '\t' << *std::get<1>(t) << endl; } @@ -55,7 +55,7 @@ int main(int, char**) { cout << endl << "Now, our table has the following records with duplicate names:" << endl << endl; - for(auto& employee: storage.iterate()) { + for (auto& employee: storage.iterate()) { cout << storage.dump(employee) << endl; } @@ -65,7 +65,7 @@ int main(int, char**) { salaryName = storage.select(columns(&Employee::name, sum(&Employee::salary)), group_by(&Employee::name), order_by(&Employee::name)); - for(auto& t: salaryName) { + for (auto& t: salaryName) { cout << std::get<0>(t) << '\t' << *std::get<1>(t) << endl; } @@ -73,7 +73,7 @@ int main(int, char**) { salaryName = storage.select(columns(&Employee::name, sum(&Employee::salary)), group_by(&Employee::name), order_by(&Employee::name).desc()); - for(auto& t: salaryName) { + for (auto& t: salaryName) { cout << std::get<0>(t) << '\t' << *std::get<1>(t) << endl; } diff --git a/examples/having.cpp b/examples/having.cpp index dea676f97..8d1bc2e17 100644 --- a/examples/having.cpp +++ b/examples/having.cpp @@ -48,7 +48,7 @@ int main() { // GROUP BY name // HAVING count(name) < 2; auto rows = storage.get_all(group_by(&Employee::name).having(less_than(count(&Employee::name), 2))); - for(auto& employee: rows) { + for (auto& employee: rows) { cout << storage.dump(employee) << endl; } cout << endl; @@ -60,7 +60,7 @@ int main() { // HAVING count(name) > 2; auto rows = storage.get_all(group_by(&Employee::name).having(greater_than(count(&Employee::name), 2))); - for(auto& employee: rows) { + for (auto& employee: rows) { cout << storage.dump(employee) << endl; } cout << endl; diff --git a/examples/index.cpp b/examples/index.cpp index 2a68a696f..661775186 100644 --- a/examples/index.cpp +++ b/examples/index.cpp @@ -41,7 +41,7 @@ int main(int, char**) { "Doe", "john.doe@sqlitetutorial.net", }); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << e.what() << endl; } std::vector moreContracts = { diff --git a/examples/insert.cpp b/examples/insert.cpp index 62ca2d243..658127ae2 100644 --- a/examples/insert.cpp +++ b/examples/insert.cpp @@ -90,7 +90,7 @@ int main(int, char**) { // and closes database. So triple insert will open and close the db three times. // Transaction openes and closes the db only once. storage.transaction([&] { - for(auto& employee: otherEmployees) { + for (auto& employee: otherEmployees) { storage.insert(employee); } return true; // commit @@ -106,7 +106,7 @@ int main(int, char**) { james.id = storage.insert(james); cout << "---------------------" << endl; - for(auto& employee: storage.iterate()) { + for (auto& employee: storage.iterate()) { cout << storage.dump(employee) << endl; } diff --git a/examples/iteration.cpp b/examples/iteration.cpp index cd183ce4d..a1dcc1e8e 100644 --- a/examples/iteration.cpp +++ b/examples/iteration.cpp @@ -40,19 +40,19 @@ int main(int, char**) { // iterate through heroes - iteration takes less memory than `get_all` because // iteration fetches row by row once it is needed. If you break at any iteration // statement will be cleared without fetching remaining rows. - for(auto& hero: storage.iterate()) { + for (auto& hero: storage.iterate()) { cout << "hero = " << storage.dump(hero) << endl; } cout << "====" << endl; // one can iterate with custom WHERE conditions.. - for(auto& hero: storage.iterate(where(c(&MarvelHero::name) == "Thor"))) { + for (auto& hero: storage.iterate(where(c(&MarvelHero::name) == "Thor"))) { cout << "hero = " << storage.dump(hero) << endl; } cout << "Heroes with LENGTH(name) < 6 :" << endl; - for(auto& hero: storage.iterate(where(length(&MarvelHero::name) < 6))) { + for (auto& hero: storage.iterate(where(length(&MarvelHero::name) < 6))) { cout << "hero = " << storage.dump(hero) << endl; } @@ -68,7 +68,7 @@ int main(int, char**) { cout << "====" << endl; cout << "Distinct hero names:" << endl; - for(std::string name: storage.iterate(select(distinct(&MarvelHero::name)))) { + for (std::string name: storage.iterate(select(distinct(&MarvelHero::name)))) { cout << name << endl; } #endif diff --git a/examples/key_value.cpp b/examples/key_value.cpp index 7658fe1e4..48c277d8a 100644 --- a/examples/key_value.cpp +++ b/examples/key_value.cpp @@ -46,7 +46,7 @@ void setValue(const std::string& key, const std::string& value) { std::string getValue(const std::string& key) { using namespace sqlite_orm; - if(auto kv = getStorage().get_pointer(key)) { + if (auto kv = getStorage().get_pointer(key)) { return kv->value; } else { return {}; diff --git a/examples/left_and_inner_join.cpp b/examples/left_and_inner_join.cpp index 6f5e90a34..4f4aeb228 100644 --- a/examples/left_and_inner_join.cpp +++ b/examples/left_and_inner_join.cpp @@ -75,16 +75,16 @@ int main(int, char**) { left_join(on(c(&Album::artistId) == &Artist::artistId)), order_by(&Album::albumId)); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { auto& artistId = std::get<0>(row); - if(artistId) { + if (artistId) { cout << *artistId; } else { cout << "null"; } cout << '\t'; auto& albumId = std::get<1>(row); - if(albumId) { + if (albumId) { cout << *albumId; } else { cout << "null"; @@ -106,16 +106,16 @@ int main(int, char**) { left_join(on(c(&Album::artistId) == &Artist::artistId)), where(is_null(&Album::albumId))); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { auto& artistId = std::get<0>(row); - if(artistId) { + if (artistId) { cout << *artistId; } else { cout << "null"; } cout << '\t'; auto& albumId = std::get<1>(row); - if(albumId) { + if (albumId) { cout << *albumId; } else { cout << "null"; @@ -135,9 +135,9 @@ int main(int, char**) { auto innerJoinRows0 = storage.select(columns(&Track::trackId, &Track::name, &Album::title), inner_join(on(c(&Track::albumId) == &Album::albumId))); cout << "innerJoinRows0 count = " << innerJoinRows0.size() << endl; - for(auto& row: innerJoinRows0) { + for (auto& row: innerJoinRows0) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t'; - if(std::get<2>(row)) { + if (std::get<2>(row)) { cout << *std::get<2>(row); } else { cout << "null"; @@ -159,21 +159,21 @@ int main(int, char**) { storage.select(columns(&Track::trackId, &Track::name, &Track::albumId, &Album::albumId, &Album::title), inner_join(on(c(&Album::albumId) == &Track::trackId))); cout << "innerJoinRows1 count = " << innerJoinRows1.size() << endl; - for(auto& row: innerJoinRows1) { + for (auto& row: innerJoinRows1) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t'; - if(std::get<2>(row)) { + if (std::get<2>(row)) { cout << *std::get<2>(row); } else { cout << "null"; } cout << '\t'; - if(std::get<3>(row)) { + if (std::get<3>(row)) { cout << *std::get<3>(row); } else { cout << "null"; } cout << '\t'; - if(std::get<4>(row)) { + if (std::get<4>(row)) { cout << *std::get<4>(row); } else { cout << "null"; @@ -196,15 +196,15 @@ int main(int, char**) { inner_join(on(c(&Album::albumId) == &Track::albumId)), inner_join(on(c(&Artist::artistId) == &Album::artistId))); cout << "innerJoinRows2 count = " << innerJoinRows2.size() << endl; - for(auto& row: innerJoinRows2) { + for (auto& row: innerJoinRows2) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t'; - if(std::get<2>(row)) { + if (std::get<2>(row)) { cout << *std::get<2>(row); } else { cout << "null"; } cout << '\t'; - if(std::get<3>(row)) { + if (std::get<3>(row)) { cout << *std::get<3>(row); } else { cout << "null"; @@ -293,7 +293,7 @@ int main(int, char**) { // ON a.doctor_id=c.doctor_id; auto rows = storage2.select(columns(&Doctor::id, &Doctor::name, &Visit::patientName, &Visit::vdate), left_join(on(c(&Doctor::id) == &Visit::doctorId))); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -306,7 +306,7 @@ int main(int, char**) { // ON a.doctor_id=c.doctor_id; rows = storage2.select(columns(&Doctor::id, &Doctor::name, &Visit::patientName, &Visit::vdate), join(on(c(&Doctor::id) == &Visit::doctorId))); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -319,7 +319,7 @@ int main(int, char**) { // USING(doctor_id); rows = storage2.select(columns(&Doctor::id, &Doctor::name, &Visit::patientName, &Visit::vdate), left_join(using_(&Visit::doctorId))); // or using_(&Doctor::id) - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } diff --git a/examples/multi_table_select.cpp b/examples/multi_table_select.cpp index e3c1d2700..a1729bb19 100644 --- a/examples/multi_table_select.cpp +++ b/examples/multi_table_select.cpp @@ -62,7 +62,7 @@ int main(int, char**) { auto rows = storage.select( columns(&ReqEquip::reqNumber, &ReqEquip::requestor, &ReqDetail::quantity, &ReqDetail::stockNumber), where(c(&ReqEquip::reqNumber) == &ReqDetail::reqNumber)); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t'; cout << std::get<1>(row) << '\t'; cout << std::get<2>(row) << '\t'; @@ -79,7 +79,7 @@ int main(int, char**) { rows = storage.select( columns(&ReqEquip::reqNumber, &ReqEquip::requestor, &ReqDetail::quantity, &ReqDetail::stockNumber), where(c(&ReqEquip::reqNumber) == &ReqDetail::reqNumber and c(&ReqEquip::reqNumber) == 1000)); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t'; cout << std::get<1>(row) << '\t'; cout << std::get<2>(row) << '\t'; diff --git a/examples/natural_join.cpp b/examples/natural_join.cpp index f66ca2b65..3b0c3e8b1 100644 --- a/examples/natural_join.cpp +++ b/examples/natural_join.cpp @@ -74,7 +74,7 @@ int main() { natural_join(), where(c(&Doctor::degree) == "MD")); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << '\t' << std::get<4>(row) << endl; } @@ -96,7 +96,7 @@ int main() { natural_join(), where(c(&Doctor::degree) == "MD")); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << '\t' << std::get<4>(row) << '\t' << std::get<5>(row) << endl; } diff --git a/examples/nullable_enum_binding.cpp b/examples/nullable_enum_binding.cpp index bbd8f0185..7c0770e5e 100644 --- a/examples/nullable_enum_binding.cpp +++ b/examples/nullable_enum_binding.cpp @@ -20,7 +20,7 @@ enum class Gender { }; std::unique_ptr GenderToString(Gender gender) { - switch(gender) { + switch (gender) { case Gender::Female: return std::make_unique("female"); case Gender::Male: @@ -32,9 +32,9 @@ std::unique_ptr GenderToString(Gender gender) { } std::unique_ptr GenderFromString(const std::string& s) { - if(s == "female") { + if (s == "female") { return std::make_unique(Gender::Female); - } else if(s == "male") { + } else if (s == "male") { return std::make_unique(Gender::Male); } return nullptr; @@ -55,7 +55,7 @@ namespace sqlite_orm { struct statement_binder { int bind(sqlite3_stmt* stmt, int index, const Gender& value) { - if(auto str = GenderToString(value)) { + if (auto str = GenderToString(value)) { return statement_binder().bind(stmt, index, *str); } else { return statement_binder().bind(stmt, index, nullptr); @@ -66,7 +66,7 @@ namespace sqlite_orm { template<> struct field_printer { std::string operator()(const Gender& t) const { - if(auto res = GenderToString(t)) { + if (auto res = GenderToString(t)) { return *res; } else { return "None"; @@ -77,8 +77,8 @@ namespace sqlite_orm { template<> struct row_extractor { Gender extract(const char* columnText) const { - if(columnText) { - if(auto gender = GenderFromString(columnText)) { + if (columnText) { + if (auto gender = GenderFromString(columnText)) { return *gender; } else { throw std::runtime_error("incorrect gender string (" + std::string(columnText) + ")"); @@ -135,19 +135,19 @@ int main(int, char**) { }); cout << "All users :" << endl; - for(auto& user: storage.iterate()) { + for (auto& user: storage.iterate()) { cout << storage.dump(user) << endl; } auto allWithNoneGender = storage.get_all(where(is_null(&User::gender))); cout << "allWithNoneGender = " << allWithNoneGender.size() << endl; - for(auto& user: allWithNoneGender) { + for (auto& user: allWithNoneGender) { cout << storage.dump(user) << endl; } auto allWithGender = storage.get_all(where(is_not_null(&User::gender))); cout << "allWithGender = " << allWithGender.size() << endl; - for(auto& user: allWithGender) { + for (auto& user: allWithGender) { cout << storage.dump(user) << endl; } diff --git a/examples/pointer_passing_interface.cpp b/examples/pointer_passing_interface.cpp index 55a6a8039..b6032b021 100644 --- a/examples/pointer_passing_interface.cpp +++ b/examples/pointer_passing_interface.cpp @@ -127,7 +127,7 @@ int main() { // returns the category's name struct error_category_name_fn { std::string operator()(ecat_arg pv) const { - if(const error_category* ec = pv) { + if (const error_category* ec = pv) { return ec->name(); } return {}; @@ -142,7 +142,7 @@ int main() { // returns the error message struct error_category_message_fn { std::string operator()(ecat_arg pv, int errorValue) const { - if(const error_category* ec = pv) { + if (const error_category* ec = pv) { return ec->message(errorValue); } return {}; @@ -180,7 +180,7 @@ int main() { struct equal_error_code_fn { bool operator()(ecode_arg pv1, ecode_arg pv2) const { const error_code *ec1 = pv1, *ec2 = pv2; - if(ec1 && ec2) { + if (ec1 && ec2) { return *ec1 == *ec2; } return false; @@ -243,7 +243,7 @@ int main() { order_by(&Result::errorCategory), order_by(&Result::errorValue), order_by(&Result::id))); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << ' ' << std::get<1>(row) << ' ' << std::get<2>(row) << ' ' << std::get<3>(row) << ' ' << std::get<4>(row) << " \"" << std::get<5>(row) << "\"" << " \"" << std::get<6>(row) << "\"" << endl; diff --git a/examples/prepared_statement.cpp b/examples/prepared_statement.cpp index e637e72bd..f06c4ed44 100644 --- a/examples/prepared_statement.cpp +++ b/examples/prepared_statement.cpp @@ -117,7 +117,7 @@ int main() { } cout << "Doctors count = " << storage.count() << endl; - for(auto& doctor: storage.iterate()) { + for (auto& doctor: storage.iterate()) { cout << storage.dump(doctor) << endl; } @@ -134,7 +134,7 @@ int main() { } cout << "Specialities count = " << storage.count() << endl; - for(auto& speciality: storage.iterate()) { + for (auto& speciality: storage.iterate()) { cout << storage.dump(speciality) << endl; } { @@ -165,7 +165,7 @@ int main() { storage.replace(Visit{212, "Jason Mallin", "2013-10-12"}); } cout << "Visits count = " << storage.count() << endl; - for(auto& visit: storage.iterate()) { + for (auto& visit: storage.iterate()) { cout << storage.dump(visit) << endl; } { @@ -177,7 +177,7 @@ int main() { { auto rows = storage.execute(selectStatement); cout << "rows count = " << rows.size() << endl; - for(auto& id: rows) { + for (auto& id: rows) { cout << id << endl; } } @@ -190,7 +190,7 @@ int main() { get<0>(selectStatement) = 11; auto rows = storage.execute(selectStatement); cout << "rows count = " << rows.size() << endl; - for(auto& id: rows) { + for (auto& id: rows) { cout << id << endl; } } @@ -205,7 +205,7 @@ int main() { { auto rows = storage.execute(selectStatement); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << endl; } } @@ -217,7 +217,7 @@ int main() { { auto rows = storage.execute(selectStatement); cout << "rows count = " << rows.size() << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << get<0>(row) << '\t' << get<1>(row) << endl; } } diff --git a/examples/private_class_members.cpp b/examples/private_class_members.cpp index a7544be81..73d10a4ad 100644 --- a/examples/private_class_members.cpp +++ b/examples/private_class_members.cpp @@ -81,7 +81,7 @@ int main(int, char**) { auto somePlayers = storage.get_all(where(less_than(length(&Player::getName), 5))); cout << "players with length(name) < 5 = " << somePlayers.size() << endl; assert(somePlayers.size() == 1); - for(auto& player: somePlayers) { + for (auto& player: somePlayers) { cout << storage.dump(player) << endl; } } diff --git a/examples/select.cpp b/examples/select.cpp index ae2a622fc..d3bca681d 100644 --- a/examples/select.cpp +++ b/examples/select.cpp @@ -71,9 +71,9 @@ void all_employees() { // now let's select id, name and salary.. auto idsNamesSalarys = storage.select(columns(&Employee::id, &Employee::name, &Employee::salary)); - for(auto& row: idsNamesSalarys) { // row's type is `tuple>` + for (auto& row: idsNamesSalarys) { // row's type is `tuple>` cout << "id = " << get<0>(row) << ", name = " << get<1>(row) << ", salary = "; - if(get<2>(row)) { + if (get<2>(row)) { cout << *get<2>(row); } else { cout << "null"; @@ -85,16 +85,16 @@ void all_employees() { auto allEmployeeTuples = storage.select(asterisk()); cout << "allEmployeeTuples count = " << allEmployeeTuples.size() << endl; - for(auto& row: allEmployeeTuples) { // row's type is std::tuple, + for (auto& row: allEmployeeTuples) { // row's type is std::tuple, // std::unique_ptr> cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << '\t'; - if(auto& value = get<3>(row)) { + if (auto& value = get<3>(row)) { cout << *value; } else { cout << "null"; } cout << '\t'; - if(auto& value = get<4>(row)) { + if (auto& value = get<4>(row)) { cout << *value; } else { cout << "null"; @@ -106,15 +106,15 @@ void all_employees() { auto allEmployeeObjects = storage.select(object()); cout << "allEmployeeObjects count = " << allEmployeeObjects.size() << endl; - for(auto& employee: allEmployeeObjects) { + for (auto& employee: allEmployeeObjects) { cout << employee.id << '\t' << employee.name << '\t' << employee.age << '\t'; - if(auto& value = employee.address) { + if (auto& value = employee.address) { cout << *value; } else { cout << "null"; } cout << '\t'; - if(auto& value = employee.salary) { + if (auto& value = employee.salary) { cout << *value; } else { cout << "null"; @@ -156,8 +156,8 @@ void all_artists() { cout << "artists.*, albums.*\n"; // row's type is `std::tuple` - for(auto& row: storage.select(columns(asterisk(), asterisk()), - join(on(c(&Album::artist_id) == &Artist::id)))) { + for (auto& row: storage.select(columns(asterisk(), asterisk()), + join(on(c(&Album::artist_id) == &Artist::id)))) { cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << '\t' << get<3>(row) << '\n'; } cout << endl; @@ -203,7 +203,7 @@ void named_adhoc_structs() { cout << "albums.name, artists.name\n"; // row's type is Z - for(auto& row: storage.select(z_struct, join(on(c(&Album::artist_id) == &Artist::id)))) { + for (auto& row: storage.select(z_struct, join(on(c(&Album::artist_id) == &Artist::id)))) { cout << row.album_name << '\t' << row.artist_name << '\n'; } cout << endl; @@ -216,7 +216,7 @@ int main() { all_employees(); all_artists(); named_adhoc_structs(); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cout << "[" << e.code() << "] " << e.what(); } #endif diff --git a/examples/self_join.cpp b/examples/self_join.cpp index 46cdda68f..8d103a9df 100644 --- a/examples/self_join.cpp +++ b/examples/self_join.cpp @@ -216,7 +216,7 @@ int main() { employee->*&Employee::firstName || " " || employee->*&Employee::lastName), inner_join(on(m->*&Employee::reportsTo == employee->*&Employee::employeeId))); cout << "firstNames count = " << firstNames.size() << endl; - for(auto& row: firstNames) { + for (auto& row: firstNames) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl; } #else @@ -226,7 +226,7 @@ int main() { &Employee::firstName || c(" ") || &Employee::lastName), inner_join(on(alias_column(&Employee::reportsTo) == &Employee::employeeId))); cout << "firstNames count = " << firstNames.size() << endl; - for(auto& row: firstNames) { + for (auto& row: firstNames) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl; } #endif @@ -249,7 +249,7 @@ int main() { employee->*&Employee::firstName || " " || employee->*&Employee::lastName), inner_join(on(emp->*&Employee::reportsTo == employee->*&Employee::employeeId))); cout << "firstNames count = " << firstNames.size() << endl; - for(auto& row: firstNames) { + for (auto& row: firstNames) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl; } #else @@ -259,7 +259,7 @@ int main() { &Employee::firstName || c(" ") || &Employee::lastName), inner_join(on(alias_column(&Employee::reportsTo) == &Employee::employeeId))); cout << "firstNames count = " << firstNames.size() << endl; - for(auto& row: firstNames) { + for (auto& row: firstNames) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << endl; } #endif diff --git a/examples/subentities.cpp b/examples/subentities.cpp index 8894c10aa..37ab748c5 100644 --- a/examples/subentities.cpp +++ b/examples/subentities.cpp @@ -44,7 +44,7 @@ auto storage = // inserts or updates student and does the same with marks int addStudent(const Student& student) { auto studentId = student.id; - if(storage.count(where(c(&Student::id) == student.id))) { + if (storage.count(where(c(&Student::id) == student.id))) { storage.update(student); } else { studentId = storage.insert(student); @@ -52,7 +52,7 @@ int addStudent(const Student& student) { // insert all marks within a transaction storage.transaction([&] { storage.remove_all(where(c(&Mark::student_id) == studentId)); - for(auto& mark: student.marks) { + for (auto& mark: student.marks) { storage.insert(Mark{mark, studentId}); } return true; @@ -97,7 +97,7 @@ int main(int, char**) { auto mike = getStudent(mikeId); cout << "mike = " << storage.dump(mike) << endl; cout << "mike.marks = "; - for(auto& m: mike.marks) { + for (auto& m: mike.marks) { cout << m << " "; } cout << endl; @@ -105,7 +105,7 @@ int main(int, char**) { auto anna = getStudent(annaId); cout << "anna = " << storage.dump(anna) << endl; cout << "anna.marks = "; - for(auto& m: anna.marks) { + for (auto& m: anna.marks) { cout << m << " "; } cout << endl; diff --git a/examples/subquery.cpp b/examples/subquery.cpp index 451b33cd3..dad6b011c 100644 --- a/examples/subquery.cpp +++ b/examples/subquery.cpp @@ -1288,7 +1288,7 @@ int main(int, char**) { select(&Employee::salary, where(is_equal(&Employee::firstName, "Alexander")))))); cout << "first_name last_name salary" << endl; cout << "---------- ---------- ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } } @@ -1300,7 +1300,7 @@ int main(int, char**) { where(greater_than(&Employee::salary, select(avg(&Employee::salary))))); cout << "employee_id first_name last_name salary" << endl; cout << "----------- ---------- ---------- ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } @@ -1316,7 +1316,7 @@ int main(int, char**) { greater_than(&Employee::salary, select(avg(&Employee::salary))))); cout << "employee_id first_name last_name salary avg_salary salary>avg" << endl; cout << "----------- ---------- ---------- ---------- ---------- ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << '\t' << std::get<4>(row) << '\t' << std::get<5>(row) << endl; } @@ -1333,7 +1333,7 @@ int main(int, char**) { where(in(&Employee::departmentId, select(&Department::id, where(c(&Department::locationId) == 1700))))); cout << "first_name last_name department_id" << endl; cout << "---------- ---------- -------------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } } @@ -1352,7 +1352,7 @@ int main(int, char**) { select(&Department::id, where(between(&Department::managerId, 100, 200)))))); cout << "first_name last_name department_id" << endl; cout << "---------- ---------- -------------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } } @@ -1373,7 +1373,7 @@ int main(int, char**) { where(is_equal(&Employee::departmentId, e->*&Employee::departmentId)))))); cout << "last_name salary department_id" << endl; cout << "---------- ---------- -------------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } #else @@ -1390,7 +1390,7 @@ int main(int, char**) { where(is_equal(&Employee::departmentId, alias_column(&Employee::departmentId))))))); cout << "last_name salary department_id" << endl; cout << "---------- ---------- -------------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } #endif @@ -1410,7 +1410,7 @@ int main(int, char**) { where(is_equal(&Employee::id, &JobHistory::employeeId)))))); cout << "first_name last_name employee_id job_id" << endl; cout << "---------- ---------- ----------- ----------" << endl; - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << '\t' << std::get<3>(row) << endl; } diff --git a/examples/triggers.cpp b/examples/triggers.cpp index d2a2c2ca1..24810bf9e 100644 --- a/examples/triggers.cpp +++ b/examples/triggers.cpp @@ -154,7 +154,7 @@ int main() { // VALUES('John', 'Doe', 'jjj', '4089009334'); try { storage.insert(Lead{0, "John", "Doe", "jjj", "4089009334"}); - } catch(const std::system_error& systemError) { + } catch (const std::system_error& systemError) { cout << "error: " << systemError.what() << endl; } @@ -164,7 +164,7 @@ int main() { storage.insert(Lead{0, "John", "Doe", "john.doe@sqlitetutorial.net", "4089009334"}); cout << "Leads:" << endl; - for(auto& lead: storage.iterate()) { + for (auto& lead: storage.iterate()) { cout << storage.dump(lead) << endl; } @@ -185,7 +185,7 @@ int main() { cout << "Logs count = " << storage.count() << endl; - for(auto& leadLog: storage.iterate()) { + for (auto& leadLog: storage.iterate()) { cout << storage.dump(leadLog) << endl; } diff --git a/examples/union.cpp b/examples/union.cpp index 8952f5394..68b229917 100644 --- a/examples/union.cpp +++ b/examples/union.cpp @@ -89,7 +89,7 @@ int main() { std::sort(rows.begin(), rows.end(), [](auto& lhs, auto& rhs) { return std::get<0>(lhs) < std::get<0>(rhs); }); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } cout << endl; @@ -109,7 +109,7 @@ int main() { inner_join(on(is_equal(&Employee::id, &Department::employeeId)))), select(columns(&Department::employeeId, &Employee::name, &Department::dept), left_outer_join(on(is_equal(&Employee::id, &Department::employeeId)))))); - for(auto& row: rows) { + for (auto& row: rows) { cout << std::get<0>(row) << '\t' << std::get<1>(row) << '\t' << std::get<2>(row) << endl; } cout << endl; diff --git a/examples/unique.cpp b/examples/unique.cpp index aa477bb5f..59f4aefaa 100644 --- a/examples/unique.cpp +++ b/examples/unique.cpp @@ -34,7 +34,7 @@ int main(int, char**) { auto id2 = storage.insert(Entry{0, sameString, std::make_unique("I got you")}); cout << "inserted " << storage.dump(storage.get(id2)) << endl; - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { cerr << e.what() << endl; } diff --git a/examples/update.cpp b/examples/update.cpp index ed3a27342..6f24ccc8e 100644 --- a/examples/update.cpp +++ b/examples/update.cpp @@ -47,7 +47,7 @@ int main(int, char**) { stor->replace(Employee{7, "James", 24, "Houston", 10000.0}); // show 'COMPANY' table contents - for(auto& employee: stor->iterate()) { + for (auto& employee: stor->iterate()) { cout << stor->dump(employee) << endl; } cout << endl; @@ -60,7 +60,7 @@ int main(int, char**) { employee6); // actually this call updates all non-primary-key columns' values to passed object's fields // show 'COMPANY' table contents again - for(auto& employee: stor->iterate()) { + for (auto& employee: stor->iterate()) { cout << stor->dump(employee) << endl; } cout << endl; @@ -71,7 +71,7 @@ int main(int, char**) { where(c(&Employee::age) < 30)); // show 'COMPANY' table contents one more time - for(auto& employee: stor->iterate()) { + for (auto& employee: stor->iterate()) { cout << stor->dump(employee) << endl; } cout << endl; diff --git a/examples/user_defined_functions.cpp b/examples/user_defined_functions.cpp index 5c3d60314..d9ee12ee7 100644 --- a/examples/user_defined_functions.cpp +++ b/examples/user_defined_functions.cpp @@ -21,9 +21,9 @@ using std::endl; struct SignFunction { double operator()(double arg) const { - if(arg > 0) { + if (arg > 0) { return 1; - } else if(arg < 0) { + } else if (arg < 0) { return -1; } else { return 0; @@ -51,7 +51,7 @@ struct AcceleratedSumFunction { std::vector list; void step(int value) { - if(!this->list.empty()) { + if (!this->list.empty()) { auto nextValue = list.back() + value; this->list.push_back(nextValue); } else { @@ -62,9 +62,9 @@ struct AcceleratedSumFunction { std::string fin() const { std::stringstream ss; ss << "("; - for(size_t i = 0; i < this->list.size(); ++i) { + for (size_t i = 0; i < this->list.size(); ++i) { ss << this->list[i]; - if(i < (this->list.size() - 1)) { + if (i < (this->list.size() - 1)) { ss << ", "; } } @@ -93,14 +93,14 @@ struct ArithmeticMeanFunction { double operator()(const arg_values& args) const { double result = 0; - for(auto arg_value: args) { - if(arg_value.is_float()) { + for (auto arg_value: args) { + if (arg_value.is_float()) { result += arg_value.get(); - } else if(arg_value.is_integer()) { + } else if (arg_value.is_integer()) { result += arg_value.get(); } } - if(!args.empty()) { + if (!args.empty()) { result /= double(args.size()); } return result; @@ -156,7 +156,7 @@ int main() { auto aSumRows = storage.select(columns(accelerated_sum(&Table::a), accelerated_sum(&Table::b), accelerated_sum(&Table::c))); cout << "SELECT ASUM(a), ASUM(b), ASUM(c) FROM t:" << endl; - for(auto& row: aSumRows) { + for (auto& row: aSumRows) { cout << '\t' << get<0>(row) << endl; cout << '\t' << get<1>(row) << endl; cout << '\t' << get<2>(row) << endl; @@ -199,7 +199,7 @@ int main() { func(&Table::b), func(&Table::c))); cout << "SELECT ASUM(a), ASUM(b), ASUM(c) FROM t:" << endl; - for(auto& row: aSumRows) { + for (auto& row: aSumRows) { cout << '\t' << get<0>(row) << endl; cout << '\t' << get<1>(row) << endl; cout << '\t' << get<2>(row) << endl; diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index a1266c80f..14f91712e 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -692,7 +692,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED template decltype(auto) static_if([[maybe_unused]] T&& trueFn, [[maybe_unused]] F&& falseFn) { - if constexpr(B) { + if constexpr (B) { return std::forward(trueFn); } else { return std::forward(falseFn); @@ -701,7 +701,7 @@ namespace sqlite_orm { template decltype(auto) static_if([[maybe_unused]] T&& trueFn) { - if constexpr(B) { + if constexpr (B) { return std::forward(trueFn); } else { return empty_callable<>; @@ -710,7 +710,7 @@ namespace sqlite_orm { template void call_if_constexpr([[maybe_unused]] L&& lambda, [[maybe_unused]] Args&&... args) { - if constexpr(B) { + if constexpr (B) { lambda(std::forward(args)...); } } @@ -1084,7 +1084,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED constexpr size_t find_first_true_helper(std::initializer_list values) { size_t i = 0; - for(auto first = values.begin(); first != values.end() && !*first; ++first) { + for (auto first = values.begin(); first != values.end() && !*first; ++first) { ++i; } return i; @@ -1092,7 +1092,7 @@ namespace sqlite_orm { constexpr size_t count_true_helper(std::initializer_list values) { size_t n = 0; - for(auto first = values.begin(); first != values.end(); ++first) { + for (auto first = values.begin(); first != values.end(); ++first) { n += *first; } return n; @@ -1635,7 +1635,7 @@ namespace sqlite_orm { #if defined(SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED) && defined(SQLITE_ORM_IF_CONSTEXPR_SUPPORTED) template constexpr void iterate_tuple(Tpl& tpl, std::index_sequence, L&& lambda) { - if constexpr(reversed) { + if constexpr (reversed) { // nifty fold expression trick: make use of guaranteed right-to-left evaluation order when folding over operator= int sink; // note: `(void)` cast silences warning 'expression result unused' @@ -1650,7 +1650,7 @@ namespace sqlite_orm { template void iterate_tuple(Tpl& tpl, std::index_sequence, L&& lambda) { - if SQLITE_ORM_CONSTEXPR_IF(reversed) { + if SQLITE_ORM_CONSTEXPR_IF (reversed) { iterate_tuple(tpl, std::index_sequence{}, std::forward(lambda)); lambda(std::get(tpl)); } else { @@ -2263,7 +2263,7 @@ namespace sqlite_orm { * Make a table reference. */ template - requires(!orm_recordset_alias) + requires (!orm_recordset_alias) consteval internal::table_reference column() { return {}; } @@ -2272,7 +2272,7 @@ namespace sqlite_orm { * Make a table reference. */ template - requires(!orm_recordset_alias) + requires (!orm_recordset_alias) consteval internal::table_reference c() { return {}; } @@ -2297,10 +2297,10 @@ namespace sqlite_orm { static_assert(is_cte_moniker_v, "`Moniker' must be a CTE moniker"); - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { static_assert(is_column_alias_v>); return column_pointer{{}}; - } else if constexpr(is_column_alias_v) { + } else if constexpr (is_column_alias_v) { return column_pointer>{{}}; } else { return column_pointer{std::move(field)}; @@ -2498,7 +2498,7 @@ namespace sqlite_orm { template SQLITE_ORM_CONSTEVAL auto n_to_colalias() { constexpr column_alias<'1' + n % 10, C...> colalias{}; - if constexpr(n > 10) { + if constexpr (n > 10) { return n_to_colalias(); } else { return colalias; @@ -2570,16 +2570,16 @@ namespace sqlite_orm { * select(alias_column(&User::id)) */ template - requires(!orm_cte_moniker>) + requires (!orm_cte_moniker>) constexpr auto alias_column(C field) { using namespace ::sqlite_orm::internal; using A = decltype(als); using aliased_type = type_t; static_assert(is_field_of_v, "Column must be from aliased table"); - if constexpr(is_column_pointer_v) { + if constexpr (is_column_pointer_v) { return alias_column_t{std::move(field)}; - } else if constexpr(std::is_same_v, aliased_type>) { + } else if constexpr (std::is_same_v, aliased_type>) { return alias_column_t{field}; } else { // wrap in column_pointer @@ -2601,7 +2601,7 @@ namespace sqlite_orm { * select(als->*&User::id) */ template - requires(!orm_cte_moniker>) + requires (!orm_cte_moniker>) constexpr auto operator->*(const A& /*tableAlias*/, F field) { return alias_column(std::move(field)); } @@ -2620,7 +2620,7 @@ namespace sqlite_orm { using namespace ::sqlite_orm::internal; using cte_moniker_t = type_t; - if constexpr(is_column_pointer_v) { + if constexpr (is_column_pointer_v) { static_assert(std::is_same, cte_moniker_t>::value, "Column pointer must match aliased CTE"); return alias_column_t{c}; @@ -2638,7 +2638,7 @@ namespace sqlite_orm { * because recordset aliases are derived from `sqlite_orm::alias_tag` */ template - requires(orm_cte_moniker>) + requires (orm_cte_moniker>) constexpr auto operator->*(const A& /*tableAlias*/, C c) { return alias_column(std::move(c)); } @@ -2647,7 +2647,7 @@ namespace sqlite_orm { * Create a column reference to an aliased CTE column. */ template - requires(orm_cte_moniker>) + requires (orm_cte_moniker>) constexpr auto alias_column(C c) { using A = std::remove_const_t; return alias_column(std::move(c)); @@ -2878,7 +2878,7 @@ namespace sqlite_orm { } std::string message(int c) const override final { - switch(static_cast(c)) { + switch (static_cast(c)) { case orm_error_code::not_found: return "Not found"; case orm_error_code::type_is_not_mapped_to_storage: @@ -3375,7 +3375,7 @@ namespace sqlite_orm { }; inline std::ostream& operator<<(std::ostream& os, foreign_key_action action) { - switch(action) { + switch (action) { case foreign_key_action::no_action: os << "NO ACTION"; break; @@ -3401,7 +3401,7 @@ namespace sqlite_orm { const bool update; // true if update and false if delete operator std::string() const { - if(this->update) { + if (this->update) { return "ON UPDATE"; } else { return "ON DELETE"; @@ -3425,7 +3425,7 @@ namespace sqlite_orm { foreign_key_type no_action() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::no_action; } else { res.on_delete._action = foreign_key_action::no_action; @@ -3435,7 +3435,7 @@ namespace sqlite_orm { foreign_key_type restrict_() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::restrict_; } else { res.on_delete._action = foreign_key_action::restrict_; @@ -3445,7 +3445,7 @@ namespace sqlite_orm { foreign_key_type set_null() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::set_null; } else { res.on_delete._action = foreign_key_action::set_null; @@ -3455,7 +3455,7 @@ namespace sqlite_orm { foreign_key_type set_default() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::set_default; } else { res.on_delete._action = foreign_key_action::set_default; @@ -3465,7 +3465,7 @@ namespace sqlite_orm { foreign_key_type cascade() const { auto res = this->fk; - if(update) { + if (update) { res.on_update._action = foreign_key_action::cascade; } else { res.on_delete._action = foreign_key_action::cascade; @@ -3566,7 +3566,7 @@ namespace sqlite_orm { } static std::string string_from_collate_argument(collate_argument argument) { - switch(argument) { + switch (argument) { case collate_argument::binary: return "BINARY"; case collate_argument::nocase: @@ -3923,7 +3923,7 @@ namespace sqlite_orm { std::string operator()(const std::vector& t) const { std::stringstream ss; ss << std::hex; - for(auto c: t) { + for (auto c: t) { ss << c; } return ss.str(); @@ -3963,7 +3963,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; std::string operator()(const T& t) const { - if(t) { + if (t) { return field_printer()(*t); } else { return field_printer{}(nullptr); @@ -3980,7 +3980,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; std::string operator()(const T& t) const { - if(t.has_value()) { + if (t.has_value()) { return field_printer()(*t); } else { return field_printer{}(std::nullopt); @@ -7786,7 +7786,7 @@ namespace sqlite_orm { internal::field_type_or_type_t>>, bool> = true> auto nullif(X x, Y y) { - if constexpr(std::is_void_v) { + if constexpr (std::is_void_v) { using F = internal::built_in_function_t< std::optional, internal::field_type_or_type_t>>, internal::nullif_string, @@ -8290,10 +8290,10 @@ namespace sqlite_orm { */ #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires((is_column_alias_v || std::is_member_pointer_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((is_column_alias_v || std::is_member_pointer_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto operator()(ExplicitCols... explicitColumns) const; #else templateall) { + if (!this->all) { return "UNION"; } else { return "UNION ALL"; @@ -8868,7 +8868,7 @@ namespace sqlite_orm { with_t(bool recursiveIndicated, cte_type cte, expression_type expression) : recursiveIndicated{recursiveIndicated}, cte{std::move(cte)}, expression{std::move(expression)} { - if constexpr(is_select_v) { + if constexpr (is_select_v) { this->expression.highest_level = true; } } @@ -9144,11 +9144,11 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires((internal::is_column_alias_v || std::is_member_pointer_v || - internal::is_column_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((internal::is_column_alias_v || std::is_member_pointer_v || + internal::is_column_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto cte(ExplicitCols... explicitColumns) { using namespace ::sqlite_orm::internal; static_assert((!is_builtin_numeric_column_alias_v && ...), @@ -9164,10 +9164,10 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template template - requires((is_column_alias_v || std::is_member_pointer_v || - std::same_as> || - std::convertible_to) && - ...) + requires ((is_column_alias_v || std::is_member_pointer_v || + std::same_as> || + std::convertible_to) && + ...) constexpr auto cte_moniker::operator()(ExplicitCols... explicitColumns) const { return cte>(std::forward(explicitColumns)...); } @@ -9535,7 +9535,7 @@ namespace sqlite_orm { * it doesn't check so explicitly, but a compiler error will occur. */ template - requires(!integral_fp_c) + requires (!integral_fp_c) void xdestroy_proxy(void* p) noexcept { // C-casting `void* -> P*` like statement_binder> auto o = (P*)p; @@ -9600,7 +9600,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D, P* = nullptr) noexcept - requires(internal::is_unusable_for_xdestroy) + requires (internal::is_unusable_for_xdestroy) { static_assert(polyfill::always_false_v, "A function pointer, which is not of type xdestroy_fn_t, is prohibited."); @@ -9621,7 +9621,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D, P* = nullptr) noexcept - requires(internal::needs_xdestroy_proxy) + requires (internal::needs_xdestroy_proxy) { return internal::xdestroy_proxy; } @@ -9642,7 +9642,7 @@ namespace sqlite_orm { */ template constexpr xdestroy_fn_t obtain_xdestroy_for(D d, P* = nullptr) noexcept - requires(internal::yields_xdestroy) + requires (internal::yields_xdestroy) { return d; } @@ -9805,8 +9805,8 @@ namespace sqlite_orm { p_{std::exchange(other.p_, nullptr)}, d_{std::move(other.d_)} {} ~pointer_binding() { - if(p_) { - if(auto xDestroy = get_xdestroy()) { + if (p_) { + if (auto xDestroy = get_xdestroy()) { // note: C-casting `P* -> void*` like statement_binder> xDestroy((void*)p_); } @@ -10178,7 +10178,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; int bind(sqlite3_stmt* stmt, int index, const V& value) const { - if(value) { + if (value) { return statement_binder().bind(stmt, index, *value); } else { return statement_binder().bind(stmt, index, nullptr); @@ -10192,7 +10192,7 @@ namespace sqlite_orm { template<> struct statement_binder, void> { int bind(sqlite3_stmt* stmt, int index, const std::vector& value) const { - if(!value.empty()) { + if (!value.empty()) { return sqlite3_bind_blob(stmt, index, (const void*)&value.front(), int(value.size()), SQLITE_TRANSIENT); } else { return sqlite3_bind_blob(stmt, index, "", 0, SQLITE_TRANSIENT); @@ -10200,7 +10200,7 @@ namespace sqlite_orm { } void result(sqlite3_context* context, const std::vector& value) const { - if(!value.empty()) { + if (!value.empty()) { sqlite3_result_blob(context, (const void*)&value.front(), int(value.size()), nullptr); } else { sqlite3_result_blob(context, "", 0, nullptr); @@ -10216,7 +10216,7 @@ namespace sqlite_orm { using unqualified_type = std::remove_cv_t; int bind(sqlite3_stmt* stmt, int index, const V& value) const { - if(value) { + if (value) { return statement_binder().bind(stmt, index, *value); } else { return statement_binder().bind(stmt, index, std::nullopt); @@ -10236,7 +10236,7 @@ namespace sqlite_orm { template = true> void operator()(const T& t) { int rc = statement_binder{}.bind(this->stmt, this->index++, t); - if(SQLITE_OK != rc) { + if (SQLITE_OK != rc) { throw_translated_sqlite_error(this->stmt); } } @@ -10254,7 +10254,7 @@ namespace sqlite_orm { template void operator()(const T* value) { - if(!value) { + if (!value) { throw std::system_error{orm_error_code::value_is_null}; } (*this)(*value); @@ -10290,14 +10290,14 @@ namespace sqlite_orm { template void bind(const T& t, size_t idx) const { int rc = statement_binder{}.bind(this->stmt, int(idx + 1), t); - if(SQLITE_OK != rc) { + if (SQLITE_OK != rc) { throw_translated_sqlite_error(this->stmt); } } template void bind(const T* value, size_t idx) const { - if(!value) { + if (!value) { throw std::system_error{orm_error_code::value_is_null}; } (*this)(*value, idx); @@ -10955,7 +10955,7 @@ namespace sqlite_orm { #ifdef SQLITE_ORM_WITH_CPP20_ALIASES template - requires(std::is_function_v) + requires (std::is_function_v) struct callable_arguments_impl { using args_tuple = function_arguments; using return_type = std::decay_t>; @@ -10986,7 +10986,7 @@ namespace sqlite_orm { * Bundle of type and name of a traditional sqlite_orm user-defined function. */ template - requires(requires { UDF::name(); }) + requires (requires { UDF::name(); }) struct udf_holder #else /* @@ -11213,7 +11213,7 @@ namespace sqlite_orm { * Return original `udf` if stateless or a copy of it otherwise */ constexpr decltype(auto) callable() const { - if constexpr(stateless) { + if constexpr (stateless) { return (this->udf); } else { // non-const copy @@ -11255,7 +11255,7 @@ namespace sqlite_orm { * From a classic function object instance. */ template - requires(orm_classic_function_object && (stateless || std::copy_constructible)) + requires (orm_classic_function_object && (stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(F callable) const { using Sig = function_signature_type_t; // detect whether overloaded call operator can be picked using `Sig` @@ -11267,7 +11267,7 @@ namespace sqlite_orm { * From a function object instance, picking the overloaded call operator. */ template - requires((stateless || std::copy_constructible)) + requires ((stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(F callable) const { // detect whether overloaded call operator can be picked using `Sig` using call_operator_type = decltype(static_cast(&F::operator())); @@ -11278,7 +11278,7 @@ namespace sqlite_orm { * From a classic function object type. */ template - requires(stateless || std::copy_constructible) + requires (stateless || std::copy_constructible) [[nodiscard]] consteval auto quote(Args&&... constructorArgs) const { using Sig = function_signature_type_t; return quoted_scalar_function{this->cstr, std::forward(constructorArgs)...}; @@ -11288,7 +11288,7 @@ namespace sqlite_orm { * From a function object type, picking the overloaded call operator. */ template - requires((stateless || std::copy_constructible)) + requires ((stateless || std::copy_constructible)) [[nodiscard]] consteval auto quote(Args&&... constructorArgs) const { // detect whether overloaded call operator can be picked using `Sig` using call_operator_type = decltype(static_cast(&F::operator())); @@ -11314,7 +11314,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_WITH_CPP20_ALIASES - requires(orm_scalar_udf || orm_aggregate_udf) + requires (orm_scalar_udf || orm_aggregate_udf) #endif SQLITE_ORM_INLINE_VAR constexpr internal::function func{}; @@ -11752,7 +11752,7 @@ namespace sqlite_orm { }; inline std::ostream& operator<<(std::ostream& os, sync_schema_result value) { - switch(value) { + switch (value) { case sync_schema_result::new_table_created: return os << "new table created"; case sync_schema_result::already_in_sync: @@ -12153,7 +12153,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with_field_type{}, call_as_template_base([&res, &memberPointer, &object](const auto& column) { - if(compare_any(column.setter, memberPointer)) { + if (compare_any(column.setter, memberPointer)) { res = &polyfill::invoke(column.member_pointer, object); } })); @@ -12167,7 +12167,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with{}, [&result, &name](auto& column) { - if(column.name != name) { + if (column.name != name) { return; } using generated_op_index_sequence = @@ -12202,7 +12202,7 @@ namespace sqlite_orm { std::vector primary_key_column_names() const { using pkcol_index_sequence = col_index_sequence_with; - if(pkcol_index_sequence::size() > 0) { + if (pkcol_index_sequence::size() > 0) { return create_from_tuple>(this->elements, pkcol_index_sequence{}, &column_identifier::name); @@ -12227,8 +12227,8 @@ namespace sqlite_orm { std::vector composite_key_columns_names(const primary_key_t& primaryKey) const { return create_from_tuple>(primaryKey.columns, [this, empty = std::string{}](auto& memberPointer) { - if(const std::string* columnName = - this->find_column_name(memberPointer)) { + if (const std::string* columnName = + this->find_column_name(memberPointer)) { return *columnName; } else { return empty; @@ -12247,7 +12247,7 @@ namespace sqlite_orm { iterate_tuple(this->elements, col_index_sequence_with_field_type{}, [&res, m](auto& c) { - if(compare_any(c.member_pointer, m) || compare_any(c.setter, m)) { + if (compare_any(c.member_pointer, m) || compare_any(c.setter, m)) { res = &c.name; } }); @@ -12412,7 +12412,8 @@ namespace sqlite_orm { check_if_is_type>::template fn, member_field_type_t>; iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) { - if(compare_any(memberPointer, column.member_pointer) || compare_any(memberPointer, column.setter)) { + if (compare_any(memberPointer, column.member_pointer) || + compare_any(memberPointer, column.setter)) { res = true; } }); @@ -12667,16 +12668,16 @@ namespace sqlite_orm { std::ranges::transform(string, string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - if(auto found = std::ranges::find(journalModes, string, journal_mode_to_string); - found != journalModes.end()) SQLITE_ORM_CPP_LIKELY { + if (auto found = std::ranges::find(journalModes, string, journal_mode_to_string); + found != journalModes.end()) SQLITE_ORM_CPP_LIKELY { return {true, *found}; } #else std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - for(auto journalMode: journalModes) { - if(journal_mode_to_string(journalMode) == string) { + for (auto journalMode: journalModes) { + if (journal_mode_to_string(journalMode) == string) { return {true, journalMode}; } } @@ -12768,16 +12769,16 @@ namespace sqlite_orm { std::ranges::transform(string, string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - if(auto found = std::ranges::find(lockingModes, string, locking_mode_to_string); - found != lockingModes.end()) SQLITE_ORM_CPP_LIKELY { + if (auto found = std::ranges::find(lockingModes, string, locking_mode_to_string); + found != lockingModes.end()) SQLITE_ORM_CPP_LIKELY { return {true, *found}; } #else std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c) noexcept { return std::toupper(c); }); - for(auto lockingMode: lockingModes) { - if(locking_mode_to_string(lockingMode) == string) { + for (auto lockingMode: lockingModes) { + if (locking_mode_to_string(lockingMode) == string) { return {true, lockingMode}; } } @@ -12850,7 +12851,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif row_extractor column_text_extractor() { return {}; @@ -12861,7 +12862,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif row_extractor row_value_extractor() { return {}; @@ -12872,7 +12873,7 @@ namespace sqlite_orm { */ template #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif row_extractor boxed_value_extractor() { return {}; @@ -12882,7 +12883,7 @@ namespace sqlite_orm { template int extract_single_value(void* data, int argc, char** argv, char**) { auto& res = *(R*)data; - if(argc) { + if (argc) { const auto rowExtractor = internal::column_text_extractor(); res = rowExtractor.extract(argv[0]); } @@ -12979,7 +12980,7 @@ namespace sqlite_orm { template struct row_extractor::value>> { T extract(const char* columnText) const { - if(columnText) { + if (columnText) { return columnText; } else { return {}; @@ -12987,7 +12988,7 @@ namespace sqlite_orm { } T extract(sqlite3_stmt* stmt, int columnIndex) const { - if(auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex)) { + if (auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex)) { return cStr; } else { return {}; @@ -12995,7 +12996,7 @@ namespace sqlite_orm { } T extract(sqlite3_value* value) const { - if(auto cStr = (const char*)sqlite3_value_text(value)) { + if (auto cStr = (const char*)sqlite3_value_text(value)) { return cStr; } else { return {}; @@ -13009,7 +13010,7 @@ namespace sqlite_orm { template<> struct row_extractor { std::wstring extract(const char* columnText) const { - if(columnText) { + if (columnText) { std::wstring_convert> converter; return converter.from_bytes(columnText); } else { @@ -13019,7 +13020,7 @@ namespace sqlite_orm { std::wstring extract(sqlite3_stmt* stmt, int columnIndex) const { auto cStr = (const char*)sqlite3_column_text(stmt, columnIndex); - if(cStr) { + if (cStr) { std::wstring_convert> converter; return converter.from_bytes(cStr); } else { @@ -13028,7 +13029,7 @@ namespace sqlite_orm { } std::wstring extract(sqlite3_value* value) const { - if(auto cStr = (const wchar_t*)sqlite3_value_text16(value)) { + if (auto cStr = (const wchar_t*)sqlite3_value_text16(value)) { return cStr; } else { return {}; @@ -13043,10 +13044,10 @@ namespace sqlite_orm { V extract(const char* columnText) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif { - if(columnText) { + if (columnText) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(columnText)); } else { @@ -13056,11 +13057,11 @@ namespace sqlite_orm { V extract(sqlite3_stmt* stmt, int columnIndex) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif { auto type = sqlite3_column_type(stmt, columnIndex); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(stmt, columnIndex)); } else { @@ -13070,11 +13071,11 @@ namespace sqlite_orm { V extract(sqlite3_value* value) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif { auto type = sqlite3_value_type(value); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return is_std_ptr::make(rowExtractor.extract(value)); } else { @@ -13090,10 +13091,10 @@ namespace sqlite_orm { V extract(const char* columnText) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_column_text_extractable) + requires (orm_column_text_extractable) #endif { - if(columnText) { + if (columnText) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(columnText)); } else { @@ -13103,11 +13104,11 @@ namespace sqlite_orm { V extract(sqlite3_stmt* stmt, int columnIndex) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_row_value_extractable) + requires (orm_row_value_extractable) #endif { auto type = sqlite3_column_type(stmt, columnIndex); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(stmt, columnIndex)); } else { @@ -13117,11 +13118,11 @@ namespace sqlite_orm { V extract(sqlite3_value* value) const #ifdef SQLITE_ORM_CPP20_CONCEPTS_SUPPORTED - requires(orm_boxed_value_extractable) + requires (orm_boxed_value_extractable) #endif { auto type = sqlite3_value_type(value); - if(type != SQLITE_NULL) { + if (type != SQLITE_NULL) { const row_extractor rowExtractor{}; return std::make_optional(rowExtractor.extract(value)); } else { @@ -13173,9 +13174,9 @@ namespace sqlite_orm { template<> struct row_extractor { locking_mode extract(const char* columnText) const { - if(columnText) { + if (columnText) { auto resultPair = internal::locking_mode_from_string(columnText); - if(resultPair.first) { + if (resultPair.first) { return resultPair.second; } else { throw std::system_error{orm_error_code::incorrect_locking_mode_string}; @@ -13199,9 +13200,9 @@ namespace sqlite_orm { template<> struct row_extractor { journal_mode extract(const char* columnText) const { - if(columnText) { + if (columnText) { auto resultPair = internal::journal_mode_from_string(columnText); - if(resultPair.first) { + if (resultPair.first) { return resultPair.second; } else { throw std::system_error{orm_error_code::incorrect_journal_mode_string}; @@ -13234,8 +13235,8 @@ namespace sqlite_orm { */ template auto make_row_extractor([[maybe_unused]] const DBOs& dbObjects) { - if constexpr(polyfill::is_specialization_of_v || - polyfill::is_specialization_of_v || is_table_reference_v) { + if constexpr (polyfill::is_specialization_of_v || + polyfill::is_specialization_of_v || is_table_reference_v) { return struct_extractor{dbObjects}; } else { return row_value_extractor(); @@ -13474,7 +13475,7 @@ namespace sqlite_orm { * @param char2Escape The character to escape */ inline std::string sql_escape(std::string str, char char2Escape) { - for(size_t pos = 0; (pos = str.find(char2Escape, pos)) != str.npos; pos += 2) { + for (size_t pos = 0; (pos = str.find(char2Escape, pos)) != str.npos; pos += 2) { str.replace(pos, 1, 2, char2Escape); } @@ -13518,7 +13519,7 @@ namespace sqlite_orm { // note: query is deliberately taken by value, such that it is thrown away early inline sqlite3_stmt* prepare_stmt(sqlite3* db, std::string query) { sqlite3_stmt* stmt; - if(sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { + if (sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { throw_translated_sqlite_error(db); } return stmt; @@ -13526,7 +13527,7 @@ namespace sqlite_orm { inline void perform_void_exec(sqlite3* db, const std::string& query) { int rc = sqlite3_exec(db, query.c_str(), nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -13536,7 +13537,7 @@ namespace sqlite_orm { int (*callback)(void* data, int argc, char** argv, char**), void* user_data) { int rc = sqlite3_exec(db, query, callback, user_data, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -13551,14 +13552,14 @@ namespace sqlite_orm { template void perform_step(sqlite3_stmt* stmt) { int rc = sqlite3_step(stmt); - if(rc != expected) { + if (rc != expected) { throw_translated_sqlite_error(stmt); } } template void perform_step(sqlite3_stmt* stmt, L&& lambda) { - switch(int rc = sqlite3_step(stmt)) { + switch (int rc = sqlite3_step(stmt)) { case SQLITE_ROW: { lambda(stmt); } break; @@ -13574,7 +13575,7 @@ namespace sqlite_orm { void perform_steps(sqlite3_stmt* stmt, L&& lambda) { int rc; do { - switch(rc = sqlite3_step(stmt)) { + switch (rc = sqlite3_step(stmt)) { case SQLITE_ROW: { lambda(stmt); } break; @@ -13584,7 +13585,7 @@ namespace sqlite_orm { throw_translated_sqlite_error(stmt); } } - } while(rc != SQLITE_DONE); + } while (rc != SQLITE_DONE); } } } @@ -13634,7 +13635,7 @@ namespace sqlite_orm { void step() { perform_step(this->stmt.get(), std::bind(&mapped_iterator::extract_object, this)); - if(!this->current) { + if (!this->current) { this->stmt.reset(); } } @@ -13658,7 +13659,7 @@ namespace sqlite_orm { mapped_iterator& operator=(mapped_iterator&&) = default; value_type& operator*() const { - if(!this->stmt) SQLITE_ORM_CPP_UNLIKELY { + if (!this->stmt) SQLITE_ORM_CPP_UNLIKELY { throw std::system_error{orm_error_code::trying_to_dereference_null_iterator}; } return *this->current; @@ -13745,18 +13746,18 @@ namespace sqlite_orm { connection_holder(std::string filename_) : filename(std::move(filename_)) {} void retain() { - if(1 == ++this->_retain_count) { + if (1 == ++this->_retain_count) { auto rc = sqlite3_open(this->filename.c_str(), &this->db); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } } void release() { - if(0 == --this->_retain_count) { + if (0 == --this->_retain_count) { auto rc = sqlite3_close(this->db); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -13788,7 +13789,7 @@ namespace sqlite_orm { // rebind connection reference connection_ref& operator=(const connection_ref& other) { - if(other.holder != this->holder) { + if (other.holder != this->holder) { this->holder->release(); this->holder = other.holder; this->holder->retain(); @@ -14008,7 +14009,7 @@ namespace sqlite_orm { template void operator()(const count_asterisk_t&) { auto tableName = lookup_table_name(this->db_objects); - if(!tableName.empty()) { + if (!tableName.empty()) { this->table_names.emplace(std::move(tableName), ""); } } @@ -14173,7 +14174,7 @@ namespace sqlite_orm { std::string sql() const { // note: sqlite3 internally checks for null before calling // sqlite3_normalized_sql() or sqlite3_expanded_sql(), so check here, too, even if superfluous - if(const char* sql = sqlite3_sql(this->stmt)) { + if (const char* sql = sqlite3_sql(this->stmt)) { return sql; } else { return {}; @@ -14184,7 +14185,7 @@ namespace sqlite_orm { std::string expanded_sql() const { // note: must check return value due to SQLITE_OMIT_TRACE using char_ptr = std::unique_ptr>; - if(char_ptr sql{sqlite3_expanded_sql(this->stmt)}) { + if (char_ptr sql{sqlite3_expanded_sql(this->stmt)}) { return sql.get(); } else { return {}; @@ -14193,7 +14194,7 @@ namespace sqlite_orm { #endif #if SQLITE_VERSION_NUMBER >= 3026000 and defined(SQLITE_ENABLE_NORMALIZE) std::string normalized_sql() const { - if(const char* sql = sqlite3_normalized_sql(this->stmt)) { + if (const char* sql = sqlite3_normalized_sql(this->stmt)) { return sql; } else { return {}; @@ -15242,7 +15243,7 @@ namespace sqlite_orm { template void operator()(const node_type& vec, L& lambda) const { - for(auto& i: vec) { + for (auto& i: vec) { iterate_ast(i, lambda); } } @@ -16114,10 +16115,10 @@ namespace sqlite_orm { std::string serialize_order_by(const T&, const Ctx&); inline void stream_sql_escaped(std::ostream& os, serialize_arg_type str, char char2Escape) { - for(size_t offset = 0, next; true; offset = next + 1) { + for (size_t offset = 0, next; true; offset = next + 1) { next = str.find(char2Escape, offset); - if(next == str.npos) SQLITE_ORM_CPP_LIKELY { + if (next == str.npos) SQLITE_ORM_CPP_LIKELY { os.write(str.data() + offset, str.size() - offset); break; } @@ -16138,7 +16139,7 @@ namespace sqlite_orm { // note: In practice, escaping double quotes in identifiers is arguably overkill, // but since the SQLite grammar allows it, it's better to be safe than sorry. - if(!qualifier.empty()) { + if (!qualifier.empty()) { ss << quoteChar; stream_sql_escaped(ss, qualifier, quoteChar); ss << qualified; @@ -16148,7 +16149,7 @@ namespace sqlite_orm { stream_sql_escaped(ss, identifier, quoteChar); ss << quoteChar; } - if(!alias.empty()) { + if (!alias.empty()) { ss << aliased; stream_sql_escaped(ss, alias, quoteChar); ss << quoteChar; @@ -16275,7 +16276,7 @@ namespace sqlite_orm { auto& context = std::get<3>(tpl); iterate_tuple(args, [&ss, &opString, &context, first = true](auto& arg) mutable { - if(!std::exchange(first, false)) { + if (!std::exchange(first, false)) { ss << ' ' << opString << ' '; } ss << serialize(arg, context); @@ -16309,7 +16310,7 @@ namespace sqlite_orm { static constexpr std::array sep = {", ", ""}; bool first = true; - for(auto& argument: args) { + for (auto& argument: args) { ss << sep[std::exchange(first, false)] << serialize(argument, context); } return ss; @@ -16322,7 +16323,7 @@ namespace sqlite_orm { const auto& strings = std::get<1>(tpl); static constexpr std::array sep = {", ", ""}; - for(size_t i = 0, first = true; i < strings.size(); ++i) { + for (size_t i = 0, first = true; i < strings.size(); ++i) { ss << sep[std::exchange(first, false)] << strings[i]; } return ss; @@ -16352,7 +16353,7 @@ namespace sqlite_orm { static constexpr std::array sep = {", ", ""}; bool first = true; - for(auto& identifier: identifiers) { + for (auto& identifier: identifiers) { ss << sep[std::exchange(first, false)]; stream_identifier(ss, identifier); } @@ -16366,7 +16367,7 @@ namespace sqlite_orm { const size_t& columnsCount = std::get<1>(tpl); const ptrdiff_t& valuesCount = std::get<2>(tpl); - if(!valuesCount || !columnsCount) { + if (!valuesCount || !columnsCount) { return ss; } @@ -16374,10 +16375,10 @@ namespace sqlite_orm { result.reserve((1 + (columnsCount * 1) + (columnsCount * 2 - 2) + 1) * valuesCount + (valuesCount * 2 - 2)); static constexpr std::array sep = {", ", ""}; - for(ptrdiff_t i = 0, first = true; i < valuesCount; ++i) { + for (ptrdiff_t i = 0, first = true; i < valuesCount; ++i) { result += sep[std::exchange(first, false)]; result += "("; - for(size_t i = 0, first = true; i < columnsCount; ++i) { + for (size_t i = 0, first = true; i < columnsCount; ++i) { result += sep[std::exchange(first, false)]; result += "?"; } @@ -16435,7 +16436,7 @@ namespace sqlite_orm { table.template for_each_column_excluding(call_as_template_base( [&ss, &excluded, &context, &object, first = true](auto& column) mutable { - if(excluded(column)) { + if (excluded(column)) { return; } @@ -16456,7 +16457,7 @@ namespace sqlite_orm { iterate_tuple(columns, [&ss, &context, first = true](auto& colRef) mutable { const std::string* columnName = find_column_name(context.db_objects, colRef); - if(!columnName) { + if (!columnName) { throw std::system_error{orm_error_code::column_not_found}; } @@ -16498,12 +16499,12 @@ namespace sqlite_orm { ss << ' ' << serialize(constraint, context); }); // add implicit null constraint - if(!context.fts5_columns) { + if (!context.fts5_columns) { constexpr bool hasExplicitNullableConstraint = mpl::invoke_t, check_if_has_type>, constraints_tuple>::value; - if SQLITE_ORM_CONSTEXPR_IF(!hasExplicitNullableConstraint) { - if(isNotNull) { + if SQLITE_ORM_CONSTEXPR_IF (!hasExplicitNullableConstraint) { + if (isNotNull) { ss << " NOT NULL"; } else { ss << " NULL"; @@ -16531,7 +16532,7 @@ namespace sqlite_orm { auto& res = *(std::vector*)data; res.reserve(argc); const auto rowExtractor = column_text_extractor(); - for(int i = 0; i < argc; ++i) { + for (int i = 0; i < argc; ++i) { auto rowString = rowExtractor.extract(argv[i]); res.push_back(std::move(rowString)); } @@ -16664,7 +16665,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char**) -> int { auto& res = *(std::vector*)data; - if(argc) { + if (argc) { auto index = 0; auto cid = atoi(argv[index++]); std::string name = argv[index++]; @@ -16701,7 +16702,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char**) -> int { auto& res = *(std::vector*)data; - if(argc) { + if (argc) { auto index = 0; auto cid = atoi(argv[index++]); std::string name = argv[index++]; @@ -16758,7 +16759,7 @@ namespace sqlite_orm { void set_pragma_impl(const std::string& query, sqlite3* db = nullptr) { auto con = this->get_connection(); - if(db == nullptr) { + if (db == nullptr) { db = con.get(); } perform_void_exec(db, query); @@ -16948,8 +16949,8 @@ namespace sqlite_orm { } ~transaction_guard_t() noexcept(false) { - if(this->gotta_fire) { - if(this->commit_on_destroy) { + if (this->gotta_fire) { + if (this->commit_on_destroy) { this->commit_func(); } else { this->rollback_func(); @@ -17022,7 +17023,7 @@ namespace sqlite_orm { std::unique_ptr holder_) : handle(sqlite3_backup_init(to_.get(), zDestName.c_str(), from_.get(), zSourceName.c_str())), holder(std::move(holder_)), to(to_), from(from_) { - if(!this->handle) { + if (!this->handle) { throw std::system_error{orm_error_code::failed_to_init_a_backup}; } } @@ -17032,7 +17033,7 @@ namespace sqlite_orm { from(other.from) {} ~backup_t() { - if(this->handle) { + if (this->handle) { (void)sqlite3_backup_finish(this->handle); } } @@ -17146,7 +17147,7 @@ namespace sqlite_orm { iterator& operator++() { ++this->index; - if(this->index < int(this->container.size())) { + if (this->index < int(this->container.size())) { this->currentValue = this->container[this->index]; } else { this->currentValue = {}; @@ -17157,7 +17158,7 @@ namespace sqlite_orm { iterator operator++(int) { auto res = *this; ++this->index; - if(this->index < int(this->container.size())) { + if (this->index < int(this->container.size())) { this->currentValue = this->container[this->index]; } else { this->currentValue = {}; @@ -17166,7 +17167,7 @@ namespace sqlite_orm { } arg_value operator*() const { - if(this->index < int(this->container.size()) && this->index >= 0) { + if (this->index < int(this->container.size()) && this->index >= 0) { return this->currentValue; } else { throw std::system_error{orm_error_code::index_is_out_of_bounds}; @@ -17204,7 +17205,7 @@ namespace sqlite_orm { } arg_value operator[](int index) const { - if(index < this->argsCount && index >= 0) { + if (index < this->argsCount && index >= 0) { sqlite3_value* value = this->values[index]; return {value}; } else { @@ -17380,11 +17381,11 @@ namespace sqlite_orm { ~udf_proxy() { // destruct - if(/*bool aprioriConstructed = */ !constructAt && destroy) { + if (/*bool aprioriConstructed = */ !constructAt && destroy) { destroy(udfMemorySpace.first); } // deallocate - if(udfMemorySpace.second) { + if (udfMemorySpace.second) { udfMemorySpace.second(udfMemorySpace.first); } } @@ -17428,12 +17429,12 @@ namespace sqlite_orm { inline void* ensure_aggregate_udf(sqlite3_context* context, udf_proxy* proxy, int argsCount) { // reserve memory for storing a void pointer (which is the `udfHandle`, i.e. address of the aggregate function object) void* ctxMemory = sqlite3_aggregate_context(context, sizeof(void*)); - if(!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { + if (!ctxMemory) SQLITE_ORM_CPP_UNLIKELY { throw std::bad_alloc(); } void*& udfHandle = *static_cast(ctxMemory); - if(udfHandle) SQLITE_ORM_CPP_LIKELY { + if (udfHandle) SQLITE_ORM_CPP_LIKELY { return udfHandle; } else { assert_args_count(proxy, argsCount); @@ -17489,7 +17490,7 @@ namespace sqlite_orm { try { // note: it is possible that the 'step' function was never called udfHandle = ensure_aggregate_udf(context, proxy, -1); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc&) { sqlite3_result_error_nomem(context); return; } @@ -17639,7 +17640,7 @@ namespace sqlite_orm { ss.str(), [](void* data, int argc, char** argv, char** /*azColName*/) -> int { auto& res = *(bool*)data; - if(argc) { + if (argc) { res = !!atoi(argv[0]); } return 0; @@ -17651,8 +17652,8 @@ namespace sqlite_orm { void add_generated_cols(std::vector& columnsToAdd, const std::vector& storageTableInfo) { // iterate through storage columns - for(const table_xinfo& storageColumnInfo: storageTableInfo) { - if(storageColumnInfo.hidden) { + for (const table_xinfo& storageColumnInfo: storageTableInfo) { + if (storageColumnInfo.hidden) { columnsToAdd.push_back(&storageColumnInfo); } } @@ -17739,8 +17740,8 @@ namespace sqlite_orm { "SELECT name FROM sqlite_master WHERE type='table'", [](void* data, int argc, char** argv, char** /*columnName*/) -> int { auto& tableNames_ = *(data_t*)data; - for(int i = 0; i < argc; ++i) { - if(argv[i]) { + for (int i = 0; i < argc; ++i) { + if (argv[i]) { tableNames_.emplace_back(argv[i]); } } @@ -17763,7 +17764,7 @@ namespace sqlite_orm { void open_forever() { this->isOpenedForever = true; this->connection->retain(); - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } } @@ -17860,7 +17861,7 @@ namespace sqlite_orm { nullptr, std::pair{nullptr, null_xdestroy_f}); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_scalar_function(db, this->scalarFunctions.back()); } @@ -17994,24 +17995,24 @@ namespace sqlite_orm { void create_collation(const std::string& name, collating_function f) { const auto functionExists = bool(f); collating_function* function = nullptr; - if(functionExists) { + if (functionExists) { function = &(collatingFunctions[name] = std::move(f)); } // create collations if db is open - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); int rc = sqlite3_create_collation(db, name.c_str(), SQLITE_UTF8, function, functionExists ? collate_callback : nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } - if(!functionExists) { + if (!functionExists) { collatingFunctions.erase(name); } } @@ -18043,7 +18044,7 @@ namespace sqlite_orm { sqlite3* db = this->connection->get(); perform_void_exec(db, "COMMIT"); this->connection->release(); - if(this->connection->retain_count() < 0) { + if (this->connection->retain_count() < 0) { throw std::system_error{orm_error_code::no_active_transaction}; } } @@ -18052,7 +18053,7 @@ namespace sqlite_orm { sqlite3* db = this->connection->get(); perform_void_exec(db, "ROLLBACK"); this->connection->release(); - if(this->connection->retain_count() < 0) { + if (this->connection->retain_count() < 0) { throw std::system_error{orm_error_code::no_active_transaction}; } } @@ -18120,8 +18121,8 @@ namespace sqlite_orm { int busy_handler(std::function handler) { _busy_handler = std::move(handler); - if(this->is_opened()) { - if(_busy_handler) { + if (this->is_opened()) { + if (_busy_handler) { return sqlite3_busy_handler(this->connection->get(), busy_handler_callback, this); } else { return sqlite3_busy_handler(this->connection->get(), nullptr, nullptr); @@ -18138,7 +18139,7 @@ namespace sqlite_orm { inMemory(filename.empty() || filename == ":memory:"), connection(std::make_unique(std::move(filename))), cachedForeignKeysCount(foreignKeysCount) { - if(this->inMemory) { + if (this->inMemory) { this->connection->retain(); this->on_open_internal(this->connection->get()); } @@ -18149,24 +18150,24 @@ namespace sqlite_orm { limit(std::bind(&storage_base::get_connection, this)), inMemory(other.inMemory), connection(std::make_unique(other.connection->filename)), cachedForeignKeysCount(other.cachedForeignKeysCount) { - if(this->inMemory) { + if (this->inMemory) { this->connection->retain(); this->on_open_internal(this->connection->get()); } } ~storage_base() { - if(this->isOpenedForever) { + if (this->isOpenedForever) { this->connection->release(); } - if(this->inMemory) { + if (this->inMemory) { this->connection->release(); } } void begin_transaction_internal(const std::string& query) { this->connection->retain(); - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } sqlite3* db = this->connection->get(); @@ -18175,7 +18176,7 @@ namespace sqlite_orm { connection_ref get_connection() { connection_ref res{*this->connection}; - if(1 == this->connection->retain_count()) { + if (1 == this->connection->retain_count()) { this->on_open_internal(this->connection->get()); } return res; @@ -18198,42 +18199,42 @@ namespace sqlite_orm { void on_open_internal(sqlite3* db) { #if SQLITE_VERSION_NUMBER >= 3006019 - if(this->cachedForeignKeysCount) { + if (this->cachedForeignKeysCount) { this->foreign_keys(db, true); } #endif - if(this->pragma.synchronous_ != -1) { + if (this->pragma.synchronous_ != -1) { this->pragma.synchronous(this->pragma.synchronous_); } - if(this->pragma.journal_mode_ != -1) { + if (this->pragma.journal_mode_ != -1) { this->pragma.set_pragma("journal_mode", static_cast(this->pragma.journal_mode_), db); } - for(auto& p: this->collatingFunctions) { + for (auto& p: this->collatingFunctions) { int rc = sqlite3_create_collation(db, p.first.c_str(), SQLITE_UTF8, &p.second, collate_callback); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } - for(auto& p: this->limit.limits) { + for (auto& p: this->limit.limits) { sqlite3_limit(db, p.first, p.second); } - if(_busy_handler) { + if (_busy_handler) { sqlite3_busy_handler(this->connection->get(), busy_handler_callback, this); } - for(auto& udfProxy: this->scalarFunctions) { + for (auto& udfProxy: this->scalarFunctions) { try_to_create_scalar_function(db, udfProxy); } - for(auto& udfProxy: this->aggregateFunctions) { + for (auto& udfProxy: this->aggregateFunctions) { try_to_create_aggregate_function(db, udfProxy); } - if(this->on_open) { + if (this->on_open) { this->on_open(db); } } @@ -18247,7 +18248,7 @@ namespace sqlite_orm { : int(std::tuple_size::value); using is_stateless = std::is_empty; auto udfMemorySpace = preallocate_udf_memory(); - if SQLITE_ORM_CONSTEXPR_IF(is_stateless::value) { + if SQLITE_ORM_CONSTEXPR_IF (is_stateless::value) { constructAt(udfMemorySpace.first); } this->scalarFunctions.emplace_back( @@ -18265,7 +18266,7 @@ namespace sqlite_orm { }, udfMemorySpace); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_scalar_function(db, this->scalarFunctions.back()); } @@ -18290,7 +18291,7 @@ namespace sqlite_orm { F* udfPointer; try { udfPointer = proxy_get_aggregate_step_udf(context, argsCount); - } catch(const std::bad_alloc&) { + } catch (const std::bad_alloc&) { sqlite3_result_error_nomem(context); return; } @@ -18313,7 +18314,7 @@ namespace sqlite_orm { }, obtain_udf_allocator()); - if(this->connection->retain_count() > 0) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); try_to_create_aggregate_function(db, this->aggregateFunctions.back()); } @@ -18327,8 +18328,8 @@ namespace sqlite_orm { return udfProxy.name == name; }); #endif - if(it != functions.end()) { - if(this->connection->retain_count() > 0) { + if (it != functions.end()) { + if (this->connection->retain_count() > 0) { sqlite3* db = this->connection->get(); int rc = sqlite3_create_function_v2(db, name.c_str(), @@ -18339,7 +18340,7 @@ namespace sqlite_orm { nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -18359,7 +18360,7 @@ namespace sqlite_orm { nullptr, nullptr, nullptr); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(db); } } @@ -18373,7 +18374,7 @@ namespace sqlite_orm { nullptr, udfProxy.func, aggregate_function_final_callback); - if(rc != SQLITE_OK) { + if (rc != SQLITE_OK) { throw_translated_sqlite_error(rc); } } @@ -18399,7 +18400,7 @@ namespace sqlite_orm { void drop_table_internal(sqlite3* db, const std::string& tableName, bool ifExists) { std::stringstream ss; ss << "DROP TABLE"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << streaming_identifier(tableName) << std::flush; @@ -18409,7 +18410,7 @@ namespace sqlite_orm { void drop_index_internal(const std::string& indexName, bool ifExists) { std::stringstream ss; ss << "DROP INDEX"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << quote_identifier(indexName) << std::flush; @@ -18419,7 +18420,7 @@ namespace sqlite_orm { void drop_trigger_internal(const std::string& triggerName, bool ifExists) { std::stringstream ss; ss << "DROP TRIGGER"; - if(ifExists) { + if (ifExists) { ss << " IF EXISTS"; } ss << ' ' << quote_identifier(triggerName) << std::flush; @@ -18434,7 +18435,7 @@ namespace sqlite_orm { static int busy_handler_callback(void* selfPointer, int triesCount) { auto& storage = *static_cast(selfPointer); - if(storage._busy_handler) { + if (storage._busy_handler) { return storage._busy_handler(triesCount); } else { return 0; @@ -18447,8 +18448,8 @@ namespace sqlite_orm { bool notEqual = false; // iterate through storage columns - for(size_t storageColumnInfoIndex = 0; storageColumnInfoIndex < storageTableInfo.size(); - ++storageColumnInfoIndex) { + for (size_t storageColumnInfoIndex = 0; storageColumnInfoIndex < storageTableInfo.size(); + ++storageColumnInfoIndex) { // get storage's column info table_xinfo& storageColumnInfo = storageTableInfo[storageColumnInfoIndex]; @@ -18462,7 +18463,7 @@ namespace sqlite_orm { return ti.name == columnName; }); #endif - if(dbColumnInfoIt != dbTableInfo.end()) { + if (dbColumnInfoIt != dbTableInfo.end()) { auto& dbColumnInfo = *dbColumnInfoIt; auto columnsAreEqual = dbColumnInfo.name == storageColumnInfo.name && @@ -18470,7 +18471,7 @@ namespace sqlite_orm { (!dbColumnInfo.dflt_value.empty()) == (!storageColumnInfo.dflt_value.empty()) && dbColumnInfo.pk == storageColumnInfo.pk && (dbColumnInfo.hidden == 0) == (storageColumnInfo.hidden == 0); - if(!columnsAreEqual) { + if (!columnsAreEqual) { notEqual = true; break; } @@ -18729,16 +18730,16 @@ namespace sqlite_orm { std::vector& collect_table_column_names(std::vector& collectedExpressions, bool definedOrder, const Ctx& context) { - if(definedOrder) { + if (definedOrder) { auto& table = pick_table>(context.db_objects); collectedExpressions.reserve(collectedExpressions.size() + table.template count_of()); table.for_each_column([qualified = !context.skip_table_name, &tableName = table.name, &collectedExpressions](const column_identifier& column) { - if(is_alias::value) { + if (is_alias::value) { collectedExpressions.push_back(quote_identifier(alias_extractor::extract()) + "." + quote_identifier(column.name)); - } else if(qualified) { + } else if (qualified) { collectedExpressions.push_back(quote_identifier(tableName) + "." + quote_identifier(column.name)); } else { @@ -18747,9 +18748,9 @@ namespace sqlite_orm { }); } else { collectedExpressions.reserve(collectedExpressions.size() + 1); - if(is_alias::value) { + if (is_alias::value) { collectedExpressions.push_back(quote_identifier(alias_extractor::extract()) + ".*"); - } else if(!context.skip_table_name) { + } else if (!context.skip_table_name) { const basic_table& table = pick_table>(context.db_objects); collectedExpressions.push_back(quote_identifier(table.name) + ".*"); } else { @@ -18769,7 +18770,7 @@ namespace sqlite_orm { template std::vector& operator()(const E& t, const Ctx& context) { auto columnExpression = serialize(t, context); - if(columnExpression.empty()) { + if (columnExpression.empty()) { throw std::system_error{orm_error_code::column_not_found}; } this->collectedExpressions.reserve(this->collectedExpressions.size() + 1); @@ -18799,8 +18800,8 @@ namespace sqlite_orm { (*this)(colExpr, context); }); // note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order - if(tuple_has_template::columns_type, asterisk_t>::value && - this->collectedExpressions.capacity() > this->collectedExpressions.size()) { + if (tuple_has_template::columns_type, asterisk_t>::value && + this->collectedExpressions.capacity() > this->collectedExpressions.size()) { this->collectedExpressions.shrink_to_fit(); } return this->collectedExpressions; @@ -18813,8 +18814,8 @@ namespace sqlite_orm { (*this)(colExpr, context); }); // note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order - if(tuple_has_template::columns_type, asterisk_t>::value && - this->collectedExpressions.capacity() > this->collectedExpressions.size()) { + if (tuple_has_template::columns_type, asterisk_t>::value && + this->collectedExpressions.capacity() > this->collectedExpressions.size()) { this->collectedExpressions.shrink_to_fit(); } return this->collectedExpressions; @@ -18862,12 +18863,12 @@ namespace sqlite_orm { auto serialize(const T& t, const C& context); inline void unquote_identifier(std::string& identifier) { - if(!identifier.empty()) { + if (!identifier.empty()) { constexpr char quoteChar = '"'; constexpr char sqlEscaped[] = {quoteChar, quoteChar}; identifier.erase(identifier.end() - 1); identifier.erase(identifier.begin()); - for(size_t pos = 0; (pos = identifier.find(sqlEscaped, pos, 2)) != identifier.npos; ++pos) { + for (size_t pos = 0; (pos = identifier.find(sqlEscaped, pos, 2)) != identifier.npos; ++pos) { identifier.erase(pos, 1); } } @@ -18875,7 +18876,7 @@ namespace sqlite_orm { inline void unquote_or_erase(std::string& name) { constexpr char quoteChar = '"'; - if(name.front() == quoteChar) { + if (name.front() == quoteChar) { unquote_identifier(name); } else { // unaliased expression - see 3. below @@ -18895,7 +18896,7 @@ namespace sqlite_orm { auto newContext = context; newContext.skip_table_name = true; std::string columnName = serialize(t, newContext); - if(columnName.empty()) { + if (columnName.empty()) { throw std::system_error{orm_error_code::column_not_found}; } unquote_or_erase(columnName); @@ -18973,11 +18974,11 @@ namespace sqlite_orm { iterate_tuple(cols.columns, [&columnNames, &newContext](auto& m) { using value_type = polyfill::remove_cvref_t; - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { columnNames.push_back(alias_extractor>::extract()); } else { std::string columnName = serialize(m, newContext); - if(!columnName.empty()) { + if (!columnName.empty()) { columnNames.push_back(std::move(columnName)); } else { throw std::system_error{orm_error_code::column_not_found}; @@ -18996,8 +18997,8 @@ namespace sqlite_orm { std::vector columnNames = get_cte_column_names(sel.col, context); // 2. override column names from cte expression - if(size_t n = std::tuple_size_v) { - if(n != columnNames.size()) { + if (size_t n = std::tuple_size_v) { + if (n != columnNames.size()) { throw std::system_error{orm_error_code::column_not_found}; } @@ -19005,24 +19006,24 @@ namespace sqlite_orm { iterate_tuple(explicitColRefs, [&idx, &columnNames, &context](auto& colRef) { using ColRef = polyfill::remove_cvref_t; - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { columnNames[idx] = alias_extractor>::extract(); - } else if constexpr(std::is_member_pointer::value) { + } else if constexpr (std::is_member_pointer::value) { using O = table_type_of_t; - if(auto* columnName = find_column_name(context.db_objects, colRef)) { + if (auto* columnName = find_column_name(context.db_objects, colRef)) { columnNames[idx] = *columnName; } else { // relaxed: allow any member pointer as column reference columnNames[idx] = typeid(ColRef).name(); } - } else if constexpr(polyfill::is_specialization_of_v) { + } else if constexpr (polyfill::is_specialization_of_v) { columnNames[idx] = colRef.name; - } else if constexpr(std::is_same_v) { - if(!colRef.empty()) { + } else if constexpr (std::is_same_v) { + if (!colRef.empty()) { columnNames[idx] = colRef; } - } else if constexpr(std::is_same_v>) { - if(columnNames[idx].empty()) { + } else if constexpr (std::is_same_v>) { + if (columnNames[idx].empty()) { columnNames[idx] = std::to_string(idx + 1); } } else { @@ -19034,8 +19035,8 @@ namespace sqlite_orm { // 3. fill in blanks with numerical column identifiers { - for(size_t i = 0, n = columnNames.size(); i < n; ++i) { - if(columnNames[i].empty()) { + for (size_t i = 0, n = columnNames.size(); i < n; ++i) { + if (columnNames[i].empty()) { columnNames[i] = std::to_string(i + 1); } } @@ -19076,10 +19077,10 @@ namespace sqlite_orm { newContext.skip_table_name = false; ss << serialize(orderBy.expression, newContext); - if(!orderBy._collate_argument.empty()) { + if (!orderBy._collate_argument.empty()) { ss << " COLLATE " << orderBy._collate_argument; } - switch(orderBy.asc_desc) { + switch (orderBy.asc_desc) { case 1: ss << " ASC"; break; @@ -19100,16 +19101,16 @@ namespace sqlite_orm { std::stringstream ss; ss << static_cast(orderBy) << " "; int index = 0; - for(const dynamic_order_by_entry_t& entry: orderBy) { - if(index > 0) { + for (const dynamic_order_by_entry_t& entry: orderBy) { + if (index > 0) { ss << ", "; } ss << entry.name; - if(!entry._collate_argument.empty()) { + if (!entry._collate_argument.empty()) { ss << " COLLATE " << entry._collate_argument; } - switch(entry.asc_desc) { + switch (entry.asc_desc) { case 1: ss << " ASC"; break; @@ -19457,7 +19458,7 @@ namespace sqlite_orm { template std::string operator()(const T& statement, const Ctx& context) const { - if(context.replace_bindable_with_question) { + if (context.replace_bindable_with_question) { return "?"; } else { return this->do_serialize(statement); @@ -19539,7 +19540,7 @@ namespace sqlite_orm { std::stringstream ss; ss << "CREATE TABLE " << streaming_identifier(tableName) << " (" << streaming_expressions_tuple(statement.elements, context) << ")"; - if(statement_type::is_without_rowid_v) { + if (statement_type::is_without_rowid_v) { ss << " WITHOUT ROWID"; } return ss.str(); @@ -19631,7 +19632,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "excluded."; - if(auto* columnName = find_column_name(context.db_objects, statement.expression)) { + if (auto* columnName = find_column_name(context.db_objects, statement.expression)) { ss << streaming_identifier(*columnName); } else { throw std::system_error{orm_error_code::column_not_found}; @@ -19709,16 +19710,16 @@ namespace sqlite_orm { using value_type = polyfill::remove_cvref_t; auto needParenthesis = std::is_member_pointer::value; ss << ' '; - if(needParenthesis) { + if (needParenthesis) { ss << '('; } ss << serialize(value, context); - if(needParenthesis) { + if (needParenthesis) { ss << ')'; } }); ss << ' ' << "DO"; - if(std::tuple_size::value == 0) { + if (std::tuple_size::value == 0) { ss << " NOTHING"; } else { auto updateContext = context; @@ -19777,7 +19778,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& c, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(alias_extractor::extract()) << "."; } auto newContext = context; @@ -19796,7 +19797,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& e, const Ctx& context) const { std::stringstream ss; - if(auto* columnName = find_column_name(context.db_objects, e)) { + if (auto* columnName = find_column_name(context.db_objects, e)) { ss << streaming_identifier( !context.skip_table_name ? lookup_table_name>(context.db_objects) : "", *columnName, @@ -19855,7 +19856,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -19870,7 +19871,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -19885,7 +19886,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(!context.skip_table_name) { + if (!context.skip_table_name) { ss << streaming_identifier(lookup_table_name(context.db_objects)) << "."; } ss << static_cast(statement); @@ -20031,7 +20032,7 @@ namespace sqlite_orm { std::stringstream ss; ss << "WITH"; - if(c.recursiveIndicated) { + if (c.recursiveIndicated) { ss << " RECURSIVE"; } ss << " " << serialize(c.cte, tupleContext); @@ -20118,11 +20119,11 @@ namespace sqlite_orm { std::stringstream ss; ss << expression.serialize(); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << "("; } ss << serialize(get_from_expression(expression.argument), subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << ")"; } return ss.str(); @@ -20144,11 +20145,11 @@ namespace sqlite_orm { std::stringstream ss; ss << static_cast(expression) << " "; - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << "("; } ss << serialize(get_from_expression(expression.c), subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesize) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesize) { ss << ")"; } return ss.str(); @@ -20173,19 +20174,19 @@ namespace sqlite_orm { is_binary_operator>::value; std::stringstream ss; - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeLeft) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeLeft) { ss << "("; } ss << serialize(statement.lhs, subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeLeft) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeLeft) { ss << ")"; } ss << " " << statement.serialize() << " "; - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeRight) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeRight) { ss << "("; } ss << serialize(statement.rhs, subCtx); - if SQLITE_ORM_CONSTEXPR_IF(parenthesizeRight) { + if SQLITE_ORM_CONSTEXPR_IF (parenthesizeRight) { ss << ")"; } return ss.str(); @@ -20230,19 +20231,19 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; } ss << " "; - if(is_compound_operator::value) { + if (is_compound_operator::value) { ss << '('; } auto newContext = context; newContext.use_parentheses = true; ss << serialize(statement.argument, newContext); - if(is_compound_operator::value) { + if (is_compound_operator::value) { ss << ')'; } return ss.str(); @@ -20261,7 +20262,7 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; @@ -20280,7 +20281,7 @@ namespace sqlite_orm { std::stringstream ss; auto leftString = serialize(statement.left, context); ss << leftString << " "; - if(!statement.negative) { + if (!statement.negative) { ss << "IN"; } else { ss << "NOT IN"; @@ -20289,11 +20290,11 @@ namespace sqlite_orm { using args_type = std::tuple; constexpr bool theOnlySelect = std::tuple_size::value == 1 && is_select>::value; - if(!theOnlySelect) { + if (!theOnlySelect) { ss << "("; } ss << streaming_expressions_tuple(statement.argument, context); - if(!theOnlySelect) { + if (!theOnlySelect) { ss << ")"; } return ss.str(); @@ -20367,7 +20368,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case conflict_clause_t::rollback: return "ROLLBACK"; case conflict_clause_t::abort: @@ -20421,7 +20422,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "PRIMARY KEY"; - switch(statement.options.asc_option) { + switch (statement.options.asc_option) { case statement_type::order_by::ascending: ss << " ASC"; break; @@ -20431,12 +20432,12 @@ namespace sqlite_orm { default: break; } - if(statement.options.conflict_clause_is_on) { + if (statement.options.conflict_clause_is_on) { ss << " ON CONFLICT " << serialize(statement.options.conflict_clause, context); } using columns_tuple = typename statement_type::columns_tuple; const size_t columnsCount = std::tuple_size::value; - if(columnsCount) { + if (columnsCount) { ss << "(" << streaming_mapped_columns_expressions(statement.columns, context) << ")"; } return ss.str(); @@ -20453,7 +20454,7 @@ namespace sqlite_orm { ss << static_cast(c); using columns_tuple = typename statement_type::columns_tuple; const size_t columnsCount = std::tuple_size::value; - if(columnsCount) { + if (columnsCount) { ss << "(" << streaming_mapped_columns_expressions(c.columns, context) << ")"; } return ss.str(); @@ -20561,10 +20562,10 @@ namespace sqlite_orm { ss << streaming_identifier(refTableName); } ss << "(" << streaming_mapped_columns_expressions(fk.references, context) << ")"; - if(fk.on_update) { + if (fk.on_update) { ss << ' ' << static_cast(fk.on_update) << " " << fk.on_update._action; } - if(fk.on_delete) { + if (fk.on_delete) { ss << ' ' << static_cast(fk.on_delete) << " " << fk.on_delete._action; } return ss.str(); @@ -20591,12 +20592,12 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(statement.full) { + if (statement.full) { ss << "GENERATED ALWAYS "; } ss << "AS ("; ss << serialize(statement.expression, context) << ")"; - switch(statement.storage) { + switch (statement.storage) { case basic_generated_always::storage_type::not_specified: //.. break; @@ -20619,7 +20620,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& column, const Ctx& context) const { std::stringstream ss; ss << streaming_identifier(column.name); - if(!context.fts5_columns) { + if (!context.fts5_columns) { ss << " " << type_printer>>().print(); } ss << streaming_column_constraints( @@ -20708,7 +20709,7 @@ namespace sqlite_orm { ss << "UPDATE " << streaming_identifier(table.name) << " SET "; table.template for_each_column_excluding>( [&table, &ss, &context, &object = get_ref(statement.object), first = true](auto& column) mutable { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -20719,7 +20720,7 @@ namespace sqlite_orm { ss << " WHERE "; table.for_each_column( [&table, &context, &ss, &object = get_ref(statement.object), first = true](auto& column) mutable { - if(!column.template is() && !exists_in_composite_primary_key(table, column)) { + if (!column.template is() && !exists_in_composite_primary_key(table, column)) { return; } @@ -20740,8 +20741,8 @@ namespace sqlite_orm { std::stringstream ss; ss << "SET "; int index = 0; - for(const dynamic_set_entry& entry: statement) { - if(index > 0) { + for (const dynamic_set_entry& entry: statement) { + if (index > 0) { ss << ", "; } ss << entry.serialized_value; @@ -20800,7 +20801,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { const auto& tableNames = collect_table_names(statement.set, context); - if(tableNames.empty()) { + if (tableNames.empty()) { throw std::system_error{orm_error_code::no_tables_specified}; } const std::string& tableName = tableNames.begin()->first; @@ -20827,7 +20828,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( [&table, &columnNames](auto& column) { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -20837,13 +20838,13 @@ namespace sqlite_orm { std::stringstream ss; ss << "INSERT INTO " << streaming_identifier(table.name) << " "; - if(columnNamesCount) { + if (columnNamesCount) { ss << "(" << streaming_identifiers(columnNames) << ")"; } else { ss << "DEFAULT"; } ss << " VALUES"; - if(columnNamesCount) { + if (columnNamesCount) { ss << " (" << streaming_field_values_excluding( mpl::conjunction>, @@ -20885,11 +20886,11 @@ namespace sqlite_orm { subCtx.use_parentheses = true; std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << streaming_serialized(get_column_names(statement, subCtx)); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -20905,7 +20906,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(is_insert_raw::value) { + if (is_insert_raw::value) { ss << "INSERT"; } else { ss << "REPLACE"; @@ -20913,12 +20914,12 @@ namespace sqlite_orm { iterate_tuple(statement.args, [&context, &ss](auto& value) { using value_type = polyfill::remove_cvref_t; ss << ' '; - if(is_columns::value) { + if (is_columns::value) { auto newContext = context; newContext.skip_table_name = true; newContext.use_parentheses = true; ss << serialize(value, newContext); - } else if(is_values::value || is_select::value) { + } else if (is_values::value || is_select::value) { auto newContext = context; newContext.use_parentheses = false; ss << serialize(value, newContext); @@ -20947,7 +20948,7 @@ namespace sqlite_orm { }); table.for_each_primary_key_column([&table, &ss, &idsStrings, index = 0](auto& memberPointer) mutable { auto* columnName = table.find_column_name(memberPointer); - if(!columnName) { + if (!columnName) { throw std::system_error{orm_error_code::column_not_found}; } @@ -20993,7 +20994,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( [&table, &columnNames](auto& column) { - if(exists_in_composite_primary_key(table, column)) { + if (exists_in_composite_primary_key(table, column)) { return; } @@ -21004,15 +21005,15 @@ namespace sqlite_orm { std::stringstream ss; ss << "INSERT INTO " << streaming_identifier(table.name) << " "; - if(columnNamesCount) { + if (columnNamesCount) { ss << "(" << streaming_identifiers(columnNames) << ")"; } else { ss << "DEFAULT"; } ss << " VALUES "; - if(columnNamesCount) { + if (columnNamesCount) { ss << streaming_values_placeholders(columnNamesCount, valuesCount); - } else if(valuesCount != 1) { + } else if (valuesCount != 1) { throw std::system_error{orm_error_code::cannot_use_default_value}; } return ss.str(); @@ -21074,12 +21075,12 @@ namespace sqlite_orm { << streaming_identifier(table.name) << " WHERE "; auto primaryKeyColumnNames = table.primary_key_column_names(); - if(primaryKeyColumnNames.empty()) { + if (primaryKeyColumnNames.empty()) { throw std::system_error{orm_error_code::table_has_no_primary_key_column}; } - for(size_t i = 0; i < primaryKeyColumnNames.size(); ++i) { - if(i > 0) { + for (size_t i = 0; i < primaryKeyColumnNames.size(); ++i) { + if (i > 0) { ss << " AND "; } ss << streaming_identifier(primaryKeyColumnNames[i]) << " = ?"; @@ -21113,7 +21114,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case conflict_action::replace: return "REPLACE"; case conflict_action::abort: @@ -21165,19 +21166,19 @@ namespace sqlite_orm { subCtx.use_parentheses = true; std::stringstream ss; - if(!is_compound_operator::value) { - if(!sel.highest_level && context.use_parentheses) { + if (!is_compound_operator::value) { + if (!sel.highest_level && context.use_parentheses) { ss << "("; } ss << "SELECT "; } - if(get_distinct(sel.col)) { + if (get_distinct(sel.col)) { ss << static_cast(distinct(0)) << " "; } ss << streaming_serialized(get_column_names(sel.col, subCtx)); using conditions_tuple = typename statement_type::conditions_type; constexpr bool hasExplicitFrom = tuple_has::value; - if(!hasExplicitFrom) { + if (!hasExplicitFrom) { auto tableNames = collect_table_names(sel, context); using joins_index_sequence = filter_tuple_sequence_t; // deduplicate table names of constrained join statements @@ -21189,13 +21190,13 @@ namespace sqlite_orm { alias_extractor::as_alias()}; tableNames.erase(tableNameWithAlias); }); - if(!tableNames.empty() && !is_compound_operator::value) { + if (!tableNames.empty() && !is_compound_operator::value) { ss << " FROM " << streaming_identifiers(tableNames); } } ss << streaming_conditions_tuple(sel.conditions, context); - if(!is_compound_operator::value) { - if(!sel.highest_level && context.use_parentheses) { + if (!is_compound_operator::value) { + if (!sel.highest_level && context.use_parentheses) { ss << ")"; } } @@ -21211,11 +21212,11 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << serialize(statement.column_or_expression, context); - if(!statement._collation_name.empty()) { + if (!statement._collation_name.empty()) { ss << " COLLATE " << statement._collation_name; } - if(statement._order) { - switch(statement._order) { + if (statement._order) { + switch (statement._order) { case -1: ss << " DESC"; break; @@ -21269,7 +21270,7 @@ namespace sqlite_orm { std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; ss << "CREATE "; - if(statement.unique) { + if (statement.unique) { ss << "UNIQUE "; } using indexed_type = typename statement_type::table_mapped_type; @@ -21279,7 +21280,7 @@ namespace sqlite_orm { std::string whereString; iterate_tuple(statement.elements, [&columnNames, &context, &whereString](auto& value) { using value_type = polyfill::remove_cvref_t; - if(!is_where::value) { + if (!is_where::value) { auto newContext = context; newContext.use_parentheses = false; auto whereString = serialize(value, newContext); @@ -21290,7 +21291,7 @@ namespace sqlite_orm { } }); ss << " (" << streaming_serialized(columnNames) << ")"; - if(!whereString.empty()) { + if (!whereString.empty()) { ss << ' ' << whereString; } return ss.str(); @@ -21353,7 +21354,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { - switch(statement.type) { + switch (statement.type) { case raise_t::type_t::ignore: return "RAISE(IGNORE)"; @@ -21376,7 +21377,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case trigger_timing::trigger_before: return "BEFORE"; case trigger_timing::trigger_after: @@ -21394,7 +21395,7 @@ namespace sqlite_orm { template serialize_result_type operator()(const statement_type& statement, const Ctx&) const { - switch(statement) { + switch (statement) { case trigger_type::trigger_delete: return "DELETE"; case trigger_type::trigger_insert: @@ -21443,7 +21444,7 @@ namespace sqlite_orm { ss << serialize(statement.type_base, context); ss << " ON " << streaming_identifier(lookup_table_name(context.db_objects)); - if(statement.do_for_each_row) { + if (statement.do_for_each_row) { ss << " FOR EACH ROW"; } statement.container_when.apply([&ss, &context](auto& value) { @@ -21467,7 +21468,7 @@ namespace sqlite_orm { ss << " BEGIN "; iterate_tuple(statement.elements, [&ss, &context](auto& element) { using element_type = polyfill::remove_cvref_t; - if(is_select::value) { + if (is_select::value) { auto newContext = context; newContext.use_parentheses = false; ss << serialize(element, newContext); @@ -21619,8 +21620,8 @@ namespace sqlite_orm { newContext.skip_table_name = false; std::stringstream ss; ss << static_cast(limt) << " "; - if(HO) { - if(OI) { + if (HO) { + if (OI) { limt.off.apply([&newContext, &ss](auto& value) { ss << serialize(value, newContext); }); @@ -21668,11 +21669,11 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << streaming_expressions_tuple(statement, context); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -21686,7 +21687,7 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << "VALUES "; @@ -21695,7 +21696,7 @@ namespace sqlite_orm { tupleContext.use_parentheses = true; ss << streaming_expressions_tuple(statement.tuple, tupleContext); } - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -21709,11 +21710,11 @@ namespace sqlite_orm { template std::string operator()(const statement_type& statement, const Ctx& context) const { std::stringstream ss; - if(context.use_parentheses) { + if (context.use_parentheses) { ss << '('; } ss << "VALUES " << streaming_dynamic_expressions(statement.vector, context); - if(context.use_parentheses) { + if (context.use_parentheses) { ss << ')'; } return ss.str(); @@ -22074,15 +22075,15 @@ namespace sqlite_orm { auto determine_cte_colref(const DBOs& /*dbObjects*/, const SubselectColRef& subselectColRef, const ExplicitColRef& explicitColRef) { - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { return explicitColRef; - } else if constexpr(std::is_member_pointer::value) { + } else if constexpr (std::is_member_pointer::value) { return explicitColRef; - } else if constexpr(std::is_base_of_v) { + } else if constexpr (std::is_base_of_v) { return explicitColRef.member_pointer; - } else if constexpr(std::is_same_v) { + } else if constexpr (std::is_same_v) { return subselectColRef; - } else if constexpr(std::is_same_v>) { + } else if constexpr (std::is_same_v>) { return subselectColRef; } else { static_assert(polyfill::always_false_v, "Invalid explicit column reference specified"); @@ -22094,7 +22095,7 @@ namespace sqlite_orm { const SubselectColRefs& subselectColRefs, [[maybe_unused]] const ExplicitColRefs& explicitColRefs, std::index_sequence) { - if constexpr(std::tuple_size_v != 0) { + if constexpr (std::tuple_size_v != 0) { static_assert( (!is_builtin_numeric_column_alias_v< alias_holder_type_or_none_t>> && @@ -22161,7 +22162,7 @@ namespace sqlite_orm { std::index_sequence) { auto tbl = make_cte_table(dbObjects, get(cte)); - if constexpr(sizeof...(In) > 0) { + if constexpr (sizeof...(In) > 0) { return make_recursive_cte_db_objects( // Because CTEs can depend on their predecessor we recursively pass in a new set of DBOs db_objects_cat(dbObjects, std::move(tbl)), @@ -22287,18 +22288,18 @@ namespace sqlite_orm { // here we copy source table to another with a name with '_backup' suffix, but in case table with such // a name already exists we append suffix 1, then 2, etc until we find a free name.. auto backupTableName = table.name + "_backup"; - if(this->table_exists(db, backupTableName)) { + if (this->table_exists(db, backupTableName)) { int suffix = 1; do { std::stringstream ss; ss << suffix << std::flush; auto anotherBackupTableName = backupTableName + ss.str(); - if(!this->table_exists(db, anotherBackupTableName)) { + if (!this->table_exists(db, anotherBackupTableName)) { backupTableName = std::move(anotherBackupTableName); break; } ++suffix; - } while(true); + } while (true); } this->create_table(db, backupTableName, table); @@ -22389,7 +22390,7 @@ namespace sqlite_orm { #if defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED - requires(is_select_v) #endif result_set_view iterate(Select expression) { expression.highest_level = true; @@ -22400,7 +22401,7 @@ namespace sqlite_orm { #if (SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE) template #ifdef SQLITE_ORM_CONCEPTS_SUPPORTED - requires(is_select_v) + requires (is_select_v) #endif result_set_view, db_objects_type> iterate(with_t expression) { auto con = this->get_connection(); @@ -22475,12 +22476,12 @@ namespace sqlite_orm { std::string group_concat_internal(F O::* m, std::unique_ptr y, Args&&... args) { this->assert_mapped_type(); std::vector rows; - if(y) { + if (y) { rows = this->select(sqlite_orm::group_concat(m, std::move(*y)), std::forward(args)...); } else { rows = this->select(sqlite_orm::group_concat(m), std::forward(args)...); } - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -22658,7 +22659,7 @@ namespace sqlite_orm { using R = mapped_type_proxy_t; this->assert_mapped_type(); auto rows = this->select(sqlite_orm::count(), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -22684,7 +22685,7 @@ namespace sqlite_orm { int count(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::count(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -22703,7 +22704,7 @@ namespace sqlite_orm { double avg(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::avg(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return rows.front(); } else { return 0; @@ -22753,7 +22754,7 @@ namespace sqlite_orm { bool> = true> std::string group_concat(F field, const char* y, Args&&... args) { std::unique_ptr str; - if(y) { + if (y) { str = std::make_unique(y); } else { str = std::make_unique(); @@ -22774,7 +22775,7 @@ namespace sqlite_orm { std::unique_ptr max(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::max(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -22794,7 +22795,7 @@ namespace sqlite_orm { std::unique_ptr min(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::min(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -22815,8 +22816,8 @@ namespace sqlite_orm { this->assert_mapped_type>(); std::vector> rows = this->select(sqlite_orm::sum(std::move(field)), std::forward(args)...); - if(!rows.empty()) { - if(rows.front()) { + if (!rows.empty()) { + if (rows.front()) { return std::make_unique(std::move(*rows.front())); } else { return {}; @@ -22839,7 +22840,7 @@ namespace sqlite_orm { double total(F field, Args&&... args) { this->assert_mapped_type>(); auto rows = this->select(sqlite_orm::total(std::move(field)), std::forward(args)...); - if(!rows.empty()) { + if (!rows.empty()) { return std::move(rows.front()); } else { return {}; @@ -22957,7 +22958,7 @@ namespace sqlite_orm { void replace_range(It from, It to, Projection project = {}) { using O = std::decay_t; this->assert_mapped_type(); - if(from == to) { + if (from == to) { return; } @@ -22969,7 +22970,7 @@ namespace sqlite_orm { template void replace_range(It from, It to, Projection project = {}) { this->assert_mapped_type(); - if(from == to) { + if (from == to) { return; } @@ -23078,7 +23079,7 @@ namespace sqlite_orm { using O = std::decay_t(), *std::declval()))>; this->assert_mapped_type(); this->assert_insertable_type(); - if(from == to) { + if (from == to) { return; } auto statement = @@ -23090,7 +23091,7 @@ namespace sqlite_orm { void insert_range(It from, It to, Projection project = {}) { this->assert_mapped_type(); this->assert_insertable_type(); - if(from == to) { + if (from == to) { return; } auto statement = @@ -23154,7 +23155,7 @@ namespace sqlite_orm { sqlite3* db, bool preserve, bool* attempt_to_preserve) { - if(attempt_to_preserve) { + if (attempt_to_preserve) { *attempt_to_preserve = true; } @@ -23163,7 +23164,7 @@ namespace sqlite_orm { // first let's see if table with such name exists.. auto gottaCreateTable = !this->table_exists(db, table.name); - if(!gottaCreateTable) { + if (!gottaCreateTable) { // get table info provided in `make_table` call.. auto storageTableInfo = table.get_table_info(); @@ -23171,15 +23172,15 @@ namespace sqlite_orm { // this vector will contain pointers to columns that gotta be added.. std::vector columnsToAdd; - if(calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo)) { + if (calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo)) { gottaCreateTable = true; } - if(!gottaCreateTable) { // if all storage columns are equal to actual db columns but there are + if (!gottaCreateTable) { // if all storage columns are equal to actual db columns but there are // excess columns at the db.. - if(!dbTableInfo.empty()) { + if (!dbTableInfo.empty()) { // extra table columns than storage columns - if(!preserve) { + if (!preserve) { #if SQLITE_VERSION_NUMBER >= 3035000 // DROP COLUMN feature exists (v3.35.0) res = sync_schema_result::old_columns_removed; #else @@ -23190,33 +23191,33 @@ namespace sqlite_orm { } } } - if(gottaCreateTable) { + if (gottaCreateTable) { res = sync_schema_result::dropped_and_recreated; } else { - if(!columnsToAdd.empty()) { + if (!columnsToAdd.empty()) { // extra storage columns than table columns - for(const table_xinfo* colInfo: columnsToAdd) { + for (const table_xinfo* colInfo: columnsToAdd) { const basic_generated_always::storage_type* generatedStorageType = table.find_column_generated_storage_type(colInfo->name); - if(generatedStorageType) { - if(*generatedStorageType == basic_generated_always::storage_type::stored) { + if (generatedStorageType) { + if (*generatedStorageType == basic_generated_always::storage_type::stored) { gottaCreateTable = true; break; } // fallback cause VIRTUAL can be added } else { - if(colInfo->notnull && colInfo->dflt_value.empty()) { + if (colInfo->notnull && colInfo->dflt_value.empty()) { gottaCreateTable = true; // no matter if preserve is true or false, there is no way to preserve data, so we wont try! - if(attempt_to_preserve) { + if (attempt_to_preserve) { *attempt_to_preserve = false; }; break; } } } - if(!gottaCreateTable) { - if(res == sync_schema_result::old_columns_removed) { + if (!gottaCreateTable) { + if (res == sync_schema_result::old_columns_removed) { res = sync_schema_result::new_columns_added_and_old_columns_removed; } else { res = sync_schema_result::new_columns_added; @@ -23225,7 +23226,7 @@ namespace sqlite_orm { res = sync_schema_result::dropped_and_recreated; } } else { - if(res != sync_schema_result::old_columns_removed) { + if (res != sync_schema_result::old_columns_removed) { res = sync_schema_result::already_in_sync; } } @@ -23601,7 +23602,7 @@ namespace sqlite_orm { mpl::conjunction>, mpl::disjunction_fn>>( call_as_template_base([&table, &bindValue, &object](auto& column) { - if(!exists_in_composite_primary_key(table, column)) { + if (!exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } })); @@ -23651,12 +23652,12 @@ namespace sqlite_orm { auto& object = get_object(statement.expression); table.template for_each_column_excluding>( call_as_template_base([&table, &bindValue, &object](auto& column) { - if(!exists_in_composite_primary_key(table, column)) { + if (!exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } })); table.for_each_column([&table, &bindValue, &object](auto& column) { - if(column.template is() || exists_in_composite_primary_key(table, column)) { + if (column.template is() || exists_in_composite_primary_key(table, column)) { bindValue(polyfill::invoke(column.member_pointer, object)); } }); @@ -23706,14 +23707,14 @@ namespace sqlite_orm { object_from_column_builder builder{res.emplace(), stmt}; table.for_each_column(builder); }); - if(!res.has_value()) { + if (!res.has_value()) { throw std::system_error{orm_error_code::not_found}; } return std::move(res).value(); #else auto& table = this->get_table(); auto stepRes = sqlite3_step(stmt); - switch(stepRes) { + switch (stepRes) { case SQLITE_ROW: { T res; object_from_column_builder builder{res, stmt}; @@ -23777,7 +23778,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif @@ -23798,7 +23799,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif @@ -23820,7 +23821,7 @@ namespace sqlite_orm { res.push_back(std::move(obj)); }); #ifdef SQLITE_ORM_IF_CONSTEXPR_SUPPORTED - if constexpr(polyfill::is_specialization_of_v) { + if constexpr (polyfill::is_specialization_of_v) { res.shrink_to_fit(); } #endif @@ -23946,7 +23947,7 @@ namespace sqlite_orm { this->for_each_column([&res](auto& column) { using field_type = field_type_t>; std::string dft; - if(auto d = column.default_value()) { + if (auto d = column.default_value()) { dft = std::move(*d); } using constraints_tuple = decltype(column.constraints); @@ -23965,7 +23966,7 @@ namespace sqlite_orm { column.template is()); }); auto compositeKeyColumnNames = this->composite_key_columns_names(); - for(size_t i = 0; i < compositeKeyColumnNames.size(); ++i) { + for (size_t i = 0; i < compositeKeyColumnNames.size(); ++i) { const std::string& columnName = compositeKeyColumnNames[i]; #if __cpp_lib_ranges >= 201911L auto it = std::ranges::find(res, columnName, &table_xinfo::name); @@ -23974,7 +23975,7 @@ namespace sqlite_orm { return ti.name == columnName; }); #endif - if(it != res.end()) { + if (it != res.end()) { it->pk = static_cast(i + 1); } } @@ -24108,11 +24109,11 @@ namespace sqlite_orm { template template> sync_schema_result storage_t::sync_table(const Table& table, sqlite3* db, bool preserve) { - if(std::is_same, sqlite_master>::value) { + if (std::is_same, sqlite_master>::value) { return sync_schema_result::already_in_sync; } #ifdef SQLITE_ENABLE_DBSTAT_VTAB - if(std::is_same, dbstat>::value) { + if (std::is_same, dbstat>::value) { return sync_schema_result::already_in_sync; } #endif // SQLITE_ENABLE_DBSTAT_VTAB @@ -24120,14 +24121,14 @@ namespace sqlite_orm { bool attempt_to_preserve = true; auto schema_stat = this->schema_status(table, db, preserve, &attempt_to_preserve); - if(schema_stat != sync_schema_result::already_in_sync) { - if(schema_stat == sync_schema_result::new_table_created) { + if (schema_stat != sync_schema_result::already_in_sync) { + if (schema_stat == sync_schema_result::new_table_created) { this->create_table(db, table.name, table); res = sync_schema_result::new_table_created; } else { - if(schema_stat == sync_schema_result::old_columns_removed || - schema_stat == sync_schema_result::new_columns_added || - schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { + if (schema_stat == sync_schema_result::old_columns_removed || + schema_stat == sync_schema_result::new_columns_added || + schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { // get table info provided in `make_table` call.. auto storageTableInfo = table.get_table_info(); @@ -24140,9 +24141,9 @@ namespace sqlite_orm { this->calculate_remove_add_columns(columnsToAdd, storageTableInfo, dbTableInfo); - if(schema_stat == sync_schema_result::old_columns_removed) { + if (schema_stat == sync_schema_result::old_columns_removed) { #if SQLITE_VERSION_NUMBER >= 3035000 // DROP COLUMN feature exists (v3.35.0) - for(auto& tableInfo: dbTableInfo) { + for (auto& tableInfo: dbTableInfo) { this->drop_column(db, table.name, tableInfo.name); } res = sync_schema_result::old_columns_removed; @@ -24153,10 +24154,10 @@ namespace sqlite_orm { #endif } - if(schema_stat == sync_schema_result::new_columns_added) { - for(const table_xinfo* colInfo: columnsToAdd) { + if (schema_stat == sync_schema_result::new_columns_added) { + for (const table_xinfo* colInfo: columnsToAdd) { table.for_each_column([this, colInfo, &tableName = table.name, db](auto& column) { - if(column.name != colInfo->name) { + if (column.name != colInfo->name) { return; } this->add_column(db, tableName, column); @@ -24165,7 +24166,7 @@ namespace sqlite_orm { res = sync_schema_result::new_columns_added; } - if(schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { + if (schema_stat == sync_schema_result::new_columns_added_and_old_columns_removed) { auto storageTableInfo = table.get_table_info(); this->add_generated_cols(columnsToAdd, storageTableInfo); @@ -24174,7 +24175,7 @@ namespace sqlite_orm { this->backup_table(db, table, columnsToAdd); res = sync_schema_result::new_columns_added_and_old_columns_removed; } - } else if(schema_stat == sync_schema_result::dropped_and_recreated) { + } else if (schema_stat == sync_schema_result::dropped_and_recreated) { // now get current table info from db using `PRAGMA table_xinfo` query.. auto dbTableInfo = this->pragma.table_xinfo(table.name); // should include generated columns auto storageTableInfo = table.get_table_info(); @@ -24186,7 +24187,7 @@ namespace sqlite_orm { this->add_generated_cols(columnsToAdd, storageTableInfo); - if(preserve && attempt_to_preserve) { + if (preserve && attempt_to_preserve) { this->backup_table(db, table, columnsToAdd); } else { this->drop_create_with_loss(db, table); @@ -24219,7 +24220,7 @@ namespace sqlite_orm { return columnName == tableInfo->name; }); #endif - if(columnToIgnoreIt == columnsToIgnore.end()) { + if (columnToIgnoreIt == columnsToIgnore.end()) { columnNames.push_back(cref(columnName)); } }); @@ -24647,10 +24648,10 @@ namespace sqlite_orm { const result_type* result = nullptr; internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable { using node_type = polyfill::remove_cvref_t; - if(internal::is_bindable::value) { + if (internal::is_bindable::value) { ++index; } - if(index == N) { + if (index == N) { internal::call_if_constexpr::value>( [](auto& r, auto& n) { r = &n; @@ -24673,10 +24674,10 @@ namespace sqlite_orm { internal::iterate_ast(statement.expression, [&result, index = -1](auto& node) mutable { using node_type = polyfill::remove_cvref_t; - if(internal::is_bindable::value) { + if (internal::is_bindable::value) { ++index; } - if(index == N) { + if (index == N) { internal::call_if_constexpr::value>( [](auto& r, auto& n) { r = const_cast>(&n); @@ -24816,7 +24817,7 @@ namespace sqlite_orm { template struct note_value_fn { P operator()(P&& value, carray_pointer_arg

pv) const { - if(P* observer = pv) { + if (P* observer = pv) { *observer = value; } return std::move(value); diff --git a/tests/backup_tests.cpp b/tests/backup_tests.cpp index 2eb0b6838..b935e3e82 100644 --- a/tests/backup_tests.cpp +++ b/tests/backup_tests.cpp @@ -69,7 +69,7 @@ TEST_CASE("backup") { auto backup = storage.make_backup_to(backupFilename); do { backup.step(1); - } while(backup.remaining() > 0); + } while (backup.remaining() > 0); } SECTION("storage step -1") { auto backup = storage.make_backup_to(storage2); @@ -79,7 +79,7 @@ TEST_CASE("backup") { auto backup = storage.make_backup_to(storage2); do { backup.step(1); - } while(backup.remaining() > 0); + } while (backup.remaining() > 0); } REQUIRE(storage2.table_exists(usersTableName)); auto rowsFromBackup = storage2.get_all(); @@ -105,7 +105,7 @@ TEST_CASE("backup") { auto backup = storage2.make_backup_from(backupFilename); do { backup.step(1); - } while(backup.remaining() > 0); + } while (backup.remaining() > 0); } SECTION("storage") { storage2.backup_from(storage); @@ -118,7 +118,7 @@ TEST_CASE("backup") { auto backup = storage2.make_backup_from(storage); do { backup.step(1); - } while(backup.remaining() > 0); + } while (backup.remaining() > 0); } REQUIRE(storage2.table_exists(usersTableName)); auto rowsFromBackup = storage2.get_all(); diff --git a/tests/built_in_functions_tests/core_functions_tests.cpp b/tests/built_in_functions_tests/core_functions_tests.cpp index 74d620a5f..ad47b5f6a 100644 --- a/tests/built_in_functions_tests/core_functions_tests.cpp +++ b/tests/built_in_functions_tests/core_functions_tests.cpp @@ -248,7 +248,7 @@ TEST_CASE("quote") { TEST_CASE("randomblob") { auto storage = make_storage({}); - for(auto i = 0; i < 20; ++i) { + for (auto i = 0; i < 20; ++i) { auto blobLength = i + 1; auto rows = storage.select(randomblob(blobLength)); REQUIRE(rows.size() == 1); diff --git a/tests/built_in_functions_tests/math_functions.cpp b/tests/built_in_functions_tests/math_functions.cpp index 856120736..c7be1e6a9 100644 --- a/tests/built_in_functions_tests/math_functions.cpp +++ b/tests/built_in_functions_tests/math_functions.cpp @@ -16,9 +16,9 @@ TEST_CASE("math functions") { auto doubleComparator = std::bind(is_double_eq, _1, _2, Epsilon); #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED auto optionalComparator = [](const std::optional& lhs, const std::optional& rhs) { - if(lhs.has_value() && rhs.has_value()) { + if (lhs.has_value() && rhs.has_value()) { return is_double_eq(*lhs, *rhs, Epsilon); - } else if(!lhs.has_value() && !rhs.has_value()) { + } else if (!lhs.has_value() && !rhs.has_value()) { return true; } else { return false; diff --git a/tests/get_all_custom_containers.cpp b/tests/get_all_custom_containers.cpp index b587a256f..ec7da2e97 100644 --- a/tests/get_all_custom_containers.cpp +++ b/tests/get_all_custom_containers.cpp @@ -24,7 +24,7 @@ namespace { } bool operator()(const std::unique_ptr& lhs, const User& rhs) const { - if(lhs) { + if (lhs) { return this->operator()(*lhs, rhs); } else { return false; @@ -32,7 +32,7 @@ namespace { } #ifdef SQLITE_ORM_OPTIONAL_SUPPORTED bool operator()(const std::optional& lhs, const User& rhs) const { - if(lhs.has_value()) { + if (lhs.has_value()) { return this->operator()(*lhs, rhs); } else { return false; diff --git a/tests/iterate.cpp b/tests/iterate.cpp index 1c16ea7de..52836309e 100644 --- a/tests/iterate.cpp +++ b/tests/iterate.cpp @@ -28,7 +28,7 @@ TEST_CASE("Iterate mapped") { db.replace(expected); SECTION("range-based for") { - for(Test& obj: db.iterate()) { + for (Test& obj: db.iterate()) { REQUIRE(obj == expected); } } @@ -77,7 +77,7 @@ TEST_CASE("Iterate select statement") { std::vector expected_vec{expected}; SECTION("range-based for") { - for(Test&& obj: db.iterate(select(object()))) { + for (Test&& obj: db.iterate(select(object()))) { REQUIRE(obj == expected); } } diff --git a/tests/json.cpp b/tests/json.cpp index dc1966733..27396c4ac 100644 --- a/tests/json.cpp +++ b/tests/json.cpp @@ -100,7 +100,7 @@ TEST_CASE("json_array_length nullable") { value = std::move(rows[0]); REQUIRE(rows.size() == 1); REQUIRE(bool(expected) == bool(value)); - if(expected) { + if (expected) { REQUIRE(*expected == *value); } } @@ -375,7 +375,7 @@ TEST_CASE("json_type") { testCases.push_back(TestCase{R"({"a":[2,3.5,true,false,null,"x"]})", "null", "$.a[4]"}); testCases.push_back(TestCase{R"({"a":[2,3.5,true,false,null,"x"]})", "text", "$.a[5]"}); testCases.push_back(TestCase{R"({"a":[2,3.5,true,false,null,"x"]})", "", "$.a[6]"}); - for(auto& testCase: testCases) { + for (auto& testCase: testCases) { { auto rows = storage.select(json_type(testCase.argument, testCase.secondArgument)); decltype(rows) expected; @@ -386,7 +386,7 @@ TEST_CASE("json_type") { auto rows = storage.select(json_type>(testCase.argument, testCase.secondArgument)); REQUIRE(rows.size() == 1); - if(!testCase.result.empty()) { + if (!testCase.result.empty()) { REQUIRE(rows[0]); REQUIRE(*rows[0] == testCase.result); } else { @@ -406,7 +406,7 @@ TEST_CASE("json_valid") { std::vector testCases; testCases.push_back(TestCase{R"({"x":35})", true}); testCases.push_back(TestCase{R"({"x":35)", false}); - for(auto& testCase: testCases) { + for (auto& testCase: testCases) { auto rows = storage.select(json_valid(testCase.argument)); decltype(rows) expected; expected.push_back(testCase.expected); diff --git a/tests/operators/arithmetic_operators.cpp b/tests/operators/arithmetic_operators.cpp index c54e4a64b..24f97a0b3 100644 --- a/tests/operators/arithmetic_operators.cpp +++ b/tests/operators/arithmetic_operators.cpp @@ -23,12 +23,12 @@ TEST_CASE("Arithmetic operators") { "Upside down", }; auto number = 10; - for(auto& name: names) { + for (auto& name: names) { storage.insert(Object{name, int(name.length()), number}); } { // + auto rows = storage.select(c(&Object::nameLen) + 1000); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(int(row) == name.length() + 1000); @@ -36,7 +36,7 @@ TEST_CASE("Arithmetic operators") { } { // + auto rows = storage.select(columns(c(&Object::nameLen) + 1000)); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(int(std::get<0>(row)) == name.length() + 1000); @@ -45,7 +45,7 @@ TEST_CASE("Arithmetic operators") { { // || std::string suffix = "ototo"; auto rows = storage.select(c(&Object::name) || suffix); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(row == name + suffix); @@ -54,7 +54,7 @@ TEST_CASE("Arithmetic operators") { { // daisy-chaining ||, left std::string suffix = "ototo"; auto rows = storage.select(c(&Object::name) || suffix || "."); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(row == name + suffix + "."); @@ -63,7 +63,7 @@ TEST_CASE("Arithmetic operators") { { // daisy-chaining ||, right std::string prefix = "ototo"; auto rows = storage.select(prefix || (c(&Object::name) || ".")); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(row == prefix + name + "."); @@ -72,7 +72,7 @@ TEST_CASE("Arithmetic operators") { { // || std::string suffix = "ototo"; auto rows = storage.select(columns(conc(&Object::name, suffix))); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(std::get<0>(row) == name + suffix); @@ -109,7 +109,7 @@ TEST_CASE("Arithmetic operators") { c(&Object::nameLen) / c(&Object::number), c(&Object::nameLen) / 2)); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(std::get<0>(row) == name + suffix); @@ -155,7 +155,7 @@ TEST_CASE("Arithmetic operators") { &Object::nameLen % c(&Object::number), c(&Object::nameLen) % c(&Object::number), c(&Object::nameLen) % 5)); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; auto& name = names[i]; REQUIRE(std::get<0>(row) == static_cast(name.length()) % number); diff --git a/tests/operators/glob.cpp b/tests/operators/glob.cpp index 43ebf5113..3f4da1a93 100644 --- a/tests/operators/glob.cpp +++ b/tests/operators/glob.cpp @@ -48,7 +48,7 @@ TEST_CASE("Glob") { } auto expectIds = [](const std::vector& employees, const std::vector ids) { - for(auto expectedId: ids) { + for (auto expectedId: ids) { REQUIRE(find_if(employees.begin(), employees.end(), [expectedId](auto& employee) { return employee.id == expectedId; }) != employees.end()); diff --git a/tests/pointer_passing_interface.cpp b/tests/pointer_passing_interface.cpp index 450d5c1bd..2f4311112 100644 --- a/tests/pointer_passing_interface.cpp +++ b/tests/pointer_passing_interface.cpp @@ -61,7 +61,7 @@ TEST_CASE("pointer-passing") { // return value from a pointer of type "carray" struct fetch_from_pointer_fn { int64 operator()(carray_pointer_arg pv) const { - if(const int64* v = pv) { + if (const int64* v = pv) { return *v; } return 0; @@ -128,7 +128,7 @@ TEST_CASE("pointer-passing") { )); auto stmt = storage.prepare(std::move(ast)); throw std::system_error{0, std::system_category()}; - } catch(const std::system_error&) { + } catch (const std::system_error&) { } // unbound pointer value must be deleted in face of exceptions (unregistered sql function) REQUIRE(delete_int64::deleted == true); diff --git a/tests/pragma_tests.cpp b/tests/pragma_tests.cpp index 21bcd76c8..062f1a10d 100644 --- a/tests/pragma_tests.cpp +++ b/tests/pragma_tests.cpp @@ -50,15 +50,15 @@ TEST_CASE("journal_mode") { auto jm = stor->pragma.journal_mode(); REQUIRE(jm == journal_mode::DELETE); - for(auto i = 0; i < 2; ++i) { - if(i == 0) { + for (auto i = 0; i < 2; ++i) { + if (i == 0) { stor->begin_transaction(); } stor->pragma.journal_mode(journal_mode::MEMORY); jm = stor->pragma.journal_mode(); REQUIRE(jm == journal_mode::MEMORY); - if(i == 1) { // WAL cannot be set within a transaction + if (i == 1) { // WAL cannot be set within a transaction stor->pragma.journal_mode(journal_mode::WAL); jm = stor->pragma.journal_mode(); REQUIRE(jm == journal_mode::WAL); @@ -77,7 +77,7 @@ TEST_CASE("journal_mode") { jm = stor->pragma.journal_mode(); REQUIRE(jm == journal_mode::TRUNCATE); - if(i == 0) { + if (i == 0) { stor->rollback(); } } @@ -95,7 +95,7 @@ TEST_CASE("Synchronous") { try { storage.pragma.synchronous(newValue); throw std::runtime_error("Must not fire"); - } catch(const std::system_error&) { + } catch (const std::system_error&) { // Safety level may not be changed inside a transaction REQUIRE(storage.pragma.synchronous() == value); } diff --git a/tests/prepared_statement_tests/insert.cpp b/tests/prepared_statement_tests/insert.cpp index e03857db7..6dbbc1f8c 100644 --- a/tests/prepared_statement_tests/insert.cpp +++ b/tests/prepared_statement_tests/insert.cpp @@ -26,9 +26,9 @@ TEST_CASE("Prepared insert") { } bool compareNames(const decltype(name)& lhs, const decltype(name)& rhs) const { - if(lhs && rhs) { + if (lhs && rhs) { return *lhs == *rhs; - } else if(!lhs && !rhs) { + } else if (!lhs && !rhs) { return true; } else { return false; diff --git a/tests/prepared_statement_tests/insert_range.cpp b/tests/prepared_statement_tests/insert_range.cpp index 9648b5627..9a94ecd4c 100644 --- a/tests/prepared_statement_tests/insert_range.cpp +++ b/tests/prepared_statement_tests/insert_range.cpp @@ -99,7 +99,7 @@ TEST_CASE("Prepared insert range") { decltype(users) otherUsers; otherUsers.push_back(User{6, "DJ Alban"}); otherUsers.push_back(User{7, "Flo Rida"}); - for(auto& user: otherUsers) { + for (auto& user: otherUsers) { expected.push_back(user); } get<0>(statement) = otherUsers.begin(); @@ -125,7 +125,7 @@ TEST_CASE("Prepared insert range") { decltype(usersPointers) otherUsers; otherUsers.emplace_back(new User{6, "DJ Alban"}); otherUsers.emplace_back(new User{7, "Flo Rida"}); - for(auto& user: otherUsers) { + for (auto& user: otherUsers) { expected.push_back(*user); } get<0>(statement) = otherUsers.begin(); diff --git a/tests/prepared_statement_tests/select.cpp b/tests/prepared_statement_tests/select.cpp index 135956f51..47b090bb5 100644 --- a/tests/prepared_statement_tests/select.cpp +++ b/tests/prepared_statement_tests/select.cpp @@ -157,7 +157,7 @@ TEST_CASE("Prepared select") { } } SECTION("serialize one column") { - for(auto i = 0; i < 2; ++i) { + for (auto i = 0; i < 2; ++i) { auto statement = storage.prepare(select(&User::id)); testSerializing(statement); SECTION("nothing") { @@ -170,7 +170,7 @@ TEST_CASE("Prepared select") { } } SECTION("serialize one column with order by") { - for(auto i = 0; i < 2; ++i) { + for (auto i = 0; i < 2; ++i) { auto statement = storage.prepare(select(&User::name, order_by(&User::id))); auto str = storage.dump(statement); testSerializing(statement); diff --git a/tests/row_extractor.cpp b/tests/row_extractor.cpp index f0b989876..95d3bda7b 100644 --- a/tests/row_extractor.cpp +++ b/tests/row_extractor.cpp @@ -18,7 +18,7 @@ struct SuperHero { }; std::string GenderToString(Gender gender) { - switch(gender) { + switch (gender) { case Gender::Female: return "female"; case Gender::Male: @@ -30,9 +30,9 @@ std::string GenderToString(Gender gender) { } std::optional GenderFromString(const std::string& s) { - if(s == "female") { + if (s == "female") { return Gender::Female; - } else if(s == "male") { + } else if (s == "male") { return Gender::Male; } return std::nullopt; @@ -63,7 +63,7 @@ struct sqlite_orm::field_printer { template<> struct sqlite_orm::row_extractor { Gender extract(const char* columnText) const { - if(auto gender = GenderFromString(columnText)) { + if (auto gender = GenderFromString(columnText)) { return *gender; } else { throw std::runtime_error("incorrect gender string (" + std::string(columnText) + ")"); @@ -97,7 +97,7 @@ struct CustomConcatFunction { std::string operator()(const arg_values& args) const { std::string result; - for(auto arg_value: args) { + for (auto arg_value: args) { result += arg_value.get(); } return result; diff --git a/tests/row_id.cpp b/tests/row_id.cpp index 2b65c1d61..db250b460 100644 --- a/tests/row_id.cpp +++ b/tests/row_id.cpp @@ -28,7 +28,7 @@ TEST_CASE("Row id") { _rowid_(), &SimpleTable::letter, &SimpleTable::desc)); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; REQUIRE(std::get<0>(row) == std::get<1>(row)); REQUIRE(std::get<1>(row) == std::get<2>(row)); diff --git a/tests/select_constraints_tests.cpp b/tests/select_constraints_tests.cpp index a0e6aa9b6..034b8869d 100644 --- a/tests/select_constraints_tests.cpp +++ b/tests/select_constraints_tests.cpp @@ -572,7 +572,7 @@ TEST_CASE("Dynamic order by") { auto rows = storage.get_all(orderBy); REQUIRE(rows.size() == 4); - for(size_t i = 0; i < rows.size(); ++i) { + for (size_t i = 0; i < rows.size(); ++i) { auto& row = rows[i]; REQUIRE(row.id == expectedIds[i]); } diff --git a/tests/statement_serializer_tests/bindables.cpp b/tests/statement_serializer_tests/bindables.cpp index 111c5c8bb..ef6ae56dc 100644 --- a/tests/statement_serializer_tests/bindables.cpp +++ b/tests/statement_serializer_tests/bindables.cpp @@ -85,7 +85,7 @@ template void require_strings(const array& values, const array& expected, index_sequence) { - for(size_t i = 0; i < sizeof...(Idx); ++i) { + for (size_t i = 0; i < sizeof...(Idx); ++i) { require_string(values[i], expected[i]); } } diff --git a/tests/static_tests/function_static_tests.cpp b/tests/static_tests/function_static_tests.cpp index ee7c387c7..cbb827d43 100644 --- a/tests/static_tests/function_static_tests.cpp +++ b/tests/static_tests/function_static_tests.cpp @@ -33,9 +33,9 @@ TEST_CASE("function static") { std::string operator()(const arg_values& args) const { std::string res; res.reserve(args.size()); - for(auto value: args) { + for (auto value: args) { auto stringValue = value.get(); - if(!stringValue.empty()) { + if (!stringValue.empty()) { res += stringValue.front(); } } diff --git a/tests/storage_non_crud_tests.cpp b/tests/storage_non_crud_tests.cpp index a4cfe0b47..15ad250f9 100644 --- a/tests/storage_non_crud_tests.cpp +++ b/tests/storage_non_crud_tests.cpp @@ -177,7 +177,7 @@ TEST_CASE("InsertRange") { SECTION("pointers") { std::vector> objects; objects.reserve(100); - for(auto i = 0; i < 100; ++i) { + for (auto i = 0; i < 100; ++i) { objects.push_back(std::make_unique(0, "Skillet")); } storage.insert_range(objects.begin(), objects.end(), &std::unique_ptr::operator*); @@ -224,7 +224,7 @@ TEST_CASE("Select") { REQUIRE(rc == SQLITE_OK); rc = sqlite3_step(stmt); - if(rc != SQLITE_DONE) { + if (rc != SQLITE_DONE) { throw std::runtime_error(sqlite3_errmsg(db)); } sqlite3_finalize(stmt); @@ -240,7 +240,7 @@ TEST_CASE("Select") { sqlite3_bind_text(stmt, 3, "hey", -1, nullptr); sqlite3_bind_int(stmt, 4, 5); rc = sqlite3_step(stmt); - if(rc != SQLITE_DONE) { + if (rc != SQLITE_DONE) { throw std::runtime_error(sqlite3_errmsg(db)); } sqlite3_finalize(stmt); @@ -256,7 +256,7 @@ TEST_CASE("Select") { sqlite3_bind_text(stmt, 3, "brothers", -1, nullptr); sqlite3_bind_int(stmt, 4, 15); rc = sqlite3_step(stmt); - if(rc != SQLITE_DONE) { + if (rc != SQLITE_DONE) { throw std::runtime_error(sqlite3_errmsg(db)); } sqlite3_finalize(stmt); @@ -274,7 +274,7 @@ TEST_CASE("Select") { sqlite3_bind_int64(stmt, 1, firstId); rc = sqlite3_step(stmt); - if(rc != SQLITE_ROW) { + if (rc != SQLITE_ROW) { throw std::runtime_error(sqlite3_errmsg(db)); } REQUIRE(sqlite3_column_int(stmt, 0) == firstId); diff --git a/tests/storage_tests.cpp b/tests/storage_tests.cpp index 68cd66135..437eced79 100644 --- a/tests/storage_tests.cpp +++ b/tests/storage_tests.cpp @@ -334,7 +334,7 @@ TEST_CASE("insert") { storage.remove_all(); storage.remove_all(); - for(auto i = 0; i < 100; ++i) { + for (auto i = 0; i < 100; ++i) { storage.insert(Object{ 0, "Skillet", diff --git a/tests/sync_schema_tests.cpp b/tests/sync_schema_tests.cpp index 65d48945c..6c0aab30f 100644 --- a/tests/sync_schema_tests.cpp +++ b/tests/sync_schema_tests.cpp @@ -58,7 +58,7 @@ TEST_CASE("Sync schema") { usersToInsert.push_back({-1, "Brad", std::make_unique(65), nullptr}); usersToInsert.push_back({-1, "Paul", std::make_unique(65), nullptr}); - for(auto& user: usersToInsert) { + for (auto& user: usersToInsert) { auto insertedId = storage.insert(user); user.id = insertedId; } @@ -97,7 +97,7 @@ TEST_CASE("Sync schema") { REQUIRE(usersFromDb.size() == usersToInsert.size()); - for(size_t i = 0; i < usersFromDb.size(); ++i) { + for (size_t i = 0; i < usersFromDb.size(); ++i) { auto& userFromDb = usersFromDb[i]; auto& oldUser = usersToInsert[i]; REQUIRE(userFromDb == oldUser); @@ -170,7 +170,7 @@ TEST_CASE("issue521") { pocosToInsert.push_back({-1, "Michael", 10, 10.10f}); pocosToInsert.push_back({-1, "Joyce", 20, 20.20f}); - for(auto& poco: pocosToInsert) { + for (auto& poco: pocosToInsert) { auto insertedId = storage.insert(poco); poco.id = insertedId; } @@ -180,7 +180,7 @@ TEST_CASE("issue521") { using namespace sqlite_orm; auto pocosFromDb = storage.get_all(order_by(&MockDatabasePoco::id)); - for(size_t i = 0; i < pocosFromDb.size(); ++i) { + for (size_t i = 0; i < pocosFromDb.size(); ++i) { auto& pocoFromDb = pocosFromDb[i]; auto& oldPoco = pocosToInsert[i]; @@ -204,7 +204,7 @@ TEST_CASE("issue521") { REQUIRE(static_cast(storage.count()) == pocosToInsert.size()); auto pocosFromDb = storage.get_all(order_by(&MockDatabasePoco::id)); - for(size_t i = 0; i < pocosFromDb.size(); ++i) { + for (size_t i = 0; i < pocosFromDb.size(); ++i) { auto& pocoFromDb = pocosFromDb[i]; auto& oldPoco = pocosToInsert[i]; REQUIRE(pocoFromDb.id == oldPoco.id); @@ -229,7 +229,7 @@ TEST_CASE("issue521") { REQUIRE(static_cast(storage.count()) == pocosToInsert.size()); auto pocosFromDb = storage.get_all(order_by(&MockDatabasePoco::id)); - for(size_t i = 0; i < pocosFromDb.size(); ++i) { + for (size_t i = 0; i < pocosFromDb.size(); ++i) { auto& pocoFromDb = pocosFromDb[i]; auto& oldPoco = pocosToInsert[i]; REQUIRE(pocoFromDb.id == oldPoco.id); @@ -256,7 +256,7 @@ TEST_CASE("issue521") { REQUIRE(static_cast(storage.count()) == pocosToInsert.size()); auto pocosFromDb = storage.get_all(order_by(&MockDatabasePoco::id)); - for(size_t i = 0; i < pocosFromDb.size(); ++i) { + for (size_t i = 0; i < pocosFromDb.size(); ++i) { auto& pocoFromDb = pocosFromDb[i]; auto& oldPoco = pocosToInsert[i]; @@ -268,10 +268,10 @@ TEST_CASE("issue521") { } bool compareUniquePointers(const std::unique_ptr& lhs, const std::unique_ptr& rhs) { - if(!lhs && !rhs) { + if (!lhs && !rhs) { return true; } else { - if(lhs && rhs) { + if (lhs && rhs) { return *lhs == *rhs; } else { return false; diff --git a/tests/tests.cpp b/tests/tests.cpp index dd5bdc63d..8fd149691 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -110,7 +110,7 @@ TEST_CASE("Custom collate") { struct OtotoCollation { int operator()(int leftLength, const void* lhs, int rightLength, const void* rhs) const { - if(leftLength == rightLength) { + if (leftLength == rightLength) { return ::strncmp((const char*)lhs, (const char*)rhs, leftLength); } else { return 1; @@ -150,9 +150,9 @@ TEST_CASE("Custom collate") { storage.remove_all(); storage.insert(Item{0, "Mercury"}); storage.insert(Item{0, "Mars"}); - if(useLegacyScript) { + if (useLegacyScript) { storage.create_collation("ototo", [](int leftLength, const void* lhs, int rightLength, const void* rhs) { - if(leftLength == rightLength) { + if (leftLength == rightLength) { return ::strncmp((const char*)lhs, (const char*)rhs, leftLength); } else { return 1; @@ -181,7 +181,7 @@ TEST_CASE("Custom collate") { where(is_equal(&Item::name, "Mercury").collate()), order_by(&Item::name).collate()); - if(useLegacyScript) { + if (useLegacyScript) { storage.create_collation("ototo", {}); } else { storage.delete_collation(); diff --git a/tests/tests3.cpp b/tests/tests3.cpp index 234a0eff9..c60bc07b0 100644 --- a/tests/tests3.cpp +++ b/tests/tests3.cpp @@ -31,7 +31,7 @@ TEST_CASE("Multi order by") { auto expectedIds = {1, 2, 3, 5, 6, 4}; REQUIRE(expectedIds.size() == singers.size()); auto it = expectedIds.begin(); - for(size_t i = 0; i < singers.size(); ++i) { + for (size_t i = 0; i < singers.size(); ++i) { REQUIRE(*it == singers[i].id); ++it; } @@ -42,7 +42,7 @@ TEST_CASE("Multi order by") { auto singers = storage.get_all(order_by(&Singer::id).asc()); auto singers2 = storage.get_all(multi_order_by(order_by(&Singer::id).asc())); REQUIRE(singers.size() == singers2.size()); - for(size_t i = 0; i < singers.size(); ++i) { + for (size_t i = 0; i < singers.size(); ++i) { REQUIRE(singers[i].id == singers2[i].id); } } @@ -115,7 +115,7 @@ TEST_CASE("Wide string") { L"АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоППРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя", // russian L"AaBbCcÇçDdEeFFGgĞğHhIıİiJjKkLlMmNnOoÖöPpRrSsŞşTtUuÜüVvYyZz", // turkish }; - for(auto& expectedString: expectedStrings) { + for (auto& expectedString: expectedStrings) { auto id = storage.insert(Alphabet{0, expectedString}); REQUIRE(storage.get(id).letters == expectedString); } @@ -285,8 +285,8 @@ TEST_CASE("Blob") { auto generateData = [](size_t size) -> byte* { auto data = (byte*)::malloc(size * sizeof(byte)); - for(int i = 0; i < static_cast(size); ++i) { - if((i + 1) % 10 == 0) { + for (int i = 0; i < static_cast(size); ++i) { + if ((i + 1) % 10 == 0) { data[i] = 0; } else { data[i] = static_cast((rand() % 100) + 1); diff --git a/tests/tests5.cpp b/tests/tests5.cpp index 4f26251d1..4fed2b70f 100644 --- a/tests/tests5.cpp +++ b/tests/tests5.cpp @@ -317,7 +317,7 @@ TEST_CASE("issue822") { storage.sync_schema(); storage.replace(A(1, 1, 0, std::make_shared(55.5))); auto records = storage.get_all(where(c(&A::getAddress) == 1 and c(&A::getType) == 1 and c(&A::getIndex) == 0)); - if(records.size() != 0) { + if (records.size() != 0) { A a = records[0]; a.setValue(std::make_shared(10)); storage.update(a); diff --git a/tests/transaction_tests.cpp b/tests/transaction_tests.cpp index b40be81a2..5fee37f60 100644 --- a/tests/transaction_tests.cpp +++ b/tests/transaction_tests.cpp @@ -337,7 +337,7 @@ TEST_CASE("Transaction guard") { storage2.get_all(); alignas(alignof(internal::transaction_guard_t)) char buffer[sizeof(internal::transaction_guard_t)]; - auto guard = new(&buffer) internal::transaction_guard_t{storage.transaction_guard()}; + auto guard = new (&buffer) internal::transaction_guard_t{storage.transaction_guard()}; storage.insert({}); guard->commit_on_destroy = true; REQUIRE_THROWS_WITH(guard->~transaction_guard_t(), ContainsSubstring("database is locked")); diff --git a/tests/unique_cases/issue663.cpp b/tests/unique_cases/issue663.cpp index b4ab6135d..1a2343cdd 100644 --- a/tests/unique_cases/issue663.cpp +++ b/tests/unique_cases/issue663.cpp @@ -28,7 +28,7 @@ namespace { storage.insert_range(usersInput.begin(), usersInput.end()); const auto users = storage.template get_all(); REQUIRE(users.size() == usersInput.size()); - for(size_t i = 0; i < users.size(); ++i) { + for (size_t i = 0; i < users.size(); ++i) { REQUIRE(-1 != users[i].id); usersInput[i].id = users[i].id; } @@ -176,7 +176,7 @@ TEST_CASE("Issue 663 - fail test") { try { storage.insert_range(inputUsers.begin(), inputUsers.end()); REQUIRE(false); - } catch(const std::system_error& e) { + } catch (const std::system_error& e) { REQUIRE(e.code() == make_error_code(orm_error_code::cannot_use_default_value)); REQUIRE(storage.count() == 0); } diff --git a/tests/user_defined_functions.cpp b/tests/user_defined_functions.cpp index 6aec5ef6b..45548f607 100644 --- a/tests/user_defined_functions.cpp +++ b/tests/user_defined_functions.cpp @@ -132,9 +132,9 @@ struct FirstFunction { ++staticCallsCount; std::string res; res.reserve(args.size()); - for(auto value: args) { + for (auto value: args) { auto stringValue = value.get(); - if(!stringValue.empty()) { + if (!stringValue.empty()) { res += stringValue.front(); } } @@ -168,8 +168,8 @@ struct MultiSum { } void step(const arg_values& args) { - for(auto it = args.begin(); it != args.end(); ++it) { - if(!it->empty() && (it->is_integer() || it->is_float())) { + for (auto it = args.begin(); it != args.end(); ++it) { + if (!it->empty() && (it->is_integer() || it->is_float())) { this->sum += it->get(); } }