8#define LOG std::cout << "PluginSQL: "
9#define ERR std::cerr << "PluginSQL: "
12 template<
typename cell_t>
26 host(config[
"sql"][
"host"]),
27 port(config[
"sql"][
"port"]),
28 user(config[
"sql"][
"user"]),
29 password(config[
"sql"][
"password"]),
30 database(config[
"sql"][
"database"]),
31 scheme(config[
"id"].
get<
std::string>()),
32 conn(user, password, host, port, database){
33 CreateTables(dropTables);
36 template<
typename world_t>
38 std::stringstream cellInsertStatement;
39 std::stringstream worldInsertStatement;
49 auto &cells = w->cells;
50 for (
size_t i = 0; i < std::max(
int(cells.size() - 1),0); i++) {
52 cellInsertStatement <<
", ";
58 cellInsertStatement <<
";";
61 if(cells.size() > 0) conn.
Execute(cellInsertStatement.str());
69 conn.
Execute(worldInsertStatement.str());
75 }
catch (
const std::exception &e) {
85 if (dropTablesIfExist) {
87 std::string dropCellTable =
"DROP TABLE IF EXISTS " + scheme.
CellTable +
";";
94 if (dropTablesIfExist) {
96 std::string dropWorldTable =
"DROP TABLE IF EXISTS " + scheme.
WorldTable +
";";
void Execute(std::string query)
void endUpdate(world_t *w)
PluginSQL(nlohmann::json const &config, bool dropTables=false)
void CreateTables(bool dropTablesIfExist)
a class to store JSON values
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Provides common mathematical functions and vector operations.
iostream endl
End-of-line manipulator.
void CellValueStatement(std::stringstream &ss, cell_t *c, world_t *w)
const std::string WorldTable
const std::string WorldTableDataLayout
const std::string CellTable
const std::string CellTableDataLayout
std::string WorldTableCreationStatement
std::string CellTableCreationStatement
std::string WorldValueStatement(world_t *w)