#include #include #include using namespace std; using namespace chrono; #include "../../asynco/lib/asynco.hpp" #include "../../asynco/lib/timers.hpp" using namespace marcelb::asynco; #include "../lib/mysql.hpp" using namespace marcelb::mysql; int main() { auto inis = rtime_ms(); try { const int n = 10; // MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5, time_loop_type::internal); MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", n); // MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5); cout << "--------------init: " << rtime_ms() - inis << endl; mydb.on_error = [](const string& error) { cout << error << endl; }; mydb.on_connect = []() { cout << "Init all pool connection done" << endl; }; // periodic mysql_tloop ( [&mydb] () { // auto l_start = rtime_ms(); // vector> to_wait; // for (int i=0, old_i=0; i("SELECT id,domain FROM records WHERE enabled = 1;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); auto a2 = async_ ( [&mydb] () { try { auto response = mydb.exec("SELECT zonename,auth_key FROM zones;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); auto a3 = async_ ( [&mydb] () { try { auto response = mydb.exec("SELECT username,email FROM users WHERE enabled = 1;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); auto a4 = async_ ( [&mydb] () { try { auto response = mydb.exec("SELECT id,domain FROM records WHERE enabled = 1;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); auto a5 = async_ ( [&mydb] () { try { auto response = mydb.exec("SELECT zonename,auth_key FROM zones;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); auto a6 = async_ ( [&mydb] () { try { auto response = mydb.exec("SELECT username,email FROM users WHERE enabled = 1;"); cout << response.affected << " " << response.have_result << endl; cout << response.rows << " " << response.columns << endl; for (auto row : response) { cout << get<0>(row) << " " << get<1>(row) << endl; } for (auto column_name : response.columns_name) { cout << column_name << endl; } } catch (const SQLException error) { cout << error.what() << endl; } }); await_(a1); await_(a2); await_(a3); await_(a4); await_(a5); await_(a6); auto end = high_resolution_clock::now(); auto duration = duration_cast(end - start); cout << "-------------Izvršilo se za: " << (double)(duration.count() / 1000.0) << " ms"<< endl; } sleep(100); } catch (const SQLException error) { cout << error.what() << endl; } catch (const exception& error) { cout << error.what() << endl; } catch (const string& error) { cout << error << endl; } catch (...) { cout << "Jebi ga" << endl; } // sleep(600); _asynco_engine.run(); return 0; }