i'm building qt application make queries on mysql database. when query.exec("call selectusersphotos()")
response fine if set query string on prepare
show on code below database doesn't return values , doesn't throw erros.
if (db.open()) { cout << "querying getuserphotos user " << user->name << endl; qsqlquery query; query.prepare("call selectusersphotos()"); query.exec(); while (query.next()) { userphoto *userphoto = new userphoto(); userphoto->userphotoid = query.value(0).toint(); userphoto->userid = query.value(1).toint(); userphoto->created = query.value(2).todatetime(); userphoto->name = query.value(3).tostring().tostdstring(); usersphotos->push_back(userphoto); } query.finish(); db.close(); cout << "photos " << usersphotos->size() << endl; }
resources: http://qt.developpez.com/doc/4.6/qsqlquery/
"prepares sql query query execution. returns true if query prepared successfully; otherwise returns false."
maybe should try
bool b = query.prepare("call selectusersphotos()"); while(!b) b = query.prepare("call selectusersphotos()"); query.exec();
edit: function signature
bool qsqlquery::prepare ( const qstring & query )
so needs address of value u passing rvalue parameter. maybe u should try
qstring qstr("call selectusersphotos()"); query.prepare(qstr); query.exec(qstr);
note don't know why exec(const qstring & query) works if has same reference parameter.
Comments
Post a Comment