diff --git a/.vscode/settings.json b/.vscode/settings.json index e375c2a..ec41298 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,8 @@ "string": "cpp", "vector": "cpp", "deque": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "iostream": "cpp", + "ratio": "cpp" } } \ No newline at end of file diff --git a/lib/mysql.hpp b/lib/mysql.hpp index 584ed64..5b1f655 100644 --- a/lib/mysql.hpp +++ b/lib/mysql.hpp @@ -73,4 +73,15 @@ class mySQL { }; +class mySQLPool { + public: + uint numOfCon = 1; + vector drops; + vector dropsdown; // true is used + + mySQLPool(const uint _numOfCon, const string _path, const string _username, const string _password, const string _db); + void exec(sqlQA &sql_qa); +}; + + #endif \ No newline at end of file diff --git a/src/mysql.cpp b/src/mysql.cpp index 04d4e19..5d585f0 100644 --- a/src/mysql.cpp +++ b/src/mysql.cpp @@ -117,6 +117,8 @@ bool mySQL::connect() { uint trys = 0; bool status = true; + cout << "-----------Jebiga connect " << endl; + while (trys < CONNECT_TRY_LIMIT && status) { try { drv = get_mysql_driver_instance(); @@ -161,6 +163,7 @@ bool mySQL::disconnect() { void mySQL::exec(sqlQA &sql_qa) { if (!isPersistent || !con->isValid() || con->isClosed()) { + cout << "--------Đubre nije spojeno!!" << con->isValid() << con->isClosed() << endl; if (connect()) { throw string("[ERROR] Unable to connect database "); } @@ -223,6 +226,7 @@ void mySQL::exec(sqlQA &sql_qa) { /**/ if (!isPersistent) { + cout << "---------Gasi!" << endl; if(disconnect()) { throw string("[ERROR] Unable to close database "); } @@ -249,3 +253,35 @@ mySQL::~mySQL() { throw string("[ERROR] Unable to close database "); } } + + +mySQLPool::mySQLPool(const uint _numOfCon, const string _path, const string _username, const string _password, const string _db) { + if (_numOfCon > 0) { + numOfCon = _numOfCon; + } else { + throw string("[ERROR] The number of MySQL connections must be greater than zero "); + } + + drops.resize(numOfCon); + dropsdown.resize(numOfCon); + + for (uint i=0; iexec(sql_qa); + dropsdown[i] = false; + break; + } + } +} \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index 283e24b..66b263d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,4 +1,5 @@ #include +#include #include "../lib/mysql.hpp" @@ -6,14 +7,23 @@ using namespace std; int main() { - mySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", true); + // mySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", true); try { - sqlQA test_qa; - // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled - // test_qa.select().from("records").where("enabled = 0").limit(2); - // mydb.exec(test_qa); + mySQLPool bazenbaze(5, "tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio"); + + // sqlQA test_qa; + // // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled + // test_qa.select().from("users"); + // // mydb.exec(test_qa); + // bazenbaze.exec(test_qa); + + // sqlQA test_qa2; + // // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled + // test_qa2.select().from("records").where("enabled = 1"); + // // mydb.exec(test_qa2); + // bazenbaze.exec(test_qa2); // for (auto i : test_qa.result) { // for (auto j: i.second) { @@ -21,6 +31,68 @@ int main() { // } // } + // for (auto i : test_qa2.result) { + // for (auto j: i.second) { + // cout << i.first << " : " << j << endl; + // } + // } + + // sleep(600); + + + thread t1([&](){ + sqlQA test_qa; + // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled + test_qa.select().from("users"); + // mydb.exec(test_qa); + bazenbaze.exec(test_qa); + + for (auto i : test_qa.result) { + for (auto j: i.second) { + cout << i.first << " : " << j << endl; + } + } + }); + + + thread t2([&](){ + sqlQA test_qa2; + // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled + test_qa2.select().from("records").where("enabled = 1"); + // mydb.exec(test_qa2); + bazenbaze.exec(test_qa2); + + for (auto i : test_qa2.result) { + for (auto j: i.second) { + cout << i.first << " : " << j << endl; + } + } + + }); + + + thread t3([&](){ + sqlQA test_qa3; + // id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled + test_qa3.select().from("zones").where("enabled = 1"); + // mydb.exec(test_qa3); + bazenbaze.exec(test_qa3); + + for (auto i : test_qa3.result) { + for (auto j: i.second) { + cout << i.first << " : " << j << endl; + } + } + }); + + t1.join(); + t2.join(); + t3.join(); + + + + // sleep(600); + // test_qa.update("records").set("enabled = 1").where("domain = 'bitelex.test'"); // mydb.exec(test_qa); @@ -32,11 +104,11 @@ int main() { // test_qa.insertInTo("records", "id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled").values("'5',2,2,'www.bitelex.test','AAAA','jebiga',NULL,1"); - test_qa.deleteFrom("records").where("record_type = AAAA"); - // test_qa.update("records").set("enabled = 0").where("record_type = 'AAAA'"); - cout << test_qa.cmd << endl; - mydb.exec(test_qa); - cout << "Num rows " << test_qa.num_rows << " num columns " << test_qa.num_columns << " catch " << test_qa.updateCatch << " executed " << test_qa.executed << endl; + // test_qa.deleteFrom("records").where("record_type = AAAA"); + // // test_qa.update("records").set("enabled = 0").where("record_type = 'AAAA'"); + // cout << test_qa.cmd << endl; + // mydb.exec(test_qa); + // cout << "Num rows " << test_qa.num_rows << " num columns " << test_qa.num_columns << " catch " << test_qa.updateCatch << " executed " << test_qa.executed << endl; diff --git a/test/test.o b/test/test.o index f6f4967..6d46176 100755 Binary files a/test/test.o and b/test/test.o differ