Get postgresql working

master
Unknown 2018-04-24 17:47:05 +02:00
parent ef63050152
commit b195c126d2
5 changed files with 31 additions and 19 deletions

View File

@ -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}")

View File

@ -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.

View File

@ -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

View File

@ -1,14 +1,16 @@
#if USE_POSTGRESQL
#include "db-postgresql.h"
#ifdef USE_POSTGRESQL
#include <stdexcept>
#include <unistd.h> // for usleep
#include <arpa/inet.h>
#if _WIN32
#include <Winsock2.h> // htonl
#else
#include <arpa/inet.h> // 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<const unsigned char *>(""));
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<unsigned char *>(PQgetvalue(result, 0, 0)), PQgetlength(result, 0, 0)));
block = Block(pos, reinterpret_cast<unsigned char *>(PQgetvalue(result, 0, 0)), PQgetlength(result, 0, 0));
m_blocksReadCount++;
}

View File

@ -2,7 +2,7 @@
#include "config.h"
#if USE_POSTGRESQL
#ifdef USE_POSTGRESQL
#include "db.h"
#include <libpq-fe.h>
@ -10,18 +10,15 @@
#include <string>
#include <sstream>
#include "types.h"
class DBPostgreSQL : public DB {
typedef std::unordered_map<int64_t, ustring> 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;