diff --git a/CMakeLists.txt b/CMakeLists.txt index ef394ec..3e2b79b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ endif(ENABLE_SQLITE3) # Find postgresql if(ENABLE_POSTGRESQL) - find_library(POSTGRESQL_LIBRARY pq) + find_library(POSTGRESQL_LIBRARY NAMES pq libpq) find_path(POSTGRESQL_INCLUDE_DIR libpq-fe.h PATH_SUFFIXES postgresql) message (STATUS "postgresql library: ${POSTGRESQL_LIBRARY}") message (STATUS "postgresql headers: ${POSTGRESQL_INCLUDE_DIR}") diff --git a/Minetestmapper/CMakeLists.txt b/Minetestmapper/CMakeLists.txt index 8abdf9d..2d25e0c 100644 --- a/Minetestmapper/CMakeLists.txt +++ b/Minetestmapper/CMakeLists.txt @@ -64,19 +64,32 @@ if(WIN32) add_library (wingetopt STATIC ../wingetopt/src/getopt.c) endif() + set(wingetopt_lib "") if(WIN32) set(wingetopt_lib wingetopt) endif() + set(leveldb_lib "") if(USE_LEVELDB) set(leveldb_lib ${LEVELDB_LIBRARY}) endif() + +set(postgresql_lib "") +if(USE_POSTGRESQL) + set(postgresql_lib ${POSTGRESQL_LIBRARY}) + if(WIN32) + # the libpq database driver requires htonl which is in the Ws2_32 library + set(postgresql_lib ${POSTGRESQL_LIBRARY} "Ws2_32.lib") + endif(WIN32) +endif() + + #link_directories (../wingetopt) # Fügen Sie der ausführbaren Datei für dieses Projekt eine Quelle hinzu. add_executable (Minetestmapper ${sources}) set_target_properties(Minetestmapper PROPERTIES COMPILE_FLAGS -DBUILDER_STATIC_DEFINE) -target_link_libraries(Minetestmapper ${wingetopt_lib} ${LIBGD_LIBRARY} ${ZLIB_LIBRARY} ${SQLITE3_LIBRARY} ${leveldb_lib}) +target_link_libraries(Minetestmapper ${wingetopt_lib} ${LIBGD_LIBRARY} ${ZLIB_LIBRARY} ${SQLITE3_LIBRARY} ${leveldb_lib} ${postgresql_lib}) # TODO: Fügen Sie bei Bedarf Tests und Installationsziele hinzu. diff --git a/Minetestmapper/TileGenerator.cpp b/Minetestmapper/TileGenerator.cpp index 0babea5..c5e9620 100644 --- a/Minetestmapper/TileGenerator.cpp +++ b/Minetestmapper/TileGenerator.cpp @@ -478,7 +478,7 @@ void TileGenerator::openDb(const std::string &input) #endif } else if (m_backend == "postgresql") { -#if USE_POSTGRESQL +#ifdef USE_POSTGRESQL DBPostgreSQL *db; m_db = db = new DBPostgreSQL(input); #else @@ -494,7 +494,7 @@ void TileGenerator::openDb(const std::string &input) #endif } else if (m_backend == "redis") { -#if USE_REDIS +#ifdef USE_REDIS m_db = new DBRedis(input); m_scanEntireWorld = true; #else diff --git a/Minetestmapper/db-postgresql.cpp b/Minetestmapper/db-postgresql.cpp index 3630e29..0e44cee 100644 --- a/Minetestmapper/db-postgresql.cpp +++ b/Minetestmapper/db-postgresql.cpp @@ -1,14 +1,16 @@ -#if USE_POSTGRESQL - - - #include "db-postgresql.h" + +#ifdef USE_POSTGRESQL + #include -#include // for usleep -#include +#if _WIN32 +#include // htonl +#else +#include // htonl +#endif + #include "Settings.h" -#include "types.h" #define BLOCKPOSLIST_QUERY_COMPAT "SELECT x, y, z FROM blocks" #define BLOCKPOSLISTBOUNDED_QUERY_COMPAT "SELECT x, y, z FROM blocks WHERE x BETWEEN $1 AND $2 AND y BETWEEN $3 AND $4 AND z BETWEEN $5 AND $6" @@ -149,9 +151,9 @@ const DB::BlockPosList &DBPostgreSQL::processBlockPosListQueryResult(PGresult *r } -DB::Block DBPostgreSQL::getBlockOnPos(const BlockPos &pos) +const DB::Block DBPostgreSQL::getBlockOnPos(const BlockPos &pos) { - Block block(pos,reinterpret_cast("")); + Block block(pos, {}); m_blocksQueriedCount++; @@ -165,7 +167,7 @@ DB::Block DBPostgreSQL::getBlockOnPos(const BlockPos &pos) + (result ? PQresultErrorMessage(result) : "(result was NULL)")); if (PQntuples(result) != 0) { - block = Block(pos, ustring(reinterpret_cast(PQgetvalue(result, 0, 0)), PQgetlength(result, 0, 0))); + block = Block(pos, reinterpret_cast(PQgetvalue(result, 0, 0)), PQgetlength(result, 0, 0)); m_blocksReadCount++; } diff --git a/Minetestmapper/db-postgresql.h b/Minetestmapper/db-postgresql.h index 8065c81..7b915d8 100644 --- a/Minetestmapper/db-postgresql.h +++ b/Minetestmapper/db-postgresql.h @@ -2,7 +2,7 @@ #include "config.h" -#if USE_POSTGRESQL +#ifdef USE_POSTGRESQL #include "db.h" #include @@ -10,18 +10,15 @@ #include #include -#include "types.h" class DBPostgreSQL : public DB { - typedef std::unordered_map BlockCache; - public: DBPostgreSQL(const std::string &mapdir); virtual int getBlocksQueriedCount(void); virtual int getBlocksReadCount(void); virtual const BlockPosList &getBlockPosList(); virtual const BlockPosList &getBlockPosList(BlockPos minPos, BlockPos maxPos); - virtual Block getBlockOnPos(const BlockPos &pos); + virtual const Block getBlockOnPos(const BlockPos &pos); ~DBPostgreSQL(); private: int m_blocksQueriedCount;