From 56fe2ef40199e3c7f1ac8a6b23d7939920889330 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 16 Mar 2012 19:32:11 +0000 Subject: Fix bug with SqlMerge without an updatewhere clause --- project2/sql/sqlMergeTask.cpp | 9 +++++---- project2/sql/sqlMergeTask.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp index 2c2cdd9..9611fa9 100644 --- a/project2/sql/sqlMergeTask.cpp +++ b/project2/sql/sqlMergeTask.cpp @@ -45,7 +45,8 @@ DECLARE_LOADER("sqlmergeinsert", SqlMergeInsert); SqlMergeTask::SqlMergeTask(ScriptNodePtr p) : SourceObject(p), Task(p), - updateWhere(p->child("updatewhere", false)), + updateWhere([=](ScriptNodePtr c){ + return c ? new DynamicSql::SqlCommand(c) : NULL; }(p->child("updatewhere", false))), patchOrder(p, "patchorder", Null()), earlyKeys(p, "earlykeys", false), useView(p, "useview", false), @@ -137,7 +138,7 @@ SqlMergeTask::execute() const BOOST_FOREACH(const Keys::value_type & k, keys) { tp.addKey(k); } - tp.patch(this, patchOrder()); + tp.patch(updateWhere ? this : NULL, patchOrder()); dropTempTable(); } @@ -335,13 +336,13 @@ SqlMergeTask::copyToTempTable() const void SqlMergeTask::appendWhere(Buffer * buf) const { - buf->appendf(" AND %s ", updateWhere.getSqlFor("").c_str()); + buf->appendf(" AND %s ", updateWhere->getSqlFor("").c_str()); } void SqlMergeTask::bindWhere(DB::Command * cmd) const { unsigned int off = 0; - updateWhere.bindParams(cmd, off); + updateWhere->bindParams(cmd, off); } diff --git a/project2/sql/sqlMergeTask.h b/project2/sql/sqlMergeTask.h index bd9f050..e90cda5 100644 --- a/project2/sql/sqlMergeTask.h +++ b/project2/sql/sqlMergeTask.h @@ -47,7 +47,7 @@ class SqlMergeTask : public Task, public TablePatch::WhereProvider { Columns cols; Keys keys; Keys indexes; - const DynamicSql::SqlCommand updateWhere; + const boost::intrusive_ptr updateWhere; const Variable patchOrder; const Variable earlyKeys; const Variable useView; -- cgit v1.2.3