Storing URL & time & tags in the database works.
This commit is contained in:
parent
b7332de342
commit
a1e3c57da2
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
project(remwharead
|
project(remwharead
|
||||||
VERSION 0.0.0
|
VERSION 0.0.1
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
#include "sqlite.hpp"
|
#include "sqlite.hpp"
|
||||||
#include "parse_options.hpp"
|
#include "parse_options.hpp"
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::chrono::system_clock;
|
||||||
|
|
||||||
int main(const int argc, const char *argv[])
|
int main(const int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -33,10 +35,18 @@ int main(const int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
Database db;
|
Database db;
|
||||||
db ? cout << "success." : cout << "failure.";
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
db.store("a", "b", "c", "d", "e", "f", "g");
|
if (!db)
|
||||||
|
{
|
||||||
|
cerr << "Error: Database connection failed.\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opts.url.empty())
|
||||||
|
{
|
||||||
|
db.store(opts.url, "archive", system_clock::now(), opts.tags,
|
||||||
|
"title", "description", "fulltext");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,11 @@
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
#include <basedir.h>
|
#include <basedir.h>
|
||||||
#include <sqlite/execute.hpp>
|
#include <sqlite/execute.hpp>
|
||||||
#include <sqlite/query.hpp>
|
#include <sqlite/query.hpp>
|
||||||
|
#include "time.hpp"
|
||||||
#include "sqlite.hpp"
|
#include "sqlite.hpp"
|
||||||
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
@ -59,15 +61,26 @@ Database::operator bool() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::store(const string &uri, const string &archive_uri,
|
void Database::store(const string &uri, const string &archive_uri,
|
||||||
const string &datetime, const string &tags,
|
const system_clock::time_point &datetime,
|
||||||
const string &title, const string &description,
|
const vector<string> &tags, const string &title,
|
||||||
const string &fulltext)
|
const string &description, const string &fulltext)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const string strdatetime = timepoint_to_string(datetime);
|
||||||
|
string strtags;
|
||||||
|
for (const string &tag : tags)
|
||||||
|
{
|
||||||
|
strtags += tag;
|
||||||
|
if (tag != *(tags.rbegin()))
|
||||||
|
{
|
||||||
|
strtags += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sqlite::execute ins(*_con, "INSERT INTO remwharead "
|
sqlite::execute ins(*_con, "INSERT INTO remwharead "
|
||||||
"VALUES(?, ?, ?, ?, ?, ?, ?);");
|
"VALUES(?, ?, ?, ?, ?, ?, ?);");
|
||||||
ins % uri % archive_uri % datetime % tags
|
ins % uri % archive_uri % strdatetime % strtags
|
||||||
% title % description % fulltext;
|
% title % description % fulltext;
|
||||||
ins();
|
ins();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,14 @@
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
#include <sqlite/connection.hpp>
|
#include <sqlite/connection.hpp>
|
||||||
|
|
||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::chrono::system_clock;
|
||||||
|
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
|
@ -32,7 +36,8 @@ public:
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
|
|
||||||
void store(const string &uri, const string &archive_uri,
|
void store(const string &uri, const string &archive_uri,
|
||||||
const string &datetime, const string &tags, const string &title,
|
const system_clock::time_point &datetime,
|
||||||
|
const vector<string> &tags, const string &title,
|
||||||
const string &description, const string &fulltext);
|
const string &description, const string &fulltext);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue