Add protect if connection is not valid

queue v0.6
marcelb 12 months ago
parent 4c4fdcc938
commit 81f67c1420
  1. 3
      .gitignore
  2. 0
      2.test
  3. 11
      src/mysql.cpp
  4. 42
      test/test.cpp
  5. BIN
      test/test.o

3
.gitignore vendored

@ -1,2 +1,3 @@
example example
test/test.o test/test.o
test/*.test

@ -122,6 +122,7 @@ mySQL::mySQL(const string _path, const string _username, const string _password,
cout << except << endl; cout << except << endl;
} }
} }
usleep(1000); // za smanjenje zauzeća procesora
} }
return; return;
@ -297,11 +298,15 @@ void mySQL::getColumns(const string _table, vector<string> &_columns, Connection
Connection* mySQL::shift_con() { Connection* mySQL::shift_con() {
while (true) { while (true) {
io.lock(); io.lock();
for (uint i=0; i<con.size(); i++) { for (int i=0; i<con.size(); i++) {
Connection* con_ptr = con[0]; Connection* con_ptr = con[0];
con.pop_front(); con.pop_front();
io.unlock(); if (con_ptr->isValid()) {
return con_ptr; io.unlock();
return con_ptr;
} else {
--i;
}
} }
io.unlock(); io.unlock();
} }

@ -9,9 +9,11 @@ using namespace chrono;
int main() { int main() {
try { try {
mySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 1); // mySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 1);
mySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5);
sleep(3); // sleep(3600*10);
sleep(30);
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
@ -97,28 +99,28 @@ int main() {
// t6.join(); // t6.join();
// one by one // one by one
try { // try {
sqlQA test_qa; // sqlQA test_qa;
test_qa.select().from("records").where("enabled = 1"); // test_qa.select().from("records").where("enabled = 1");
mydb.exec(test_qa); // mydb.exec(test_qa);
test_qa.print(true); // test_qa.print(true);
} catch (const string err) { // } catch (const string err) {
cout << err << endl; // cout << err << endl;
} // }
try { // try {
sqlQA test_qa; // sqlQA test_qa;
test_qa.select().from("users"); // test_qa.select().from("users");
mydb.exec(test_qa); // mydb.exec(test_qa);
test_qa.print(true); // test_qa.print(true);
} catch (const string err) { // } catch (const string err) {
cout << err << endl; // cout << err << endl;
} // }
try { try {
sqlQA test_qa; sqlQA test_qa;
test_qa.select().from("users"); test_qa.select("zone_id,record_type,enabled").from("records").where("domain = 'bitelex.test'");
mydb.exec(test_qa); mydb.exec(test_qa);
test_qa.print(true); test_qa.print(true);
} catch (const string err) { } catch (const string err) {
@ -130,7 +132,7 @@ int main() {
auto duration = duration_cast<microseconds>(end - start); auto duration = duration_cast<microseconds>(end - start);
cout << "-------------Izvršilo se za: " << (double)(duration.count() / 1000.0) << " ms"<< endl; cout << "-------------Izvršilo se za: " << (double)(duration.count() / 1000.0) << " ms"<< endl;
sleep(100); // sleep(100);
} catch (const SQLException error) { } catch (const SQLException error) {

Binary file not shown.
Loading…
Cancel
Save