Switched from vsqlite++ to POCO.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
tastytea 2019-08-07 19:41:58 +02:00
parent cbcd64e172
commit fafb0c8aa1
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
9 changed files with 71 additions and 60 deletions

View File

@ -25,7 +25,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q - apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config - apt-get install -qy g++-6 cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8 - locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_TESTS=YES -DWITH_MOZILLA=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_TESTS=YES -DWITH_MOZILLA=YES ..
@ -55,7 +55,7 @@ steps:
- apt-get update -q - apt-get update -q
- apt-get install -qy -t xenial g++-5 - apt-get install -qy -t xenial g++-5
- apt-get install -qy cmake pkg-config - apt-get install -qy cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES ..
- make VERBOSE=1 - make VERBOSE=1
@ -82,7 +82,7 @@ steps:
- apt-get update -q - apt-get update -q
- apt-get install -qy -t xenial g++-9 - apt-get install -qy -t xenial g++-9
- apt-get install -qy cmake pkg-config - apt-get install -qy cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES ..
- make VERBOSE=1 - make VERBOSE=1
@ -102,7 +102,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q - apt-get update -q
- apt-get install -qy clang cmake pkg-config - apt-get install -qy clang cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES ..
- make VERBOSE=1 - make VERBOSE=1
@ -122,7 +122,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q - apt-get update -q
- apt-get install -qy clang cmake pkg-config - apt-get install -qy clang cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES ..
- make VERBOSE=1 - make VERBOSE=1
@ -173,7 +173,7 @@ steps:
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get' - alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
- apt-get update -q - apt-get update -q
- apt-get install -qy g++-6 cmake pkg-config - apt-get install -qy g++-6 cmake pkg-config
- apt-get install -qy libpoco-dev libxdg-basedir-dev libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc catch - apt-get install -qy libpoco-dev libxdg-basedir-dev asciidoc catch
- apt-get install -qy build-essential file - apt-get install -qy build-essential file
- rm -rf build && mkdir -p build && cd build - rm -rf build && mkdir -p build && cd build
- cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES -DMOZILLA_NMH_DIR="lib/mozilla/native-messaging-hosts" -DWITH_DEB=YES .. - cmake -DCMAKE_INSTALL_PREFIX=/usr -DWITH_MOZILLA=YES -DMOZILLA_NMH_DIR="lib/mozilla/native-messaging-hosts" -DWITH_DEB=YES ..

View File

@ -60,7 +60,6 @@ only.
* https://pkgconfig.freedesktop.org/wiki/[pkgconfig] (tested: 0.29) * https://pkgconfig.freedesktop.org/wiki/[pkgconfig] (tested: 0.29)
* http://repo.or.cz/w/libxdg-basedir.git[libxdg-basedir] (tested: 1.2) * http://repo.or.cz/w/libxdg-basedir.git[libxdg-basedir] (tested: 1.2)
* https://pocoproject.org/[POCO] (tested: 1.9 / 1.7) * https://pocoproject.org/[POCO] (tested: 1.9 / 1.7)
* http://vsqlite.virtuosic-bytes.com/[vsqlite++] (tested: 0.3)
* Optional: * Optional:
** Manpage: http://asciidoc.org/[asciidoc] (tested: 8.6) ** Manpage: http://asciidoc.org/[asciidoc] (tested: 8.6)
** Tests: https://github.com/catchorg/Catch2[catch] (tested: 2.5 / 1.2) ** Tests: https://github.com/catchorg/Catch2[catch] (tested: 2.5 / 1.2)
@ -72,8 +71,7 @@ only.
[source,zsh] [source,zsh]
---- ----
apt-get update apt-get update
apt-get install g++-6 cmake pkg-config libpoco-dev libxdg-basedir-dev \ apt-get install g++-6 cmake pkg-config libpoco-dev libxdg-basedir-dev asciidoc dpkg
libvsqlitepp-dev libboost-system-dev libboost-filesystem-dev asciidoc
export CXX="g++-6" export CXX="g++-6"
---- ----
==== ====

View File

@ -45,7 +45,7 @@ if (WITH_RPM)
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3") set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}") set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES set(CPACK_RPM_PACKAGE_REQUIRES
"poco-netssl >= 1.6, libxdg-basedir, vsqlite++ >= 0.3") "poco-netssl >= 1.6, poco-sqlite >= 1.6, libxdg-basedir")
set(CPACK_PACKAGE_FILE_NAME set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}") "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME set(CPACK_SOURCE_PACKAGE_FILE_NAME

View File

@ -1,15 +1,10 @@
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
include(GNUInstallDirs) include(GNUInstallDirs)
find_depencency(Poco COMPONENTS Foundation Net NetSSL CONFIG REQUIRED) find_depencency(Poco
COMPONENTS Foundation Net NetSSL DataSQLite
CONFIG REQUIRED)
find_dependency(PkgConfig REQUIRED) find_dependency(PkgConfig REQUIRED)
pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir)
find_file(vsqlitepp NAMES "sqlite/connection.hpp"
PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
if("${vsqlitepp}" STREQUAL "vsqlitepp-NOTFOUND")
message(FATAL_ERROR "Could not find vsqlite++.")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

View File

@ -22,7 +22,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <chrono> #include <chrono>
#include <sqlite/connection.hpp> #include <Poco/Data/Session.h>
namespace remwharead namespace remwharead
{ {
@ -31,6 +31,7 @@ namespace remwharead
using std::vector; using std::vector;
using std::chrono::system_clock; using std::chrono::system_clock;
using time_point = system_clock::time_point; using time_point = system_clock::time_point;
using Poco::Data::Session;
/*! /*!
* @brief Store and retrieve files from/to SQLite. * @brief Store and retrieve files from/to SQLite.
@ -82,7 +83,7 @@ namespace remwharead
private: private:
fs::path _dbpath; fs::path _dbpath;
std::unique_ptr<sqlite::connection> _con; std::unique_ptr<Session> _session;
bool _connected; bool _connected;
}; };

View File

@ -8,6 +8,6 @@ Name: ${name}
Description: @PROJECT_DESCRIPTION@ Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@ Version: @PROJECT_VERSION@
Cflags: -I${includedir} Cflags: -I${includedir}
Libs: -L${libdir} -l${name} -lvsqlitepp -lstdc++fs Libs: -L${libdir} -l${name} -lPocoDataSQLite -lstdc++fs
Requires.private: libxdg-basedir, icu-uc, icu-i18n Requires.private: libxdg-basedir, icu-uc, icu-i18n
Libs.private: -lPocoFoundation -lPocoNet -lPocoNetSSL Libs.private: -lPocoFoundation -lPocoNet -lPocoNetSSL

View File

@ -113,7 +113,10 @@ void App::handle_options(const std::string &name, const std::string &value)
{ {
buffer.erase(buffer.end() - 1); buffer.erase(buffer.end() - 1);
} }
_tags.push_back(buffer); if (!buffer.empty())
{
_tags.push_back(buffer);
}
pos_start = pos_end + 1; pos_start = pos_end + 1;
} }
} }

View File

@ -3,7 +3,7 @@ include(GNUInstallDirs)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir) pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir)
# Some distributions do not contain Poco*Config.cmake recipes. # Some distributions do not contain Poco*Config.cmake recipes.
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG) find_package(Poco COMPONENTS Foundation Net NetSSL DataSQLite CONFIG)
file(GLOB_RECURSE sources_lib *.cpp) file(GLOB_RECURSE sources_lib *.cpp)
file(GLOB_RECURSE headers_lib ../../include/*.hpp) file(GLOB_RECURSE headers_lib ../../include/*.hpp)
@ -23,12 +23,13 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE PkgConfig::libxdg-basedir PRIVATE PkgConfig::libxdg-basedir
PUBLIC vsqlitepp stdc++fs) PUBLIC stdc++fs)
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs. # If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
if(PocoNetSSL_FOUND) if(PocoNetSSL_FOUND)
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL) PRIVATE Poco::Foundation Poco::Net Poco::NetSSL
PUBLIC Poco::DataSQLite)
else() else()
find_file(Poco_h NAMES "Poco/Poco.h" find_file(Poco_h NAMES "Poco/Poco.h"
PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
@ -41,7 +42,8 @@ else()
"but the files seem to be in the standard directories. " "but the files seem to be in the standard directories. "
"Let's hope this works.") "Let's hope this works.")
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE PocoFoundation PocoNet PocoNetSSL) PRIVATE PocoFoundation PocoNet PocoNetSSL
PUBLIC PocoDataSQLite)
endif() endif()
endif() endif()

View File

@ -18,8 +18,8 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <basedir.h> #include <basedir.h>
#include <sqlite/execute.hpp> #include <Poco/Data/Session.h>
#include <sqlite/query.hpp> #include <Poco/Data/SQLite/Connector.h>
#include "time.hpp" #include "time.hpp"
#include "sqlite.hpp" #include "sqlite.hpp"
@ -27,6 +27,8 @@ namespace remwharead
{ {
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using namespace Poco::Data::Keywords;
using Poco::Data::Statement;
Database::Database() Database::Database()
: _connected(false) : _connected(false)
@ -44,11 +46,11 @@ namespace remwharead
} }
_dbpath /= "database.sqlite"; _dbpath /= "database.sqlite";
_con = std::make_unique<sqlite::connection>(_dbpath); Poco::Data::SQLite::Connector::registerConnector();
sqlite::execute(*_con, "CREATE TABLE IF NOT EXISTS remwharead(" _session = std::make_unique<Session>("SQLite", _dbpath);
"uri TEXT, archive_uri TEXT, datetime TEXT, " *_session << "CREATE TABLE IF NOT EXISTS remwharead("
"tags TEXT, title TEXT, description TEXT, " "uri TEXT, archive_uri TEXT, datetime TEXT, "
"fulltext TEXT);", true); "tags TEXT, title TEXT, description TEXT, fulltext TEXT);", now;
_connected = true; _connected = true;
} }
@ -72,7 +74,7 @@ namespace remwharead
{ {
string oneline = fulltext; string oneline = fulltext;
size_t pos = 0; size_t pos = 0;
while ((pos = oneline.find('\n', pos)) != std::string::npos) while ((pos = oneline.find('\n', pos)) != string::npos)
{ {
oneline.replace(pos, 1, "\\n"); oneline.replace(pos, 1, "\\n");
} }
@ -85,6 +87,8 @@ namespace remwharead
{ {
const string strdatetime = timepoint_to_string(data.datetime, true); const string strdatetime = timepoint_to_string(data.datetime, true);
string strtags; string strtags;
Statement insert(*_session);
for (const string &tag : data.tags) for (const string &tag : data.tags)
{ {
strtags += tag; strtags += tag;
@ -94,11 +98,13 @@ namespace remwharead
} }
} }
sqlite::execute ins(*_con, "INSERT INTO remwharead " // useRef() uses the const reference.
"VALUES(?, ?, ?, ?, ?, ?, ?);"); insert << "INSERT INTO remwharead "
ins % data.uri % data.archive_uri % strdatetime % strtags "VALUES(?, ?, ?, ?, ?, ?, ?);",
% data.title % data.description % data.fulltext; useRef(data.uri), useRef(data.archive_uri),
ins(); useRef(strdatetime), useRef(strtags), useRef(data.title),
useRef(data.description), useRef(data.fulltext);
insert.execute();
} }
catch (std::exception &e) catch (std::exception &e)
{ {
@ -111,40 +117,46 @@ namespace remwharead
{ {
try try
{ {
const string query = "SELECT * FROM remwharead WHERE datetime " Database::entry entrybuf;
"BETWEEN '" + timepoint_to_string(start, true) string datetime, strtags;
+ "' AND '" + timepoint_to_string(end, true) Statement select(*_session);
+ "' ORDER BY datetime DESC;";
// bind() copies the value.
select << "SELECT * FROM remwharead WHERE datetime "
"BETWEEN ? AND ? ORDER BY datetime DESC;",
bind(timepoint_to_string(start, true)),
bind(timepoint_to_string(end, true)),
into(entrybuf.uri), into(entrybuf.archive_uri), into(datetime),
into(strtags), into(entrybuf.title), into(entrybuf.description),
into(entrybuf.fulltext), range(0, 1);
sqlite::query q(*_con, query);
sqlite::result_type res = q.get_result();
vector<entry> entries; vector<entry> entries;
while(res->next_row()) while(!select.done())
{ {
select.execute();
entrybuf.datetime = string_to_timepoint(datetime);
vector<string> tags; vector<string> tags;
const string strtags = res->get_string(3);
size_t pos = 0; size_t pos = 0;
while (pos != std::string::npos) while (pos != string::npos)
{ {
const size_t newpos = strtags.find(',', pos); const size_t newpos = strtags.find(',', pos);
tags.push_back(strtags.substr(pos, newpos - pos)); const string tag = strtags.substr(pos, newpos - pos);
if (!tag.empty())
{
tags.push_back(tag);
}
pos = newpos; pos = newpos;
if (pos != std::string::npos) if (pos != string::npos)
{ {
++pos; ++pos;
} }
} }
entries.push_back entrybuf.tags = tags;
({
res->get_string(0), entries.push_back(entrybuf);
res->get_string(1),
string_to_timepoint(res->get_string(2), true),
tags,
res->get_string(4),
res->get_string(5),
res->get_string(6)
});
} }
return entries; return entries;