fixed restriction and constraint class to use size_t

This commit is contained in:
2026-06-03 16:36:51 +02:00
parent 87bd2f8b89
commit 705d361aaa
10 changed files with 29 additions and 22 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ const std::vector<attribute>& basic_object_info::attributes() const {
return object_->attributes();
}
const std::vector<class restriction>& basic_object_info::constraints() const {
const std::list<restriction>& basic_object_info::constraints() const {
return object_->constraints();
}
+1 -1
View File
@@ -62,7 +62,7 @@ size_t object::constraint_count() const {
return constraints_.size();
}
const std::vector<restriction>& object::constraints() const {
const std::list<restriction>& object::constraints() const {
return constraints_;
}
+2 -2
View File
@@ -30,7 +30,7 @@ void object_generator::create_pk_constraint(const std::string &name) const {
if (pk_attr == std::end(object_->attributes_)) {
return;
}
restriction pk_constraint(*pk_attr);
restriction pk_constraint(pk_attr->index());
pk_constraint.options_ |= utils::constraints::PrimaryKey;
pk_constraint.owner_ = object_;
object_->constraints_.emplace_back(std::move(pk_constraint));
@@ -41,7 +41,7 @@ void object_generator::create_unique_constraint(const std::string &name) const {
if (pk_attr == std::end(object_->attributes_)) {
return;
}
restriction pk_constraint(*pk_attr);
restriction pk_constraint(pk_attr->index());
pk_constraint.options_ |= utils::constraints::Unique;
pk_constraint.owner_ = object_;
}
+12 -5
View File
@@ -4,16 +4,23 @@
#include "matador/object/object.hpp"
namespace matador::object {
restriction::restriction(const class attribute& attr)
: attr_(attr) {}
restriction::restriction(const size_t attr_index)
: index_(attr_index) {}
const class attribute& restriction::attribute() const {
return attr_;
size_t restriction::attribute_index() const {
return index_;
}
std::string restriction::column_name() const {
return attr_.name();
const auto o = owner_.lock();
return o ? o->attributes().at(index_).name() : "";
}
utils::constraints restriction::options() const {
const auto o = owner_.lock();
return o ? o->attributes().at(index_).attributes().options() : utils::constraints::None;
}
std::shared_ptr<object> restriction::owner() const {
return owner_.lock();
}
@@ -33,7 +33,7 @@ query_add_foreign_key_constraint_intermediate query_add_key_constraint_intermedi
executable_query query_alter_table_intermediate::add_constraint(const object::restriction &rest) {
context_->parts.push_back(std::make_unique<internal::query_add_constraint_part_by_constraint>(
table_constraint{rest.column_name(), rest.owner()->name(), rest.attribute().attributes().options(), rest.ref_table_name(), rest.ref_column_name()}
table_constraint{rest.column_name(), rest.owner()->name(), rest.options(), rest.ref_table_name(), rest.ref_column_name()}
));
return {context_};
@@ -47,7 +47,7 @@ query_add_key_constraint_intermediate query_alter_table_intermediate::add_constr
executable_query query_alter_table_intermediate::drop_constraint(const object::restriction &rest) {
context_->parts.push_back(std::make_unique<internal::query_drop_key_constraint_part_by_constraint>(
table_constraint{rest.column_name(), rest.owner()->name(), rest.attribute().attributes().options(), rest.ref_table_name(), rest.ref_column_name()})
table_constraint{rest.column_name(), rest.owner()->name(), rest.options(), rest.ref_table_name(), rest.ref_column_name()})
);
return {context_};
}
@@ -46,11 +46,11 @@ executable_query query_create_table_columns_intermediate::constraints(const std:
std::list<table_constraint> constraints;
for (const auto& restr : restrictions) {
if (restr.is_primary_key_constraint()) {
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.attribute().attributes().options());
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.options());
} else if (restr.is_foreign_key_constraint()) {
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.attribute().attributes().options(), restr.ref_table_name(), restr.ref_column_name());
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.options(), restr.ref_table_name(), restr.ref_column_name());
} else if (restr.is_unique_constraint()) {
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.attribute().attributes().options());
constraints.emplace_back(restr.column_name(), restr.owner()->name(), restr.options());
}
}
context_->parts.push_back(std::make_unique<internal::query_create_table_constraints_part>(constraints));