summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-04-24 17:21:24 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-04-25 21:27:50 +0100
commitb843064dd46f1792d882c55ecaad0d16196a8c88 (patch)
tree11a3ee1906b3b5eb8b4e91bfb1175a232056aca0
parentUse static sql writer instead of our own class (diff)
downloadgentoobrowse-api-b843064dd46f1792d882c55ecaad0d16196a8c88.tar.bz2
gentoobrowse-api-b843064dd46f1792d882c55ecaad0d16196a8c88.tar.xz
gentoobrowse-api-b843064dd46f1792d882c55ecaad0d16196a8c88.zip
Use a command *, not a commandptr
-rw-r--r--gentoobrowse-api/service/dbUtils.cpp2
-rw-r--r--gentoobrowse-api/service/dbUtils.h2
-rw-r--r--gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp2
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp46
-rw-r--r--gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp4
-rw-r--r--gentoobrowse-api/unittests/testMaintenance.cpp1
6 files changed, 46 insertions, 11 deletions
diff --git a/gentoobrowse-api/service/dbUtils.cpp b/gentoobrowse-api/service/dbUtils.cpp
index 0bdb279..f2b7f4d 100644
--- a/gentoobrowse-api/service/dbUtils.cpp
+++ b/gentoobrowse-api/service/dbUtils.cpp
@@ -4,7 +4,7 @@ namespace Gentoo {
namespace Utils {
namespace Database {
bool
- bindOptionalsS(const DB::CommandPtr & db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs)
+ bindOptionalsS(DB::Command * db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs)
{
for(const auto & v : vs) {
if (v) {
diff --git a/gentoobrowse-api/service/dbUtils.h b/gentoobrowse-api/service/dbUtils.h
index 1f3e2f3..e609c2d 100644
--- a/gentoobrowse-api/service/dbUtils.h
+++ b/gentoobrowse-api/service/dbUtils.h
@@ -6,7 +6,7 @@
namespace Gentoo {
namespace Utils {
namespace Database {
- bool bindOptionalsS(const DB::CommandPtr & db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs);
+ bool bindOptionalsS(DB::Command * db, unsigned int c, const std::vector<boost::optional<Glib::ustring> > & vs);
}
}
}
diff --git a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
index 72c41c9..781526a 100644
--- a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
@@ -22,7 +22,7 @@ namespace Gentoo {
CategoryMetaProcessor::upsert(DB::ModifyCommandPtr m, const boost::filesystem::path & fn, const boost::filesystem::path & path) const
{
U::XmlDoc md(path);
- U::Database::bindOptionalsS(m, 0, {
+ U::Database::bindOptionalsS(m.get(), 0, {
md.getXPathValue("/catmetadata/longdescription[@lang='en']/text()"),
md.getXPathValue("/catmetadata/longdescription[1]/text()")
});
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
index afbe980..648decf 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
@@ -1,7 +1,9 @@
#include "ebuildMetaProcessor.h"
#include <modifycommand.h>
+#include <sqlWriter.h>
#include <boost/filesystem/operations.hpp>
#include <glibmm/regex.h>
+#include <tablepatch.h>
#include "fileUtils.h"
#include "xmlUtils.h"
#include "dbUtils.h"
@@ -54,6 +56,29 @@ namespace Gentoo {
KVs kvs;
};
+ class SplitEbuildProps : public DB::SqlWriter {
+ public:
+ SplitEbuildProps(int e, const std::string & p) :
+ ebuildId(e),
+ props(p)
+ {
+ }
+
+ void writeSql(AdHoc::Buffer & sql) override
+ {
+ sql.append("(SELECT ?::int ebuildId, trim(regexp_split_to_table(?, '\\s+'), '+') use)");
+ }
+
+ void bindParams(DB::Command * c, unsigned int & offset) override
+ {
+ c->bindParamI(offset++, ebuildId);
+ c->bindParamS(offset++, props);
+ }
+
+ const int ebuildId;
+ const std::string props;
+ };
+
const int EbuildMetaProcessor::FILETYPEID = 1;
void
@@ -76,21 +101,30 @@ namespace Gentoo {
// Maybe create a package
auto pi = dbc->modify(sql::maintenance::packageInsert::sql);
pi->bindParamS(0, packageName);
- Utils::Database::bindOptionalsS(pi, 1, { ecp.get("DESCRIPTION") });
+ Utils::Database::bindOptionalsS(pi.get(), 1, { ecp.get("DESCRIPTION") });
pi->bindParamS(2, packageName);
pi->bindParamS(3, categoryName);
pi->execute();
// Create an ebuild
auto m = dbc->modify(sql::maintenance::ebuildInsert::sql);
- m->bindParamS(0, matches.fetch(2));
- m->bindParamS(1, matches.fetch(2));
- Utils::Database::bindOptionalsS(m, 2, { ecp.get("SLOT") });
- Utils::Database::bindOptionalsS(m, 3, { ecp.get("LICENSE") });
+ m->bindParamS(0, ebuildVersion);
+ m->bindParamS(1, ebuildVersion);
+ Utils::Database::bindOptionalsS(m.get(), 2, { ecp.get("SLOT") });
+ Utils::Database::bindOptionalsS(m.get(), 3, { ecp.get("LICENSE") });
m->bindParamT(4, boost::posix_time::from_time_t(ecp.getStat().st_mtim.tv_sec));
m->bindParamS(5, repoName);
m->bindParamS(6, categoryName);
m->bindParamS(7, packageName);
- m->execute(false);
+ m->forEachRow<int64_t>([dbc,&ecp] (auto ebuildId) {
+ // USE flags
+ DB::TablePatch t;
+ SplitEbuildProps sep(ebuildId, ecp.get("USE").value_or(Glib::ustring()));
+ t.dest = "gentoobrowse.ebuild_uses";
+ t.srcExpr = &sep;
+ t.pk = { "ebuildid", "use" };
+ t.cols = { "ebuildid", "use" };
+ dbc->patchTable(&t);
+ });
}
}
diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
index 17af6a3..9dcf709 100644
--- a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
@@ -23,11 +23,11 @@ namespace Gentoo {
{
auto m = dbc->modify(sql::maintenance::packageMetaUpdate::sql);
U::XmlDoc md(path);
- U::Database::bindOptionalsS(m, 0, {
+ U::Database::bindOptionalsS(m.get(), 0, {
md.getXPathValue("/pkgmetadata/longdescription[@lang='en']/text()"),
md.getXPathValue("/pkgmetadata/longdescription[1]/text()")
});
- U::Database::bindOptionalsS(m, 1, {
+ U::Database::bindOptionalsS(m.get(), 1, {
md.getXPathValue("/pkgmetadata/herd/text()")
});
m->bindParamS(2, (fn / 1).string());
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index 45819e0..b51d599 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -63,6 +63,7 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
db->execute("COPY gentoobrowse.categories TO '/tmp/categories1.tsv'");
db->execute("COPY gentoobrowse.packages TO '/tmp/packages1.tsv'");
db->execute("COPY gentoobrowse.ebuilds TO '/tmp/ebuilds1.tsv'");
+ db->execute("COPY gentoobrowse.ebuild_uses TO '/tmp/ebuild_uses1.tsv'");
sd.extract("756569aa764177340726dd3d40b41d89b11b20c7", "gentoo");
m->refreshPackageTree();