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:
+10
-2
@@ -193,13 +193,17 @@ file(GLOB source_network
|
|||||||
src/network/*.[hc]pp)
|
src/network/*.[hc]pp)
|
||||||
add_library(network OBJECT ${source_network})
|
add_library(network OBJECT ${source_network})
|
||||||
|
|
||||||
if(SQLITE3_FOUND)
|
if(SQLITE3_FOUND OR PQ_FOUND)
|
||||||
file(GLOB source_database
|
file(GLOB source_database
|
||||||
src/database/*.[hc]pp)
|
src/database/*.[hc]pp)
|
||||||
add_library(database OBJECT ${source_database})
|
add_library(database OBJECT ${source_database})
|
||||||
|
|
||||||
|
if(SQLITE3_FOUND)
|
||||||
include_directories(database ${SQLITE3_INCLUDE_DIRS})
|
include_directories(database ${SQLITE3_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
if(PQ_FOUND)
|
||||||
include_directories(database ${PQ_INCLUDE_DIRS})
|
include_directories(database ${PQ_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
set(USE_DATABASE TRUE)
|
set(USE_DATABASE TRUE)
|
||||||
else()
|
else()
|
||||||
add_library(database OBJECT "")
|
add_library(database OBJECT "")
|
||||||
@@ -267,11 +271,15 @@ if(LIBIDN_FOUND)
|
|||||||
target_link_libraries(test_suite ${LIBIDN_LIBRARIES})
|
target_link_libraries(test_suite ${LIBIDN_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
if(USE_DATABASE)
|
if(USE_DATABASE)
|
||||||
|
if(SQLITE3_FOUND)
|
||||||
target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIBRARIES})
|
||||||
target_link_libraries(${PROJECT_NAME} ${PQ_LIBRARIES})
|
|
||||||
target_link_libraries(test_suite ${SQLITE3_LIBRARIES})
|
target_link_libraries(test_suite ${SQLITE3_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
if(PQ_FOUND)
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${PQ_LIBRARIES})
|
||||||
target_link_libraries(test_suite ${PQ_LIBRARIES})
|
target_link_libraries(test_suite ${PQ_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Define a __FILENAME__ macro with the relative path (from the base project directory)
|
# Define a __FILENAME__ macro with the relative path (from the base project directory)
|
||||||
# of each source file
|
# of each source file
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#cmakedefine BOTAN_FOUND
|
#cmakedefine BOTAN_FOUND
|
||||||
#cmakedefine GCRYPT_FOUND
|
#cmakedefine GCRYPT_FOUND
|
||||||
#cmakedefine UDNS_FOUND
|
#cmakedefine UDNS_FOUND
|
||||||
|
#cmakedefine PQ_FOUND
|
||||||
|
#cmakedefine SQLITE3_FOUND
|
||||||
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
|
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
|
||||||
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
|
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
|
||||||
#cmakedefine HAS_GET_TIME
|
#cmakedefine HAS_GET_TIME
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
struct CountQuery: public Query
|
struct CountQuery: public Query
|
||||||
{
|
{
|
||||||
CountQuery(std::string name):
|
CountQuery(std::string name):
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
std::unique_ptr<DatabaseEngine> Database::db;
|
std::unique_ptr<DatabaseEngine> Database::db;
|
||||||
Database::MucLogLineTable Database::muc_log_lines("muclogline_");
|
Database::MucLogLineTable Database::muc_log_lines("muclogline_");
|
||||||
Database::GlobalOptionsTable Database::global_options("globaloptions_");
|
Database::GlobalOptionsTable Database::global_options("globaloptions_");
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
template <std::size_t N=0, typename... T>
|
template <std::size_t N=0, typename... T>
|
||||||
typename std::enable_if<N < sizeof...(T), void>::type
|
typename std::enable_if<N < sizeof...(T), void>::type
|
||||||
update_autoincrement_id(std::tuple<T...>& columns, Statement& statement)
|
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_engine.hpp>
|
||||||
|
|
||||||
#include <database/postgresql_statement.hpp>
|
#include <database/postgresql_statement.hpp>
|
||||||
@@ -75,3 +78,5 @@ std::string PostgresqlEngine::id_column_type()
|
|||||||
{
|
{
|
||||||
return "SERIAL";
|
return "SERIAL";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <database/engine.hpp>
|
#include <biboumi.h>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <database/statement.hpp>
|
#include <database/statement.hpp>
|
||||||
|
#include <database/engine.hpp>
|
||||||
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#ifdef PQ_FOUND
|
||||||
|
|
||||||
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
class PostgresqlEngine: public DatabaseEngine
|
class PostgresqlEngine: public DatabaseEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -29,3 +33,16 @@ class PostgresqlEngine: public DatabaseEngine
|
|||||||
private:
|
private:
|
||||||
PGconn* const conn;
|
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 <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
void actual_bind(Statement& statement, const std::string& value, int index);
|
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 std::size_t value, int index);
|
||||||
void actual_bind(Statement& statement, const OptionalBool& value, int index);
|
void actual_bind(Statement& statement, const OptionalBool& value, int index);
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
struct Row
|
struct Row
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,12 +12,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
template <typename T>
|
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)
|
extract_row_value(Statement& statement, const int i)
|
||||||
{
|
{
|
||||||
return statement.get_column_int64(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_engine.hpp>
|
||||||
|
|
||||||
#include <database/sqlite3_statement.hpp>
|
#include <database/sqlite3_statement.hpp>
|
||||||
@@ -91,3 +95,5 @@ std::string Sqlite3Engine::id_column_type()
|
|||||||
{
|
{
|
||||||
return "INTEGER PRIMARY KEY AUTOINCREMENT";
|
return "INTEGER PRIMARY KEY AUTOINCREMENT";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
|
|
||||||
#include <database/statement.hpp>
|
#include <database/statement.hpp>
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include <biboumi.h>
|
||||||
|
|
||||||
|
#ifdef SQLITE3_FOUND
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
class Sqlite3Engine: public DatabaseEngine
|
class Sqlite3Engine: public DatabaseEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -28,3 +33,15 @@ private:
|
|||||||
sqlite3* const db;
|
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/xdg.hpp>
|
||||||
#include <utils/reload.hpp>
|
#include <utils/reload.hpp>
|
||||||
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
|
|
||||||
#ifdef UDNS_FOUND
|
#ifdef UDNS_FOUND
|
||||||
# include <network/dns_handler.hpp>
|
# include <network/dns_handler.hpp>
|
||||||
#endif
|
#endif
|
||||||
@@ -90,7 +88,8 @@ int main(int ac, char** av)
|
|||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
try {
|
try {
|
||||||
open_database();
|
open_database();
|
||||||
} catch (...) {
|
} catch (const std::exception& e) {
|
||||||
|
log_error(e.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user