From 94fe1d31a0dcac8601b177ad00d71d118dc4c59f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 24 Apr 2016 17:21:24 +0100 Subject: Use a command *, not a commandptr --- gentoobrowse-api/service/dbUtils.cpp | 2 +- gentoobrowse-api/service/dbUtils.h | 2 +- .../service/maintenance/categoryMetaProcessor.cpp | 2 +- .../service/maintenance/ebuildMetaProcessor.cpp | 46 +++++++++++++++++++--- .../service/maintenance/packageMetaProcessor.cpp | 4 +- gentoobrowse-api/unittests/testMaintenance.cpp | 1 + 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 > & vs) + bindOptionalsS(DB::Command * db, unsigned int c, const std::vector > & 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 > & vs); + bool bindOptionalsS(DB::Command * db, unsigned int c, const std::vector > & 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 +#include #include #include +#include #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([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(); -- cgit v1.2.3