Browse Source

* fixed bug in mariadb driver (init stage2 and filters)

master
bergmann 5 years ago
parent
commit
dc46fc5fb0
3 changed files with 25 additions and 25 deletions
  1. +2
    -2
      include/cpphibernate/driver/mariadb/schema/filter.h
  2. +13
    -13
      src/cpphibernate/driver/mariadb/schema/table.cpp
  3. +10
    -10
      test/cpphibernate_init.cpp

+ 2
- 2
include/cpphibernate/driver/mariadb/schema/filter.h View File

@@ -30,8 +30,8 @@ beg_namespace_cpphibernate_driver_mariadb
using field_set_type = std::set<const field_t*>;
using table_set_type = std::set<const table_t*>;

size_t cache_id { 0 };
bool exclusive;
size_t cache_id { 0 };
bool exclusive { true };
field_set_type fields;
table_set_type tables;



+ 13
- 13
src/cpphibernate/driver/mariadb/schema/table.cpp View File

@@ -308,11 +308,10 @@ struct select_query_builder_t
if (_filter.is_excluded(ctx.table))
return ret;

ret = true;

/* primary key */
assert(ctx.table.primary_key_field);
add_field(*ctx.table.primary_key_field, real_alias);
ret = true;

/* data fields */
for (auto& ptr : ctx.table.data_fields)
@@ -320,7 +319,9 @@ struct select_query_builder_t
assert(ptr);
auto& field = *ptr;
if (!_filter.is_excluded(field))
{
add_field(field, real_alias);
}
}

/* foreign table one */
@@ -401,17 +402,13 @@ struct select_query_builder_t
<< "`";

auto it = joins.insert(joins.end(), ss.str());
if (add_table({
if (!add_table({
derived_table,
derived_alias,
false,
true,
ctx.is_dynamic,
}))
{
ret = true;
}
else
{
joins.erase(it);
}
@@ -826,7 +823,7 @@ std::string build_init_stage2_query(const table_t& table)
<< "`"
<< incindent
<< indent
<< "FOREIGN KEY (`"
<< "FOREIGN KEY IF NOT EXISTS (`"
<< ref_key_info.field_name
<< "`)"
<< indent
@@ -863,7 +860,7 @@ std::string build_init_stage2_query(const table_t& table)
<< "`"
<< incindent
<< indent
<< "FOREIGN KEY (`"
<< "FOREIGN KEY IF NOT EXISTS (`"
<< ref_key_info.table_name
<< "_id_"
<< field_info.field_name
@@ -876,9 +873,12 @@ std::string build_init_stage2_query(const table_t& table)
<< "` (`"
<< ref_key_info.field_name
<< "`)"
<< indent
<< "ON DELETE SET NULL"
<< indent
<< indent;
if (field_info.value_is_nullable)
os << "ON DELETE SET NULL";
else
os << "ON DELETE CASCADE";
os << indent
<< "ON UPDATE NO ACTION"
<< decindent;
}
@@ -902,7 +902,7 @@ std::string build_init_stage2_query(const table_t& table)
<< "`"
<< incindent
<< indent
<< "FOREIGN KEY (`"
<< "FOREIGN KEY IF NOT EXISTS (`"
<< field_info.table_name
<< "_id_"
<< field_info.field_name


+ 10
- 10
test/cpphibernate_init.cpp View File

@@ -153,53 +153,53 @@ TEST(CppHibernateTests, init)

expect_query(mock, "ALTER TABLE `tbl_test3`\n"
" ADD CONSTRAINT `fk_tbl_test3_to_tbl_derived3_id_test3_list`\n"
" FOREIGN KEY (`tbl_derived3_id_test3_list`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_derived3_id_test3_list`)\n"
" REFERENCES `test`.`tbl_derived3` (`tbl_derived3_id`)\n"
" ON DELETE SET NULL\n"
" ON UPDATE NO ACTION,\n"
" ADD CONSTRAINT `fk_tbl_test3_to_tbl_derived3_id_test3_vector`\n"
" FOREIGN KEY (`tbl_derived3_id_test3_vector`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_derived3_id_test3_vector`)\n"
" REFERENCES `test`.`tbl_derived3` (`tbl_derived3_id`)\n"
" ON DELETE SET NULL\n"
" ON UPDATE NO ACTION");

expect_query(mock, "ALTER TABLE `tbl_derived1`\n"
" ADD CONSTRAINT `fk_tbl_derived1_to_tbl_base_id`\n"
" FOREIGN KEY (`tbl_base_id`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_base_id`)\n"
" REFERENCES `test`.`tbl_base` (`tbl_base_id`)\n"
" ON DELETE CASCADE\n"
" ON UPDATE CASCADE,\n"
" ADD CONSTRAINT `fk_tbl_derived1_to_tbl_test1_id_test1_data`\n"
" FOREIGN KEY (`tbl_test1_id_test1_data`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_test1_id_test1_data`)\n"
" REFERENCES `test`.`tbl_test1` (`tbl_test1_id`)\n"
" ON DELETE SET NULL\n"
" ON DELETE CASCADE\n"
" ON UPDATE NO ACTION");

expect_query(mock, "ALTER TABLE `tbl_derived2`\n"
" ADD CONSTRAINT `fk_tbl_derived2_to_tbl_base_id`\n"
" FOREIGN KEY (`tbl_base_id`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_base_id`)\n"
" REFERENCES `test`.`tbl_base` (`tbl_base_id`)\n"
" ON DELETE CASCADE\n"
" ON UPDATE CASCADE,\n"
" ADD CONSTRAINT `fk_tbl_derived2_to_tbl_test2_id_test2_nullable`\n"
" FOREIGN KEY (`tbl_test2_id_test2_nullable`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_test2_id_test2_nullable`)\n"
" REFERENCES `test`.`tbl_test2` (`tbl_test2_id`)\n"
" ON DELETE SET NULL\n"
" ON UPDATE NO ACTION,\n"
" ADD CONSTRAINT `fk_tbl_derived2_to_tbl_test2_id_test2_ptr_u`\n"
" FOREIGN KEY (`tbl_test2_id_test2_ptr_u`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_test2_id_test2_ptr_u`)\n"
" REFERENCES `test`.`tbl_test2` (`tbl_test2_id`)\n"
" ON DELETE SET NULL\n"
" ON UPDATE NO ACTION,\n"
" ADD CONSTRAINT `fk_tbl_derived2_to_tbl_test2_id_test2_ptr_s`\n"
" FOREIGN KEY (`tbl_test2_id_test2_ptr_s`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_test2_id_test2_ptr_s`)\n"
" REFERENCES `test`.`tbl_test2` (`tbl_test2_id`)\n"
" ON DELETE SET NULL\n"
" ON UPDATE NO ACTION");

expect_query(mock, "ALTER TABLE `tbl_derived3`\n"
" ADD CONSTRAINT `fk_tbl_derived3_to_tbl_derived2_id`\n"
" FOREIGN KEY (`tbl_derived2_id`)\n"
" FOREIGN KEY IF NOT EXISTS (`tbl_derived2_id`)\n"
" REFERENCES `test`.`tbl_derived2` (`tbl_derived2_id`)\n"
" ON DELETE CASCADE\n"
" ON UPDATE CASCADE");


Loading…
Cancel
Save