Calling server stored procedure using binding

a 夏天 提交于 2019-12-12 02:14:45

问题


I am trying to call a MySQL server stored procedure using Qt. The procedure returns multiple rows of data I want to retrieve.

The first snippet I tried works fine:

QSqlQuery query("CALL GetOrderItems(323)", dataBase);
qDebug() << query.first();

It also returns the desired data and query.first() is true like expected.

Then I tried to insert the parameter using parameter binding like the Qt documentation proposes. I tried the following snippets. The first uses index placeholder the second keyword placeholder.

QSqlQuery query(dataBase);
qDebug() << query.prepare("CALL GetOrderItems(?)");
query.bindValue(0, 323);
qDebug() << query.exec();
qDebug() << query.first();

QSqlQuery query(dataBase);
qDebug() << query.prepare("CALL GetOrderItems(:myparam)");
query.bindValue(":myparam", 323);
qDebug() << query.exec();
qDebug() << query.first();

Both of these queries execute fine. But query.first() returns false so I don't know how the get the results.

Can I get the result from the binding queries in some way? Why doesn't this work?


回答1:


There are two sentences that can be found in the Qt documentation:

"MySQL 5 introduces stored procedure support at the SQL level, but no API to control IN, OUT and INOUT parameters." (from here, Thanks Mat)

"Stored procedures that uses the return statement to return values, or return multiple result sets, are not fully supported." (from here)

So obviously binding parameters in Qt/MySQL is pretty useless. See also this about batch mode.



来源:https://stackoverflow.com/questions/26448906/calling-server-stored-procedure-using-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!