Add protect if connection is not valid
This commit is contained in:
		
							parent
							
								
									4c4fdcc938
								
							
						
					
					
						commit
						81f67c1420
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,2 +1,3 @@
 | 
			
		||||
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;
 | 
			
		||||
            }     
 | 
			
		||||
         }
 | 
			
		||||
         usleep(1000); // za smanjenje zauzeća procesora
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return;
 | 
			
		||||
@ -297,11 +298,15 @@ void mySQL::getColumns(const string _table, vector<string> &_columns, Connection
 | 
			
		||||
Connection* mySQL::shift_con() {
 | 
			
		||||
   while (true) {
 | 
			
		||||
      io.lock();
 | 
			
		||||
      for (uint i=0; i<con.size(); i++) {
 | 
			
		||||
      for (int i=0; i<con.size(); i++) {
 | 
			
		||||
         Connection* con_ptr = con[0];
 | 
			
		||||
         con.pop_front();
 | 
			
		||||
         io.unlock();
 | 
			
		||||
         return con_ptr;
 | 
			
		||||
         if (con_ptr->isValid()) {
 | 
			
		||||
            io.unlock();
 | 
			
		||||
            return con_ptr;
 | 
			
		||||
         } else {
 | 
			
		||||
            --i;
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      io.unlock();
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,11 @@ using namespace chrono;
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    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();
 | 
			
		||||
@ -97,28 +99,28 @@ int main() {
 | 
			
		||||
        // t6.join();
 | 
			
		||||
 | 
			
		||||
//        one by one
 | 
			
		||||
        try {
 | 
			
		||||
            sqlQA test_qa;
 | 
			
		||||
            test_qa.select().from("records").where("enabled = 1");
 | 
			
		||||
            mydb.exec(test_qa);
 | 
			
		||||
            test_qa.print(true);
 | 
			
		||||
        } catch (const string err) {
 | 
			
		||||
            cout << err << endl;
 | 
			
		||||
        }
 | 
			
		||||
        // try {
 | 
			
		||||
        //     sqlQA test_qa;
 | 
			
		||||
        //     test_qa.select().from("records").where("enabled = 1");
 | 
			
		||||
        //     mydb.exec(test_qa);
 | 
			
		||||
        //     test_qa.print(true);
 | 
			
		||||
        // } catch (const string err) {
 | 
			
		||||
        //     cout << err << endl;
 | 
			
		||||
        // }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
        try {
 | 
			
		||||
            sqlQA test_qa;
 | 
			
		||||
            test_qa.select().from("users");
 | 
			
		||||
            mydb.exec(test_qa);
 | 
			
		||||
            test_qa.print(true);
 | 
			
		||||
        } catch (const string err) {
 | 
			
		||||
            cout << err << endl;
 | 
			
		||||
        }
 | 
			
		||||
        // try {
 | 
			
		||||
        //     sqlQA test_qa;
 | 
			
		||||
        //     test_qa.select().from("users");
 | 
			
		||||
        //     mydb.exec(test_qa);
 | 
			
		||||
        //     test_qa.print(true);
 | 
			
		||||
        // } catch (const string err) {
 | 
			
		||||
        //     cout << err << endl;
 | 
			
		||||
        // }
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            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);
 | 
			
		||||
            test_qa.print(true);
 | 
			
		||||
        } catch (const string err) {
 | 
			
		||||
@ -130,7 +132,7 @@ int main() {
 | 
			
		||||
        auto duration = duration_cast<microseconds>(end - start);
 | 
			
		||||
        cout << "-------------Izvršilo se za: " << (double)(duration.count() / 1000.0) << " ms"<< endl;
 | 
			
		||||
        
 | 
			
		||||
        sleep(100);
 | 
			
		||||
        // sleep(100);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
    } catch (const SQLException error) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.o
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user