Improve error handling of map database creation
This commit is contained in:
@@ -9,20 +9,20 @@
|
||||
#include "database.h"
|
||||
#include "util/basic_macros.h"
|
||||
|
||||
class Settings;
|
||||
|
||||
class Database_PostgreSQL: public Database
|
||||
// Template class for PostgreSQL based data storage
|
||||
class Database_PostgreSQL : public Database
|
||||
{
|
||||
public:
|
||||
Database_PostgreSQL(const std::string &connect_string, const char *type);
|
||||
~Database_PostgreSQL();
|
||||
|
||||
void beginSave();
|
||||
void endSave();
|
||||
void beginSave() override;
|
||||
void endSave() override;
|
||||
void rollback();
|
||||
|
||||
bool initialized() const;
|
||||
bool initialized() const override;
|
||||
|
||||
void verifyDatabase() override;
|
||||
|
||||
protected:
|
||||
// Conversion helpers
|
||||
@@ -73,7 +73,6 @@ class Database_PostgreSQL: public Database
|
||||
}
|
||||
|
||||
void createTableIfNotExists(const std::string &table_name, const std::string &definition);
|
||||
void verifyDatabase();
|
||||
|
||||
// Database initialization
|
||||
void connectToDatabase();
|
||||
@@ -99,6 +98,12 @@ class Database_PostgreSQL: public Database
|
||||
int m_pgversion = 0;
|
||||
};
|
||||
|
||||
// Not sure why why we have to do this. can't C++ figure it out on its own?
|
||||
#define PARENT_CLASS_FUNCS \
|
||||
void beginSave() { Database_PostgreSQL::beginSave(); } \
|
||||
void endSave() { Database_PostgreSQL::endSave(); } \
|
||||
void verifyDatabase() { Database_PostgreSQL::verifyDatabase(); }
|
||||
|
||||
class MapDatabasePostgreSQL : private Database_PostgreSQL, public MapDatabase
|
||||
{
|
||||
public:
|
||||
@@ -110,8 +115,7 @@ class MapDatabasePostgreSQL : private Database_PostgreSQL, public MapDatabase
|
||||
bool deleteBlock(const v3s16 &pos);
|
||||
void listAllLoadableBlocks(std::vector<v3s16> &dst);
|
||||
|
||||
void beginSave() { Database_PostgreSQL::beginSave(); }
|
||||
void endSave() { Database_PostgreSQL::endSave(); }
|
||||
PARENT_CLASS_FUNCS
|
||||
|
||||
protected:
|
||||
virtual void createDatabase();
|
||||
@@ -129,6 +133,8 @@ class PlayerDatabasePostgreSQL : private Database_PostgreSQL, public PlayerDatab
|
||||
bool removePlayer(const std::string &name);
|
||||
void listPlayers(std::vector<std::string> &res);
|
||||
|
||||
PARENT_CLASS_FUNCS
|
||||
|
||||
protected:
|
||||
virtual void createDatabase();
|
||||
virtual void initStatements();
|
||||
@@ -143,8 +149,6 @@ class AuthDatabasePostgreSQL : private Database_PostgreSQL, public AuthDatabase
|
||||
AuthDatabasePostgreSQL(const std::string &connect_string);
|
||||
virtual ~AuthDatabasePostgreSQL() = default;
|
||||
|
||||
virtual void verifyDatabase() { Database_PostgreSQL::verifyDatabase(); }
|
||||
|
||||
virtual bool getAuth(const std::string &name, AuthEntry &res);
|
||||
virtual bool saveAuth(const AuthEntry &authEntry);
|
||||
virtual bool createAuth(AuthEntry &authEntry);
|
||||
@@ -152,6 +156,8 @@ class AuthDatabasePostgreSQL : private Database_PostgreSQL, public AuthDatabase
|
||||
virtual void listNames(std::vector<std::string> &res);
|
||||
virtual void reload();
|
||||
|
||||
PARENT_CLASS_FUNCS
|
||||
|
||||
protected:
|
||||
virtual void createDatabase();
|
||||
virtual void initStatements();
|
||||
@@ -176,10 +182,11 @@ class ModStorageDatabasePostgreSQL : private Database_PostgreSQL, public ModStor
|
||||
bool removeModEntries(const std::string &modname);
|
||||
void listMods(std::vector<std::string> *res);
|
||||
|
||||
void beginSave() { Database_PostgreSQL::beginSave(); }
|
||||
void endSave() { Database_PostgreSQL::endSave(); }
|
||||
PARENT_CLASS_FUNCS
|
||||
|
||||
protected:
|
||||
virtual void createDatabase();
|
||||
virtual void initStatements();
|
||||
};
|
||||
|
||||
#undef PARENT_CLASS_FUNCS
|
||||
|
||||
Reference in New Issue
Block a user