⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reference_counting.cc

📁 有关MYSQL的开源码
💻 CC
字号:
#include <mysqlcppapi/mysqlcppapi.h>#include <iostream>#include <iomanip>//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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -