Commit 7f4c7f8b authored by Carsten Kemena's avatar Carsten Kemena

added datbase version and date and check

parent b0ed1686
......@@ -74,6 +74,17 @@ DBAccess::readSequences_(std::vector<TargetSequence> &sequences, const std::vect
}
}
std::set<int>
DBAccess::db_versions()
{
std::string query = "select value from info where argument='db-version';";
std::set<int> versions;
auto storeVersion = std::bind([](sqlite3_stmt *stmt, std::set<int> &versions){versions.emplace(stoul(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))));}, std::placeholders::_1, std::ref(versions));
this->index_.exec(query, storeVersion);
return versions;
}
void
DBAccess::search(BSDL::AlignmentMatrix<int, BSDL::DSM> &matrix, bool all, bool collapse, int scoreThres,
RadsQueryResult &results)
......
......@@ -150,6 +150,9 @@ class DBAccess
search(BSDL::AlignmentMatrix<int, BSDL::DSM> &matrix, bool all, bool collapse, int scoreThres,
RadsQueryResult &results);
std::set<int>
db_versions();
};
......
......@@ -173,7 +173,7 @@ DBCreator::readAnnotationFile(const fs::path &annotationFile, const fs::path &se
std::pair<size_t, size_t>
DBCreator::write(const fs::path &prefix, const std::map<std::string, std::string> &info)
DBCreator::write(const fs::path &prefix, const std::multimap<std::string, std::string> &info)
{
AlgorithmPack::Output out;
fs::path dbFile = prefix;
......@@ -191,7 +191,7 @@ DBCreator::write(const fs::path &prefix, const std::map<std::string, std::string
size_t nSeqs = 0;
for (const auto pair : info)
db.exec("INSERT INTO info VALUES(NULL,'"+ pair.first + "','" + pair.second + "')");
db.exec("INSERT INTO info VALUES(NULL,'"+ pair.first + "','" + pair.second + "')");
for (auto &arrangements : dbContent_)
{
......
......@@ -101,7 +101,7 @@ class DBCreator
* @return
*/
std::pair<size_t, size_t>
write(const fs::path &prefix, const std::map<std::string, std::string> &info);
write(const fs::path &prefix, const std::multimap<std::string, std::string> &info);
};
......
......@@ -26,6 +26,8 @@
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <chrono>
#include <unordered_map>
#include <unordered_set>
#include <map>
......@@ -48,7 +50,7 @@ using namespace std;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
namespace BSDL = BioSeqDataLib;
using std::chrono::system_clock;
int
main(int argc, char *argv[])
......@@ -126,6 +128,13 @@ main(int argc, char *argv[])
try
{
system_clock::time_point today = system_clock::now();
std::time_t tt;
tt = system_clock::to_time_t(today);
char timebuf[256];
strcpy(timebuf,ctime(&tt));
timebuf[strlen(timebuf)-1]='\0';
DBCreator db;
size_t nDaFiles = daFiles.size();
for (size_t i=0; i<nDaFiles; ++i)
......@@ -143,11 +152,12 @@ main(int argc, char *argv[])
db.readInterPro(interProFile, database);
// output
std::map<std::string, std::string> info;
info["version"] = version;
info["command"] = input_command;
std::multimap<std::string, std::string> info;
info.emplace("rads-version", version);
info.emplace("command", input_command);
info.emplace("db-version", "2");
info.emplace("date", timebuf);
auto written = db.write(prefix, info);
cout << "Number of sequences included: " << written.first << "\n";
cout << "Number of distinct arrangements " << written.second << "\n";
}
......
......@@ -212,6 +212,16 @@ main(int argc, char *argv[])
}
DBAccess db(prefix);
// check if db version is compative to program
auto db_versions = db.db_versions();
if (db_versions.count(2) == 0)
{
cerr << "Database version not compatible. Please update your database!" << endl;
exit(3);
}
BSDL::DomainArrangementSet<BSDL::Domain> querySet;
//read query arrangement
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment