File: db-postgresql.h

package info (click to toggle)
minetestmapper 20200328-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 252 kB
  • sloc: cpp: 2,454; sh: 65; ansic: 32; makefile: 9
file content (35 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef _DB_POSTGRESQL_H
#define _DB_POSTGRESQL_H

#include "db.h"
#include <libpq-fe.h>

class DBPostgreSQL : public DB {
public:
	DBPostgreSQL(const std::string &mapdir);
	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;
	void getBlocksByPos(BlockList &blocks,
			const std::vector<BlockPos> &positions) override;
	~DBPostgreSQL() override;

	bool preferRangeQueries() const override { return true; }

protected:
	PGresult *checkResults(PGresult *res, bool clear = true);
	void prepareStatement(const std::string &name, const std::string &sql);
	PGresult *execPrepared(
		const char *stmtName, const int paramsNumber,
		const void **params,
		const int *paramsLengths = NULL, const int *paramsFormats = NULL,
		bool clear = true
	);
	int pg_binary_to_int(PGresult *res, int row, int col);
	BlockPos pg_to_blockpos(PGresult *res, int row, int col);

private:
	PGconn *db;
};

#endif // _DB_POSTGRESQL_H