0

I am using MySql C++ Connector latest build in a c++ app But every query i make to any table it returns true

E.x. code :

string MyQueryTest(){
 string returnValue;
 try{
   stmt->execute("UPDATE testtbl SET Name = 'Test' WHERE id = '2'");
 }
 catch(SQLException e){
   returnValue = "false";
 }

 returnValue = "true";

 return returnValue;
}

string MyValue =  MyQueryTest();

The above code return true though in my testtbl there is no id = 2 data, i have only one data entered which is id = 1 Name = MyTests

Does anyone knows any solutions around this ?

I have tried to place the returnValue = "true" inside the try statement, also i used exit(1) function inside catch error function None got me the desired returnValue to false which is the correct return of the above code

1 Answer 1

1

It's not an exceptional case when there is no data to be updated. SQLException will be thrown if you have problems with connection to Database or SQL query syntax is incorrect.

Statement class has executeUpdate() method that returns number of affected rows, you can use it to achieve your aim.

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

5 Comments

thats what it seems to me also, so how can i get this kind of "false" value which actually is not updating anything ?
I've updated my answer about executeUpdate() method.
Yes i did it right now and it returns me again always true, for a moment i though it could be something like it but in action it didint :/ there must be a response to such queries
Try executeUpdate() as I suggested in answer, it returns number of affected rows.
Yeap you are correct indeed didn`t notice your edited code until now :)

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.