c++ - Using MySQL++ throws EXC_BAD_ACCESS -


i'm attempting connect mysql database following code. throws exc_bad_access gets "query query = conn.query()" line. reason? in advance!

#include <iostream> #include <mysql++/mysql++.h>  using namespace mysqlpp;  int main(int argc, const char * argv[]) {      try {         connection conn(false);         if (conn.connect("db", "localhost", "root", "root")) {             query query = conn.query("select * django_site");         }     }     catch (badquery er) {         std::cerr << "error: " << er.what();         return -1;     } catch (const badconversion& er) {         // handle bad conversions         std::cerr << "conversion error: " << er.what() << std::endl <<         "\tretrieved data size: " << er.retrieved <<         ", actual size: " << er.actual_size << std::endl;         return -1;     } catch (const exception& er) {         // catch-all other mysql++ exceptions         std::cerr << "error: " << er.what() << std::endl;         return -1;     }      return 0; } 

printing conn object returns

(mysqlpp::connection) conn = {   mysqlpp::optionalexceptions = {     exceptions_ = false   }   error_message_ = "\xe5$}\xff\x7f"   driver_ = 0x00007fff5fc005a8   co 

what's more troubling "conn_" variable pointing null

(mysqlpp::query) query = {   std::__1::ostream = {     std::__1::basic_ios<char, std::__1::char_traits<char> > = {       std::__1::ios_base = {         __fmtflags_ = 0         __precision_ = 0         __width_ = 0         __rdstate_ = 0         __exceptions_ = 0         __rdbuf_ = 0x0000000000000000         __loc_ = 0x0000000000000000         __fn_ = 0x0000000000000000         __index_ = 0x0000000000000000         __event_size_ = 0         __event_cap_ = 0         __iarray_ = 0x0000000000000000         __iarray_size_ = 0         __iarray_cap_ = 0         __parray_ = 0x0000000000000000         __parray_size_ = 0         __parray_cap_ = 0       }       __tie_ = 0x0000000000000000       __fill_ = 0     }   }   mysqlpp::optionalexceptions = {     exceptions_ = false   }   template_defaults = {     std::__1::vector<mysqlpp::sqltypeadapter, std::__1::allocator<mysqlpp::sqltypeadapter> > = size=0 {}     parent_ = 0x0000000000000000     processing_ = false   }   conn_ = 0x0000000000000000   copacetic_ = false   parse_elems_ = size=0 {}   parsed_names_ = size=0 {}   parsed_nums_ = size=0 {}   sbuffer_ = {     std::__1::basic_streambuf<char, std::__1::char_traits<char> > = {       __loc_ = {         __locale_ = 0x0000000000000000       }       __binp_ = 0x0000000000000000       __ninp_ = 0x0000000000000000       __einp_ = 0x0000000000000000       __bout_ = 0x0000000000000000       __nout_ = 0x0000000000000000       __eout_ = 0x0000000000000000     }     __str_ = ""     __hm_ = 0x0000000000000000     __mode_ = 0   } } 

you not checking return type of call connect() before create query. calling

query query = conn.query(); 

if connect() fails cause of exception.

according manual pages http://tangentsoft.net/mysql++/doc/html/refman/classmysqlpp_1_1query.html passing null char* connection::query() function valid default argument assume database connection request has failed. check return type of

conn.connect("db", "localhost", "root", "root"); 

and double check database name, user name , password strings passing function.

also, check application has required permissions connecting database root.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -