August 2, 2011

reactive reactive
Lab Rat
61 posts

[SOLVED] Getting the OUT of a MySQL stored procedure?

 

Hi, I’m trying to get the value of a OUT variable from a stored procedure with no luck.
I’m using the code from the docs: http://doc.qt.nokia.com/4.7/qsqlquery.html#approaches-to-binding-values

I’m new to SPs so this is my test one:

PROCEDURE `abc`(IN x INT, OUT y INT)
BEGIN SET y = 11;
END

The code is:

  1. QSqlQuery query (myDB);
  2. query.prepare("CALL abc(?, ?)");
  3. query.bindValue(0, "7");
  4. query.bindValue(1, 0, QSql::Out);
  5. query.exec();
  6. int i = query.boundValue(1).toInt(); // i is 65

I get this error: OUT or INOUT argument 2 for routine blah.abc is not a variable or NEW pseudo-variable in BEFORE trigger QMYSQL3

Thanks for any advice!

4 replies

August 3, 2011

alexisdm alexisdm
Lab Rat
141 posts

You should use the code from:
http://doc.qt.nokia.com/latest/sql-driver.html#qmysql

August 3, 2011

reactive reactive
Lab Rat
61 posts

Thanks, Alexis. That’s exactly what I was looking for.

August 3, 2011

mlong mlong
Robot Herder
1551 posts

Be sure and change the thread title to add a [Solved]. Thanks!

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

August 3, 2011

reactive reactive
Lab Rat
61 posts

No problem! I looked for the “solved” button like at the Java forums. I didn’t realize I had to edit the title manually.

 
  ‹‹ [Solved]Qt and FreeBSD      Qt::key of / ››

You must log in to post a reply. Not a member yet? Register here!