QSqlQuery如何获取计数的值? [英] QSqlQuery how to get value of a count?

查看:223
本文介绍了QSqlQuery如何获取计数的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有一个查询,只是获取基于一些标准的表计数。QSqlQuery查询COUNT(*)FROM some_table WHERE some_value =:something); 
query.bindValue(:something,something);

我的问题是我如何得到这个回来的结果,显然这是你将使用



  query.value(int); 
query.value(QString);

但是文档说int index不应该使用,因为我们不知道索引是什么不能使用字符串一,因为没有归档定义为一个我想要的结果。所以假设我是正确的说,我可以从这个查询中获得计数整数值到一个int变量



cheers

解决方案

为字段计数添加别名。像这样:

  QSqlQuery查询(SELECT COUNT(*)CNT FROM some_table WHERE some_value =:something 

然后按名称 CNT p>

I have a query that is just getting the count of table based on some criteria eg:

QSqlQuery query("SELECT COUNT(*) FROM some_table WHERE some_value = :something");
query.bindValue(":something", "something");

my question is how do i get result of this back, obviously this is where you would use

query.value(int);
query.value(QString);

But the docs say that int index one shouldnt be used because we dont know what the index would be andi cant use the string one because there is no filed to define as the one i want the result for. so assuming i am correct in saying that how is it that i can get the count integer value into a int variable from this query

cheers

解决方案

Make an alias to field count. Like this:

QSqlQuery query("SELECT COUNT(*) CNT FROM some_table WHERE some_value = :something");

and then query by name CNT

这篇关于QSqlQuery如何获取计数的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆