From 3da8d1f411bd0a0495e3595ddb4f21ccac208099 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 23 Apr 2018 19:02:38 +0000 Subject: [PATCH] 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 --- src/finder.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/finder.h b/src/finder.h index cb64c2c..41aafed 100644 --- a/src/finder.h +++ b/src/finder.h @@ -204,16 +204,24 @@ public: return *this; } - Finder & select(Model::ModelData * model_data) + Finder & 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 & select(Model::ModelData & model_data) + Finder & 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() }