Reputation: 45
I'm using VisualStudio 12 for develop one app. In that app i need do some mySql call's, i have that code:
sql::Statement *stmt = db->global->createStatement();
sql::ResultSet *res = stmt->executeQuery("SELECT * FROM `tbl_jobs` WHERE name = 'maintenance';");
Server->maintenance = (res->getString("data") == "on")? true : false;
The query is ok, work's well on Navicat, but on:
res->getString("data")
Ever throw's that error:
Unhandled exception at ...: Microsoft C++ exception: sql::InvalidArgumentException at memory location ....
If i done sql::SQlException throw i get this log:
ERROR: SQLException in .... Function: main on line 33 ERROR: MySQL_ResultSet::getString: can't fetch because not on result set (MySql error code: 1544116026, SqlState: MySQL_ResultSet::getString: can't fetch because not on result set)
I understan the sql::ResultSet don't have any data, but if i print res->rowsCount() say me are 1 row... I tryed with res->first(), but throws random error's.
¿Any ideas? :c
Upvotes: 1
Views: 4183
Reputation: 1651
You must call next() or similar in order for your resultset to point to the nth result in the set
If your resultset is empty calling getString() will fail. check for a result before continuing. something like:
if(!res->next())
return; //Handle Failiure
Do this before you try to operate on your results
Here they are using a while loop alternatively.
Upvotes: 2