From 4db623074133380ca2378c1166c7f2ae7e6e5003 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 16 Jul 2017 14:51:59 +0100 Subject: Remove the need for quirky 'on first item' initialisation of SQL statements --- slicer/db/sqlInsertSerializer.cpp | 5 +---- slicer/db/sqlUpdateSerializer.cpp | 5 +---- slicer/slicer/modelPartsTypes.impl.h | 6 ++---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 6c4cf31..e90fbf2 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -41,11 +41,8 @@ namespace Slicer { void SqlInsertSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const { - ModifyPtr ins; + ModifyPtr ins = createInsert(mp->GetContainedModelPart()); mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, HookCommonPtr) { - if (!ins) { - ins = createInsert(cmp); - } bindObjectAndExecute(cmp, ins.get()); }); } diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index a2a1fc2..ce9d868 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -40,11 +40,8 @@ namespace Slicer { void SqlUpdateSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const { - ModifyPtr ins; + ModifyPtr ins = createUpdate(mp->GetContainedModelPart()); mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, HookCommonPtr) { - if (!ins) { - ins = createUpdate(cmp); - } bindObjectAndExecute(cmp, ins.get()); }); } diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 43adc1e..9b9a5a7 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -164,8 +164,7 @@ namespace Slicer { ModelPartForOptional::ModelPartForOptional(IceUtil::Optional< typename T::element_type > * h) : ModelPartModel >(h) { - BOOST_ASSERT(this->Model); - if (*this->Model) { + if (hasModel()) { modelPart = new T(&**this->Model); } } @@ -173,8 +172,7 @@ namespace Slicer { template bool ModelPartForOptional::hasModel() const { - BOOST_ASSERT(this->Model); - return *this->Model; + return this->Model && *this->Model; } template -- cgit v1.2.3