From 802315513e89ef5ee41d68c91a2ff541bb084903 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 17 Oct 2015 18:47:19 +0100 Subject: Dedupe insert bind and execute --- slicer/db/sqlInsertSerializer.cpp | 22 ++++++++++++---------- slicer/db/sqlInsertSerializer.h | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 2f8e88d..eccc083 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -30,11 +30,7 @@ namespace Slicer { SqlInsertSerializer::SerializeObject(Slicer::ModelPartPtr mp) const { auto ins = createInsert(mp); - int paramNo = 0; - mp->OnEachChild([&ins, ¶mNo](const std::string &, ModelPartPtr cmp, HookCommonPtr) { - cmp->GetValue(new SqlBinder(*ins, paramNo++)); - }); - ins->execute(); + bindObjectAndExecute(mp, ins.get()); } void @@ -45,12 +41,18 @@ namespace Slicer { if (!ins) { ins = createInsert(cmp); } - int paramNo = 0; - cmp->OnEachChild([&ins, ¶mNo](const std::string &, ModelPartPtr cmp, HookCommonPtr) { - cmp->GetValue(new SqlBinder(*ins, paramNo++)); - }); - ins->execute(); + bindObjectAndExecute(cmp, ins.get()); + }); + } + + void + SqlInsertSerializer::bindObjectAndExecute(Slicer::ModelPartPtr cmp, DB::ModifyCommand * ins) + { + int paramNo = 0; + cmp->OnEachChild([&ins, ¶mNo](const std::string &, ModelPartPtr cmp, HookCommonPtr) { + cmp->GetValue(new SqlBinder(*ins, paramNo++)); }); + ins->execute(); } SqlInsertSerializer::ModifyPtr diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index 9163f47..843be93 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -18,6 +18,7 @@ namespace Slicer { void SerializeObject(Slicer::ModelPartPtr) const; void SerializeSequence(Slicer::ModelPartPtr) const; ModifyPtr createInsert(Slicer::ModelPartPtr) const; + static void bindObjectAndExecute(Slicer::ModelPartPtr, DB::ModifyCommand *); DB::Connection * connection; const std::string tableName; -- cgit v1.2.3