#include "sqlite3.h"
}
-class ServerMap;
-
class Database_SQLite3 : public Database
{
public:
- Database_SQLite3(ServerMap *map, std::string savedir);
- virtual void beginSave();
- virtual void endSave();
-
- virtual bool saveBlock(v3s16 blockpos, std::string &data);
- virtual std::string loadBlock(v3s16 blockpos);
- virtual void listAllLoadableBlocks(std::list<v3s16> &dst);
- virtual int Initialized(void);
+ Database_SQLite3(const std::string &savedir);
~Database_SQLite3();
-private:
- ServerMap *srvmap;
- std::string m_savedir;
- sqlite3 *m_database;
- sqlite3_stmt *m_database_read;
- sqlite3_stmt *m_database_write;
- sqlite3_stmt *m_database_list;
+ void beginSave();
+ void endSave();
+
+ bool saveBlock(const v3s16 &pos, const std::string &data);
+ void loadBlock(const v3s16 &pos, std::string *block);
+ bool deleteBlock(const v3s16 &pos);
+ void listAllLoadableBlocks(std::vector<v3s16> &dst);
+ bool initialized() const { return m_initialized; }
+
+private:
+ // Open the database
+ void openDatabase();
// Create the database structure
void createDatabase();
- // Verify we can read/write to the database
+ // Open and initialize the database if needed
void verifyDatabase();
- void createDirs(std::string path);
+
+ void bindPos(sqlite3_stmt *stmt, const v3s16 &pos, int index=1);
+
+ bool m_initialized;
+
+ std::string m_savedir;
+
+ sqlite3 *m_database;
+ sqlite3_stmt *m_stmt_read;
+ sqlite3_stmt *m_stmt_write;
+ sqlite3_stmt *m_stmt_list;
+ sqlite3_stmt *m_stmt_delete;
+ sqlite3_stmt *m_stmt_begin;
+ sqlite3_stmt *m_stmt_end;
+
+ s64 m_busy_handler_data[2];
+
+ static int busyHandler(void *data, int count);
};
#endif
+