#include #include #include //This tests the reference-counting of shared connections, queries, and results. //The sharing happens when copy constructors are used. //The actual underlying resources should not be released until the last client C++ instance has died. int main() { try { mysqlcppapi::Connection connection; connection.set_Host("localhost"); connection.set_User("testuser"); connection.set_Password("testpassword"); for(int i = 0; i < 3; ++i) { std::cout << "iteration: " << i << std::endl; connection.connect(); mysqlcppapi::Connection connection_copy = connection; //Test sharing of underlying connection; connection.select_database("test"); { mysqlcppapi::Query query = connection.create_Query(); query << "select * from staff"; mysqlcppapi::Result_Store res = query.store(); } { //We actually use connection_copy to make sure that the compiler doesn't optimise it away. mysqlcppapi::Query query = connection_copy.create_Query(); mysqlcppapi::Query query2 = query; //Test sharing of underlying query; query << "select * from departments"; mysqlcppapi::Result_Store res = query.store(); mysqlcppapi::Result_Store res2 = res; //Test sharing of underlying result; } connection.close(); } } catch(mysqlcppapi::ex_base& er) { // handle any connection or query errors that may come up std::cerr << "Exception: " << er.what() << std::endl; return -1; } return 0; }