changed the way how the table name is set in a Model - added prepare_table() method
removed from Model: virtual void table_name(PT::TextStream & stream); added to Model: virtual void prepare_table(); virtual void table(const wchar_t * table_name); virtual void table(const wchar_t * schema_name, const wchar_t * table_name);
This commit is contained in:
149
src/model.cpp
149
src/model.cpp
@@ -109,12 +109,6 @@ void Model::mark_to_update()
|
||||
|
||||
|
||||
|
||||
void Model::table_name(PT::TextStream & stream)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Model::set_connector(ModelConnector & connector)
|
||||
{
|
||||
set_connector(&connector);
|
||||
@@ -133,6 +127,44 @@ ModelConnector * Model::get_connector()
|
||||
}
|
||||
|
||||
|
||||
void Model::prepare_table()
|
||||
{
|
||||
if( model_connector )
|
||||
{
|
||||
PT::Log * plog = model_connector->get_logger();
|
||||
|
||||
if( plog )
|
||||
{
|
||||
(*plog) << PT::Log::log1 << "Morm: you should provide the table name e.g. provide prepare_table() method and call table(...) there" << PT::Log::logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Model::table(const wchar_t * table_name)
|
||||
{
|
||||
if( model_env )
|
||||
{
|
||||
model_env->schema_name.clear();
|
||||
model_env->table_name.clear();
|
||||
|
||||
model_env->table_name << table_name;
|
||||
}
|
||||
}
|
||||
|
||||
void Model::table(const wchar_t * schema_name, const wchar_t * table_name)
|
||||
{
|
||||
if( model_env )
|
||||
{
|
||||
model_env->schema_name.clear();
|
||||
model_env->table_name.clear();
|
||||
|
||||
model_env->schema_name << schema_name;
|
||||
model_env->table_name << table_name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Model::object_exists()
|
||||
{
|
||||
return save_mode == DO_UPDATE_ON_SAVE;
|
||||
@@ -168,6 +200,7 @@ void Model::to_text(PT::TextStream & stream, ModelData * model_data, bool clear_
|
||||
{
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
flat_connector->to_text(stream, *this);
|
||||
}
|
||||
catch(...)
|
||||
@@ -255,6 +288,7 @@ void Model::generate_insert_query(PT::TextStream & stream, ModelData * model_dat
|
||||
{
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
db_connector->generate_insert_query(stream, *this);
|
||||
}
|
||||
catch(...)
|
||||
@@ -291,6 +325,7 @@ bool Model::insert(ModelData * model_data, bool insert_whole_tree)
|
||||
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
status = insert_tree(insert_whole_tree);
|
||||
}
|
||||
catch(...)
|
||||
@@ -385,6 +420,7 @@ void Model::generate_update_query(PT::TextStream & stream, ModelData * model_dat
|
||||
|
||||
if( db_connector )
|
||||
{
|
||||
prepare_table();
|
||||
db_connector->generate_update_query(stream, *this);
|
||||
}
|
||||
}
|
||||
@@ -416,6 +452,7 @@ bool Model::update(ModelData * model_data, bool update_whole_tree)
|
||||
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
status = update_tree(update_whole_tree);
|
||||
}
|
||||
catch(...)
|
||||
@@ -494,6 +531,7 @@ void Model::generate_remove_query(PT::TextStream & stream, ModelData * model_dat
|
||||
|
||||
if( db_connector )
|
||||
{
|
||||
prepare_table();
|
||||
db_connector->generate_remove_query(stream, *this);
|
||||
}
|
||||
}
|
||||
@@ -526,6 +564,7 @@ bool Model::remove(ModelData * model_data, bool remove_whole_tree)
|
||||
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
status = remove_tree(remove_whole_tree);
|
||||
}
|
||||
catch(...)
|
||||
@@ -621,6 +660,7 @@ bool Model::save(ModelData * model_data, bool save_whole_tree)
|
||||
|
||||
try
|
||||
{
|
||||
prepare_table();
|
||||
status = save_tree(save_whole_tree);
|
||||
}
|
||||
catch(...)
|
||||
@@ -741,6 +781,7 @@ void Model::clear()
|
||||
|
||||
try
|
||||
{
|
||||
// prepare_table() doesn't have to be called
|
||||
map_fields();
|
||||
}
|
||||
catch(...)
|
||||
@@ -865,34 +906,11 @@ bool Model::is_the_same_field(const wchar_t * field1, const wchar_t * field2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Model::prepare_table_names(bool prepare_table_index)
|
||||
{
|
||||
DbConnector * db_connector = model_connector->get_db_connector();
|
||||
|
||||
if( db_connector && model_env )
|
||||
{
|
||||
DbExpression * db_expression = db_connector->get_expression();
|
||||
|
||||
if( db_expression )
|
||||
{
|
||||
table_name(model_env->table_name);
|
||||
db_expression->prepare_short_table_name(model_env->table_name, model_env->table_name_short);
|
||||
|
||||
if( prepare_table_index && model_env->finder_helper )
|
||||
{
|
||||
model_env->table_index = model_env->finder_helper->add_join_table(model_env->table_name_short);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Model::put_table_name_with_index(PT::TextStream & str)
|
||||
{
|
||||
if( model_env )
|
||||
{
|
||||
str << model_env->table_name_short;
|
||||
str << model_env->table_name;
|
||||
|
||||
if( model_env->table_index > 1 )
|
||||
{
|
||||
@@ -902,6 +920,59 @@ void Model::put_table_name_with_index(PT::TextStream & str)
|
||||
}
|
||||
|
||||
|
||||
PT::WTextStream Model::get_table_name(bool put_schema_name)
|
||||
{
|
||||
PT::WTextStream str;
|
||||
|
||||
if( model_env )
|
||||
{
|
||||
if( put_schema_name && !model_env->schema_name.empty() )
|
||||
{
|
||||
str << model_env->schema_name;
|
||||
|
||||
// IMPROVEME make a virtual method in dbexpression to put such a dot
|
||||
str << '.';
|
||||
}
|
||||
|
||||
str << model_env->table_name;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
PT::WTextStream Model::get_table_name_with_field(const wchar_t * db_field_name, bool put_schema_name)
|
||||
{
|
||||
PT::WTextStream str;
|
||||
bool is_empty_field_name = is_empty_field(db_field_name);
|
||||
|
||||
if( model_env )
|
||||
{
|
||||
if( put_schema_name && !model_env->schema_name.empty() )
|
||||
{
|
||||
str << model_env->schema_name;
|
||||
|
||||
// IMPROVEME make a virtual method in dbexpression to put such a dot
|
||||
str << '.';
|
||||
}
|
||||
|
||||
str << model_env->table_name;
|
||||
|
||||
if( !is_empty_field_name )
|
||||
{
|
||||
str << '.'; // IMPROVEME get a virtual method from dbexpression
|
||||
}
|
||||
}
|
||||
|
||||
if( !is_empty_field_name )
|
||||
{
|
||||
str << db_field_name;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
void Model::put_to_log(const wchar_t * str)
|
||||
{
|
||||
if( model_connector )
|
||||
@@ -943,24 +1014,6 @@ void Model::put_fields_to_log(PT::Log & log, const wchar_t * db_field_name, cons
|
||||
}
|
||||
|
||||
|
||||
PT::TextStream Model::log_table_name()
|
||||
{
|
||||
PT::TextStream buf;
|
||||
table_name(buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
PT::TextStream Model::log_table_name(const wchar_t * db_field_name)
|
||||
{
|
||||
PT::TextStream buf;
|
||||
table_name(buf);
|
||||
buf << '.' << db_field_name;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user