Skip to content

Commit

Permalink
Merge pull request #1357 from uuiid/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 authored Dec 5, 2024
2 parents cf82e1e + 886beac commit 0da82b0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
9 changes: 8 additions & 1 deletion dev/implementations/table_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ namespace sqlite_orm {
if(auto d = column.default_value()) {
dft = std::move(*d);
}
using constraints_tuple = decltype(column.constraints);
constexpr bool hasExplicitNull =
mpl::invoke_t<mpl::disjunction<check_if_has_type<null_t>>, constraints_tuple>::value;
constexpr bool hasExplicitNotNull =
mpl::invoke_t<mpl::disjunction<check_if_has_type<not_null_t>>, constraints_tuple>::value;
res.emplace_back(-1,
column.name,
type_printer<field_type>().print(),
column.is_not_null(),
!hasExplicitNull && !hasExplicitNotNull
? column.is_not_null()
: (hasExplicitNull ? !hasExplicitNull : hasExplicitNotNull),
std::move(dft),
column.template is<is_primary_key>(),
column.template is<is_generated_always>());
Expand Down
9 changes: 8 additions & 1 deletion include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23838,10 +23838,17 @@ namespace sqlite_orm {
if(auto d = column.default_value()) {
dft = std::move(*d);
}
using constraints_tuple = decltype(column.constraints);
constexpr bool hasExplicitNull =
mpl::invoke_t<mpl::disjunction<check_if_has_type<null_t>>, constraints_tuple>::value;
constexpr bool hasExplicitNotNull =
mpl::invoke_t<mpl::disjunction<check_if_has_type<not_null_t>>, constraints_tuple>::value;
res.emplace_back(-1,
column.name,
type_printer<field_type>().print(),
column.is_not_null(),
!hasExplicitNull && !hasExplicitNotNull
? column.is_not_null()
: (hasExplicitNull ? !hasExplicitNull : hasExplicitNotNull),
std::move(dft),
column.template is<is_primary_key>(),
column.template is<is_generated_always>());
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ add_executable(unit_tests
unique_cases/issue86.cpp
unique_cases/issue937.cpp
unique_cases/issue663.cpp
unique_cases/issue1357.cpp
get_all_custom_containers.cpp
select_constraints_tests.cpp
backup_tests.cpp
Expand Down
51 changes: 51 additions & 0 deletions tests/unique_cases/issue1357.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch_all.hpp>

#if SQLITE_VERSION_NUMBER >= 3006019
using namespace sqlite_orm;

#ifdef SQLITE_ORM_OPTIONAL_SUPPORTED

TEST_CASE("issue1357") {
struct Employee {
int m_empno;
std::string m_ename;
std::string m_job;
std::optional<int> m_mgr;
std::string m_hiredate;
double m_salary;
std::optional<double> m_commission;
int m_depno;
};

struct Department {
int m_deptno;
std::string m_deptname;
std::string m_loc;
};

using namespace sqlite_orm;

auto storage = make_storage("",
make_table("Emp",
make_column("empno", &Employee::m_empno, primary_key().autoincrement()),
make_column("ename", &Employee::m_ename),
make_column("job", &Employee::m_job),
make_column("mgr", &Employee::m_mgr),
make_column("hiredate", &Employee::m_hiredate),
make_column("salary", &Employee::m_salary),
make_column("comm", &Employee::m_commission),
make_column("depno", &Employee::m_depno),
foreign_key(&Employee::m_depno).references(&Department::m_deptno)),
make_table("Dept",
make_column("deptno", &Department::m_deptno, primary_key().autoincrement()),
make_column("deptname", &Department::m_deptname),
make_column("loc", &Department::m_loc, null())));
storage.sync_schema(true);
storage.insert(Department{10, "Accounts", "New York"});
storage.insert(Employee{1, "Paul", "Salesman", 2, "2002-02-12", 20000.0, 0.0, 1});
storage.insert(Employee{2, "Allen", "Salesman", 2, "2002-02-12", 20000.0, 0.0, 1});
REQUIRE_NOTHROW(storage.sync_schema(true));
}
#endif
#endif

0 comments on commit 0da82b0

Please sign in to comment.