I'm wanting to start a database connection at the start of an app and keep it open for all methods and classes that I'm #including in my project.
First I went about it by creating the connection in the Main source file outside of any class declarations and then declaring it external in other source files.
Expand|Select|Wrap|Line Numbers
- // Main cpp file
- #include <mysql++>
- mysql::Connection * conn;
- // Class definitions follow, I open the connection in Main()
- if (!(conn.connect("dbName", "localhost", "user", "pwd"))) {
- ...
Second method I tried was to pass the mysql::Connection * conn as a parameter: // Call MyFn from a method in Main source file:
MyFn(this, &conn);
connection appears alive but but the app crashes when I execute the query:
Expand|Select|Wrap|Line Numbers
- // Function def in Another source file
- void myFn(wxFrame *frame, Connection *conn)
- {
- mysqlpp::Query query = conn.query(); <--- THIS is probably the cause !?
- // set up query code...
- // execute
- mysqlpp::StoreQueryResult res = query.store(); // <--- Exception happens here