A library for MySQL that implements a simpler framework for MySQL Connector++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mySQL/lib/mysql.hpp

92 lines
2.3 KiB

1 year ago
#ifndef _MYSQL_
#define _MYSQL_
#include <string>
#include <sstream>
1 year ago
#include <vector>
#include <map>
#include <iostream>
1 year ago
#include <mutex>
#include <thread>
1 year ago
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/resultset.h>
#define unlimited 0
#define reconnectSleep 100000 // in us
1 year ago
using namespace std;
using namespace sql;
using namespace mysql;
class sqlQA {
public:
// query
string cmd;
string table;
vector<string> columns;
bool isUpdate = false;
bool isSelect = false;
// answer
uint updateCatch = 0;
bool executed = false;
map<string, vector<string>> result;
uint num_rows = 0;
uint num_columns = 0;
// query methods
sqlQA& select(const string _select = "*");
sqlQA& from(const string _tablename);
sqlQA& where(const string _condition);
sqlQA& limit(const uint _limit);
sqlQA& insertInTo(const string _tablename, const string _columns = "");
sqlQA& values(const string _values);
sqlQA& update(const string _tablename);
sqlQA& set(const string _column_value_pairs);
sqlQA& deleteFrom(const string _table);
void print(bool withDetail = false);
// answer methods
private:
void parse_columns(const string _cloumns);
};
1 year ago
class mySQL {
public:
1 year ago
mutex io;
1 year ago
MySQL_Driver *drv;
// Connection *con;
// vector<Connection*> con;
vector<pair<mutex*, Connection*>> con;
1 year ago
string path, username, password, db;
bool isPersistent;
uint numOfCon;
uint reconTrys = 3;
1 year ago
mySQL(const string _path, const string _username, const string _password, const string _db, const bool _isPersistent = false, const uint _numOfCon = 1);
bool open(const string _db = "");
bool connect();
bool disconnect();
void reconnectTrys(const uint _trys);
void exec(sqlQA &sql_qa);
void getColumns(const string _table, vector<string> &_columns, Connection *ptr_con); // privatno
// ove će biti privatne sigurno
bool open_one(Connection *ptr_con);
bool connect_one(Connection *ptr_con);
bool disconnect_one(Connection *ptr_con);
pair<mutex*, Connection*> findFreeCon();
~mySQL();
};
1 year ago
#endif