Handle postgresql and sqlite3 libs properly
Do not fail to compile when one of them is missing but the other one is not. Raise an error when trying to open a database with the missing library. see #3237
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#cmakedefine BOTAN_FOUND
|
||||
#cmakedefine GCRYPT_FOUND
|
||||
#cmakedefine UDNS_FOUND
|
||||
#cmakedefine PQ_FOUND
|
||||
#cmakedefine SQLITE3_FOUND
|
||||
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
|
||||
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
|
||||
#cmakedefine HAS_GET_TIME
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
struct CountQuery: public Query
|
||||
{
|
||||
CountQuery(std::string name):
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
std::unique_ptr<DatabaseEngine> Database::db;
|
||||
Database::MucLogLineTable Database::muc_log_lines("muclogline_");
|
||||
Database::GlobalOptionsTable Database::global_options("globaloptions_");
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
template <std::size_t N=0, typename... T>
|
||||
typename std::enable_if<N < sizeof...(T), void>::type
|
||||
update_autoincrement_id(std::tuple<T...>& columns, Statement& statement)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <biboumi.h>
|
||||
#ifdef PQ_FOUND
|
||||
|
||||
#include <database/postgresql_engine.hpp>
|
||||
|
||||
#include <database/postgresql_statement.hpp>
|
||||
@@ -75,3 +78,5 @@ std::string PostgresqlEngine::id_column_type()
|
||||
{
|
||||
return "SERIAL";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <database/engine.hpp>
|
||||
#include <biboumi.h>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
|
||||
#include <database/statement.hpp>
|
||||
#include <database/engine.hpp>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <set>
|
||||
|
||||
#ifdef PQ_FOUND
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
class PostgresqlEngine: public DatabaseEngine
|
||||
{
|
||||
public:
|
||||
@@ -29,3 +33,16 @@ class PostgresqlEngine: public DatabaseEngine
|
||||
private:
|
||||
PGconn* const conn;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class PostgresqlEngine
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<DatabaseEngine> open(const std::string& string)
|
||||
{
|
||||
throw std::runtime_error("Cannot open postgresql database "s + string + ": biboumi is not compiled with libpq.");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
void actual_bind(Statement& statement, const std::string& value, int index);
|
||||
void actual_bind(Statement& statement, const std::size_t value, int index);
|
||||
void actual_bind(Statement& statement, const OptionalBool& value, int index);
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
template <typename... T>
|
||||
struct Row
|
||||
{
|
||||
|
||||
@@ -12,12 +12,10 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, sqlite3_int64>::type
|
||||
typename std::enable_if<std::is_integral<T>::value, std::int64_t>::type
|
||||
extract_row_value(Statement& statement, const int i)
|
||||
{
|
||||
return statement.get_column_int64(i);
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#include <biboumi.h>
|
||||
|
||||
#ifdef SQLITE3_FOUND
|
||||
|
||||
#include <database/sqlite3_engine.hpp>
|
||||
|
||||
#include <database/sqlite3_statement.hpp>
|
||||
@@ -91,3 +95,5 @@ std::string Sqlite3Engine::id_column_type()
|
||||
{
|
||||
return "INTEGER PRIMARY KEY AUTOINCREMENT";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,12 +4,17 @@
|
||||
|
||||
#include <database/statement.hpp>
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <set>
|
||||
|
||||
#include <biboumi.h>
|
||||
|
||||
#ifdef SQLITE3_FOUND
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
class Sqlite3Engine: public DatabaseEngine
|
||||
{
|
||||
public:
|
||||
@@ -28,3 +33,15 @@ private:
|
||||
sqlite3* const db;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class Sqlite3Engine
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<DatabaseEngine> open(const std::string& string)
|
||||
{
|
||||
throw std::runtime_error("Cannot open sqlite3 database "s + string + ": biboumi is not compiled with sqlite3 lib.");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+2
-3
@@ -6,8 +6,6 @@
|
||||
#include <utils/xdg.hpp>
|
||||
#include <utils/reload.hpp>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
#ifdef UDNS_FOUND
|
||||
# include <network/dns_handler.hpp>
|
||||
#endif
|
||||
@@ -90,7 +88,8 @@ int main(int ac, char** av)
|
||||
#ifdef USE_DATABASE
|
||||
try {
|
||||
open_database();
|
||||
} catch (...) {
|
||||
} catch (const std::exception& e) {
|
||||
log_error(e.what());
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user