2014-03-05 21:41:27 +01:00
|
|
|
#ifndef _DB_SQLITE3_H
|
|
|
|
#define _DB_SQLITE3_H
|
|
|
|
|
|
|
|
#include "db.h"
|
2020-03-27 16:12:26 +01:00
|
|
|
#include <unordered_map>
|
2014-03-05 21:41:27 +01:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
class DBSQLite3 : public DB {
|
|
|
|
public:
|
|
|
|
DBSQLite3(const std::string &mapdir);
|
2020-03-27 16:12:26 +01:00
|
|
|
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
|
|
|
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
|
|
|
int16_t min_y, int16_t max_y) override;
|
2020-03-27 21:10:00 +01:00
|
|
|
void getBlocksByPos(BlockList &blocks,
|
|
|
|
const std::vector<BlockPos> &positions) override;
|
2020-03-27 16:12:26 +01:00
|
|
|
~DBSQLite3() override;
|
|
|
|
|
2020-03-27 21:10:00 +01:00
|
|
|
bool preferRangeQueries() const override { return false; }
|
|
|
|
|
2014-03-05 21:41:27 +01:00
|
|
|
private:
|
2020-03-27 16:12:26 +01:00
|
|
|
inline void getPosRange(int64_t &min, int64_t &max, int16_t zPos,
|
|
|
|
int16_t zPos2) const;
|
|
|
|
void loadBlockCache(int16_t zPos);
|
|
|
|
|
2014-03-28 21:47:19 +01:00
|
|
|
sqlite3 *db;
|
2014-03-28 18:42:37 +01:00
|
|
|
|
|
|
|
sqlite3_stmt *stmt_get_block_pos;
|
2020-03-27 16:12:26 +01:00
|
|
|
sqlite3_stmt *stmt_get_block_pos_z;
|
2014-04-19 08:13:34 +02:00
|
|
|
sqlite3_stmt *stmt_get_blocks_z;
|
2020-03-27 21:10:00 +01:00
|
|
|
sqlite3_stmt *stmt_get_block_exact;
|
2020-03-27 16:12:26 +01:00
|
|
|
|
|
|
|
int16_t blockCachedZ = -10000;
|
|
|
|
std::unordered_map<int16_t, BlockList> blockCache; // indexed by X
|
2014-03-05 21:41:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _DB_SQLITE3_H
|