Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard the use of upsert_clause #1297

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions dev/ast/upsert_clause.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER >= 3024000
#include <tuple> // std::tuple
#include <utility> // std::forward, std::move
Expand Down Expand Up @@ -38,13 +39,18 @@ namespace sqlite_orm {

actions_tuple actions;
};
#endif

template<class T>
using is_upsert_clause = polyfill::is_specialization_of<T, upsert_clause>;
SQLITE_ORM_INLINE_VAR constexpr bool is_upsert_clause_v =
#if SQLITE_VERSION_NUMBER >= 3024000
polyfill::is_specialization_of<T, upsert_clause>::value;
#else
template<class T>
struct is_upsert_clause : polyfill::bool_constant<false> {};
false;
#endif

template<class T>
using is_upsert_clause = polyfill::bool_constant<is_upsert_clause_v<T>>;
}

#if SQLITE_VERSION_NUMBER >= 3024000
Expand All @@ -62,7 +68,7 @@ namespace sqlite_orm {
*/
template<class... Args>
internal::conflict_target<Args...> on_conflict(Args... args) {
return {std::tuple<Args...>(std::forward<Args>(args)...)};
return {{std::forward<Args>(args)...}};
}
#endif
}
2 changes: 2 additions & 0 deletions dev/node_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ namespace sqlite_orm {
template<class T, class... Args>
struct node_tuple<group_by_with_having<T, Args...>, void> : node_tuple_for<Args..., T> {};

#if SQLITE_VERSION_NUMBER >= 3024000
template<class Targets, class Actions>
struct node_tuple<upsert_clause<Targets, Actions>, void> : node_tuple<Actions> {};
#endif

template<class... Args>
struct node_tuple<set_t<Args...>, void> : node_tuple_for<Args...> {};
Expand Down
2 changes: 2 additions & 0 deletions examples/insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int main(int, char**) {
cout << storage.dump(employee) << endl;
}

#if SQLITE_VERSION_NUMBER >= 3024000
// INSERT INTO COMPANY(ID, NAME, AGE, ADDRESS, SALARY)
// VALUES (3, 'Sofia', 26, 'Madrid', 15000.0)
// (4, 'Doja', 26, 'LA', 25000.0)
Expand All @@ -127,6 +128,7 @@ int main(int, char**) {
c(&Employee::age) = excluded(&Employee::age),
c(&Employee::address) = excluded(&Employee::address),
c(&Employee::salary) = excluded(&Employee::salary))));
#endif

return 0;
}
16 changes: 12 additions & 4 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13773,6 +13773,7 @@ namespace sqlite_orm {

// #include "ast/upsert_clause.h"

#include <sqlite3.h>
#if SQLITE_VERSION_NUMBER >= 3024000
#include <tuple> // std::tuple
#include <utility> // std::forward, std::move
Expand Down Expand Up @@ -13811,13 +13812,18 @@ namespace sqlite_orm {

actions_tuple actions;
};
#endif

template<class T>
using is_upsert_clause = polyfill::is_specialization_of<T, upsert_clause>;
SQLITE_ORM_INLINE_VAR constexpr bool is_upsert_clause_v =
#if SQLITE_VERSION_NUMBER >= 3024000
polyfill::is_specialization_of<T, upsert_clause>::value;
#else
template<class T>
struct is_upsert_clause : polyfill::bool_constant<false> {};
false;
#endif

template<class T>
using is_upsert_clause = polyfill::bool_constant<is_upsert_clause_v<T>>;
}

#if SQLITE_VERSION_NUMBER >= 3024000
Expand All @@ -13835,7 +13841,7 @@ namespace sqlite_orm {
*/
template<class... Args>
internal::conflict_target<Args...> on_conflict(Args... args) {
return {std::tuple<Args...>(std::forward<Args>(args)...)};
return {{std::forward<Args>(args)...}};
}
#endif
}
Expand Down Expand Up @@ -22950,8 +22956,10 @@ namespace sqlite_orm {
template<class T, class... Args>
struct node_tuple<group_by_with_having<T, Args...>, void> : node_tuple_for<Args..., T> {};

#if SQLITE_VERSION_NUMBER >= 3024000
template<class Targets, class Actions>
struct node_tuple<upsert_clause<Targets, Actions>, void> : node_tuple<Actions> {};
#endif

template<class... Args>
struct node_tuple<set_t<Args...>, void> : node_tuple_for<Args...> {};
Expand Down