MySQL Forums
Forum List  »  Connector/C++

MySQL++ Transaction not working
Posted by: James Somers
Date: May 04, 2008 04:15AM

Hi there,
I have installed the latest version of MySQL++ and have used it for several other sections in my program and they all work. I am trying to write a transaction though which has a MySQL statement generated by the C++ code. Yeha I could use stored procedures I suppose, but I would prefer to do it in the C++ code. Here is my code:

Query MarkUpdateQuery = mysql->GetConnection()->query();
Transaction Trans(*mysql->GetConnection());
for(testiter = TestSpecs.begin(); testiter != TestSpecs.end(); testiter++)
{
MarkUpdateQuery << "UPDATE Test SET score = (score * 100 / " << quote << testiter->maxscore << ") WHERE casa_nr = " << quote << testiter->casa_nr << "; ";
MarkUpdateQuery << "UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = " << quote << testiter->casa_nr << ";";
}
MarkUpdateQuery.exec();
Trans.commit();

It generates the string correctly, I have put it directly in to MySQL and it executes without a problem. When the program goes to execute it however, it does not work. It throws a Bad Query exception and it says:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = 1001;UPDATE Test SET score ' at line 1

The entire query it generates is:

UPDATE Test SET score = (score * 100 / 200) WHERE casa_nr = 1001; UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = 1001;UPDATE Test SET score = (score * 100 / 100) WHERE casa_nr = 1002; UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = 1002;UPDATE Test SET score = (score * 100 / 100) WHERE casa_nr = 1003; UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = 1003;UPDATE Test SET score = (score * 100 / 100) WHERE casa_nr = 1004; UPDATE TestSpec SET maxscore = 100 WHERE casa_nr = 1004;

Which is valid MySQL I believe :( Any suggestions? I'm really stuck!

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL++ Transaction not working
4302
May 04, 2008 04:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.