QSqlQuery 调用 MySQL 的存储过程时,无法获取数据集?

Jonix 2013-05-19 12:06:05
QSqlQuery 调用 MySQL 的存储过程时,无法获取数据集?
存储过程中是一个SELECT * FROM table; 的语句,是为了返回一个数据集。

但 QSqlQuery 在 exec() 成功后,isSelect() 返回为 false,同时 sqlRecord() & sqlResult() 中也没有包含任何数据集的信息。

同样的代码连接到 MS SQLServer2008 时,完全正常的使用。

当我把SQL都放在存储过程中,请教这个问题如何解决?
...全文
226 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jonix 2013-05-20
  • 打赏
  • 举报
回复
引用 1 楼 feilinhe 的回复:
助手里有这么一句话:

QMYSQL Stored Procedure Support

MySQL 5 introduces stored procedure support at the SQL level, but no API to control IN, OUT and INOUT parameters. Therefore, parameters have to be set and read using SQL commands instead of QSqlQuery::bindValue().

Example stored procedure:

create procedure qtestproc (OUT param1 INT, OUT param2 INT)
BEGIN
    set param1 = 42;
    set param2 = 43;
END
Source code to access the OUT values:

QSqlQuery q;
q.exec("call qtestproc (@outval1, @outval2)");
q.exec("select @outval1, @outval2");
q.next();
qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
Note: @outval1 and @outval2 are variables local to the current connection and will not be affected by queries sent from another host or connection.
非常感谢,但我现在迫切需要的是返回数据集。即select * from ... 的结果。
feilinhe 2013-05-19
  • 打赏
  • 举报
回复
调用方式的问题,SQL Server和MySQL不太一致,具体的也没仔细研究过~
feilinhe 2013-05-19
  • 打赏
  • 举报
回复
助手里有这么一句话:

QMYSQL Stored Procedure Support

MySQL 5 introduces stored procedure support at the SQL level, but no API to control IN, OUT and INOUT parameters. Therefore, parameters have to be set and read using SQL commands instead of QSqlQuery::bindValue().

Example stored procedure:

create procedure qtestproc (OUT param1 INT, OUT param2 INT)
BEGIN
    set param1 = 42;
    set param2 = 43;
END
Source code to access the OUT values:

QSqlQuery q;
q.exec("call qtestproc (@outval1, @outval2)");
q.exec("select @outval1, @outval2");
q.next();
qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
Note: @outval1 and @outval2 are variables local to the current connection and will not be affected by queries sent from another host or connection.

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧