2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <mysql_connection.h>
|
|
|
|
#include <cppconn/driver.h>
|
|
|
|
#include <cppconn/exception.h>
|
|
|
|
#include <cppconn/resultset.h>
|
|
|
|
#include <cppconn/statement.h>
|
|
|
|
#include <cppconn/prepared_statement.h>
|
|
|
|
#include <cppconn/sqlstring.h>
|
|
|
|
|
|
|
|
class MySqlException : public std::runtime_error {
|
|
|
|
public:
|
|
|
|
MySqlException() : std::runtime_error("MySQL error!") {}
|
|
|
|
MySqlException(const std::string& msg) : std::runtime_error(msg.c_str()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
private:
|
|
|
|
static sql::Driver *driver;
|
|
|
|
static sql::Connection *con;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void Connect(const std::string& host, const std::string& database, const std::string& username, const std::string& password);
|
2022-04-09 22:35:01 +00:00
|
|
|
static void Destroy(std::string source="");
|
2021-12-05 17:54:36 +00:00
|
|
|
static sql::Statement* CreateStmt();
|
|
|
|
static sql::PreparedStatement* CreatePreppedStmt(const std::string& query);
|
|
|
|
};
|