#include <sqlpp/constraint.hpp>
#include <sqlpp/field.hpp>
#include <sqlpp/table.hpp>
namespace sqlpp
{
constraint::constraint(
table_shared_ptr table_,
string_const_reference name_,
field_container_const_reference fields_
)
:
properties::table_property(table_),
properties::name_property(name_),
field_map(*table_, fields_)
{};
string_type constraint::get_sql_name() const
{
if (!get_name().empty())
return get_name();
std::ostringstream out;
out<<get_small_type_string()<<"_"<<get_checked_table()->get_name()<<"_"<<get_field_list("_");
return out.str();
};
string_type constraint::get_sql() const
{
if (empty())
return string_type();
string_type field_list = get_field_list(",");
if (field_list.empty())
return string_type();
table_shared_ptr table=get_checked_table();
std::ostringstream out;
out<<"\tCONSTRAINT "<<get_sql_name()<<" "<<get_type_string()<<" ("<<field_list<<")";
return out.str();
};
};