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)
|
||||
project(remwharead
|
||||
VERSION 0.0.0
|
||||
VERSION 0.0.1
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include "sqlite.hpp"
|
||||
#include "parse_options.hpp"
|
||||
|
||||
|
@ -23,6 +24,7 @@ using std::cout;
|
|||
using std::cerr;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
int main(const int argc, const char *argv[])
|
||||
{
|
||||
|
@ -33,10 +35,18 @@ int main(const int argc, const char *argv[])
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <basedir.h>
|
||||
#include <sqlite/execute.hpp>
|
||||
#include <sqlite/query.hpp>
|
||||
#include "time.hpp"
|
||||
#include "sqlite.hpp"
|
||||
|
||||
using std::cerr;
|
||||
|
@ -59,15 +61,26 @@ Database::operator bool() const
|
|||
}
|
||||
|
||||
void Database::store(const string &uri, const string &archive_uri,
|
||||
const string &datetime, const string &tags,
|
||||
const string &title, const string &description,
|
||||
const string &fulltext)
|
||||
const system_clock::time_point &datetime,
|
||||
const vector<string> &tags, const string &title,
|
||||
const string &description, const string &fulltext)
|
||||
{
|
||||
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 "
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?);");
|
||||
ins % uri % archive_uri % datetime % tags
|
||||
ins % uri % archive_uri % strdatetime % strtags
|
||||
% title % description % fulltext;
|
||||
ins();
|
||||
}
|
||||
|
|
|
@ -20,10 +20,14 @@
|
|||
#include <experimental/filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <sqlite/connection.hpp>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
class Database
|
||||
{
|
||||
|
@ -32,7 +36,8 @@ public:
|
|||
operator bool() const;
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue