summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.cpp31
-rw-r--r--gentoobrowse-api/service/utils/dbUtils.h6
2 files changed, 37 insertions, 0 deletions
diff --git a/gentoobrowse-api/service/utils/dbUtils.cpp b/gentoobrowse-api/service/utils/dbUtils.cpp
index f2b7f4d..4ec0f54 100644
--- a/gentoobrowse-api/service/utils/dbUtils.cpp
+++ b/gentoobrowse-api/service/utils/dbUtils.cpp
@@ -1,4 +1,7 @@
#include "dbUtils.h"
+#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <tablepatch.h>
namespace Gentoo {
namespace Utils {
@@ -15,6 +18,34 @@ namespace Gentoo {
db->bindNull(c);
return false;
}
+
+ std::string
+ emptyClone(DB::Connection * db, const std::string & orig)
+ {
+ auto tempTable = orig;
+ auto dot = tempTable.rfind('.');
+ if (dot != std::string::npos) {
+ tempTable = tempTable.substr(dot + 1);
+ }
+ tempTable += "_clone_" + boost::lexical_cast<std::string>(db);
+ db->execute("CREATE TEMPORARY TABLE " + tempTable + " AS SELECT * FROM " + orig + " WHERE false");
+ return tempTable;
+ }
+
+ void
+ drop(DB::Connection * db, const std::string & table)
+ {
+ db->execute("DROP TABLE " + table);
+ }
+
+ DB::ModifyCommandPtr
+ tablePatchInserter(DB::Connection * dbc, const DB::TablePatch & p)
+ {
+ return dbc->modify(
+ "INSERT INTO " + p.src +
+ "(" + boost::algorithm::join(p.cols, ", ") +
+ ") VALUES(" + boost::algorithm::join(std::vector<std::string>(p.cols.size(), "?"), ", ") + ")");
+ }
}
}
}
diff --git a/gentoobrowse-api/service/utils/dbUtils.h b/gentoobrowse-api/service/utils/dbUtils.h
index e609c2d..57554e3 100644
--- a/gentoobrowse-api/service/utils/dbUtils.h
+++ b/gentoobrowse-api/service/utils/dbUtils.h
@@ -2,11 +2,17 @@
#define GENTOOBROWSE_API_SERVICE_DBUTILS_H
#include <command.h>
+#include <modifycommand.h>
+#include <connection.h>
namespace Gentoo {
namespace Utils {
namespace Database {
bool bindOptionalsS(DB::Command * db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs);
+
+ std::string emptyClone(DB::Connection *, const std::string &);
+ void drop(DB::Connection *, const std::string &);
+ DB::ModifyCommandPtr tablePatchInserter(DB::Connection *, const DB::TablePatch &);
}
}
}