1

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

3
  • Can you use try/ catch. stackoverflow.com/questions/16004540/… Commented Jun 25, 2013 at 10:19
  • you need to tag this with mysql c++ connector? Commented Jun 25, 2013 at 10:32
  • @ ldgorman Added, @metalfightm i alredy use but return's "ERROR: SQLException...." Commented Jun 25, 2013 at 10:36

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Make another errror on inline void _Container_base12::_Orphan_all(), in xutility, and i can't read any with debugger
1

call res->next() before your first getString(...) function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.