diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-02 19:27:34 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-02 19:27:34 +0100 |
commit | 9c2123473fa7c7399edc67d14c3675c2e11a42d3 (patch) | |
tree | ce4fd000c70715516559b88068fd30a80e875f2d | |
parent | Get glibmm and xml++ flags from pkg-config (diff) | |
download | slicer-1.9.2.tar.bz2 slicer-1.9.2.tar.xz slicer-1.9.2.zip |
Swap AdHoc::Buffer for CTF in db libslicer-1.9.2
-rw-r--r-- | slicer/db/sqlInsertSerializer.cpp | 27 | ||||
-rw-r--r-- | slicer/db/sqlInsertSerializer.h | 6 | ||||
-rw-r--r-- | slicer/db/sqlUpdateSerializer.cpp | 19 |
3 files changed, 27 insertions, 25 deletions
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 17d33b2..dde8f1f 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -3,7 +3,7 @@ #include <sqlExceptions.h> #include "sqlBinder.h" #include "sqlCommon.h" -#include <buffer.h> +#include <compileTimeFormatter.h> #include <modifycommand.h> #include <slicer/metadata.h> #include <boost/numeric/conversion/cast.hpp> @@ -119,37 +119,38 @@ namespace Slicer { DB::ModifyCommandPtr SqlInsertSerializer::createInsert(const Slicer::ModelPartPtr & mp) const { - AdHoc::Buffer insert; - insert.appendbf("INSERT INTO %s(", tableName); + using namespace AdHoc::literals; + std::stringstream insert; + "INSERT INTO %?("_fmt(insert, tableName); int fieldNo = 0; mp->OnEachChild(std::bind(&SqlInsertSerializer::createInsertField, this, std::ref(fieldNo), std::ref(insert), _1, _3)); - insert.append(") VALUES (", AdHoc::Buffer::Use); + insert << ") VALUES ("; for (; fieldNo > 1; --fieldNo) { - insert.append("?, "); + insert << "?, "; } - insert.append("?)"); - return connection->modify(insert); + insert << "?)"; + return connection->modify(insert.str()); } void - SqlInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const + SqlInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const { if (isBind(h)) { if (fieldNo++) { - insert.append(", "); + insert << ','; } - insert.append(name); + insert << name; } } void - SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const + SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const { if (isNotAuto(h)) { if (fieldNo++) { - insert.append(", "); + insert << ','; } - insert.append(name); + insert << name; } } } diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index d3e2215..3534b87 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -4,7 +4,7 @@ #include <slicer/serializer.h> #include <connection.h> #include <visibility.h> -#include <buffer.h> +#include <ostream> namespace Slicer { class DLL_PUBLIC SqlInsertSerializer : public Slicer::Serializer { @@ -17,7 +17,7 @@ namespace Slicer { void SerializeObject(const Slicer::ModelPartPtr &) const; void SerializeSequence(const Slicer::ModelPartPtr &) const; DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const; - virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const; + virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; @@ -31,7 +31,7 @@ namespace Slicer { SqlAutoIdInsertSerializer(const P & ... p) : SqlInsertSerializer(p...) { } protected: - virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const; + virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; }; diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 3ed7c2b..64ff1a0 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -3,7 +3,7 @@ #include <common.h> #include "sqlBinder.h" #include "sqlCommon.h" -#include <buffer.h> +#include <compileTimeFormatter.h> #include <modifycommand.h> #include <slicer/metadata.h> #include <functional> @@ -73,28 +73,29 @@ namespace Slicer { DB::ModifyCommandPtr SqlUpdateSerializer::createUpdate(const Slicer::ModelPartPtr & mp) const { - AdHoc::Buffer update; - update.appendbf("UPDATE %s SET ", tableName); + using namespace AdHoc::literals; + std::stringstream update; + "UPDATE %? SET "_fmt(update, tableName); int fieldNo = 0; mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) { if (isValue(h)) { if (fieldNo++) { - update.append(", "); + update << ", "; } - update.appendbf("%s = ?", name); + "%? = ?"_fmt(update, name); } }); - update.append(" WHERE ", AdHoc::Buffer::Use); + update << " WHERE "; fieldNo = 0; mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) { if (isPKey(h)) { if (fieldNo++) { - update.append(" AND "); + update << " AND "; } - update.appendbf("%s = ?", name); + "%? = ?"_fmt(update, name); } }); - return connection->modify(update); + return connection->modify(update.str()); } } |