fixed: finder.get() didn't check whether the resultset had exactly one item

git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1098 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2018-04-23 19:02:38 +00:00
parent cc2230001c
commit 3da8d1f411
1 changed files with 25 additions and 7 deletions

View File

@ -204,16 +204,24 @@ public:
return *this;
}
Finder<ModelClass> & select(Model::ModelData * model_data)
Finder<ModelClass> & select(Model::ModelData * model_data, bool call_prepare = true)
{
prepare_to_select();
if( call_prepare )
{
prepare_to_select();
}
this->model_data = model_data;
return select(false);
}
Finder<ModelClass> & select(Model::ModelData & model_data)
Finder<ModelClass> & select(Model::ModelData & model_data, bool call_prepare = true)
{
prepare_to_select();
if( call_prepare )
{
prepare_to_select();
}
this->model_data = &model_data;
return select(false);
}
@ -417,9 +425,17 @@ public:
if( res )
{
result.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key
model_connector->map_values_from_query(result);
result.after_select();
if( db_connector->last_select_size() == 1 )
{
result.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key
model_connector->map_values_from_query(result);
result.after_select();
}
else
{
res = false;
// log some error or throw an exception if there are more items than one?
}
}
else
{
@ -428,6 +444,7 @@ public:
}
catch(...)
{
res = false;
// throw something?
// if yes then make sure to call db_connector->clear_last_query_result();
}
@ -497,6 +514,7 @@ public:
}
catch(...)
{
res = false;
// throw or something?
// make sure to call db_connector->clear_last_query_result()
}