这个bug在SO上没搜到
sql语句是:
select sum(total) as total_sum, total, project_name from service_performance_day where enterprise_id = :eid and year = :year and month = :month and day = :day order by total desc
关键是使用了sqlite内置的sum函数,然后即使表中没有记录,ResultSet的next方法也返回YES
while([rs next]){
double sum = [[rs objectForColumnName:@"total_sum"] doubleValue];
double total = [[rs objectForColumnName:@"total"] doubleValue];
NSString *name = [rs objectForColumnName:@"project_name"];
ServicePerformance *performance = [[ServicePerformance alloc] initWithTitle:name Value:total Ratio:total / sum];
[performances addObject:performance];
}
正常情况下,如果没有使用sum函数,不会走到while循环体中。但是使用了sum函数(其他内置函数没有测过),ResultSet的next函数就有BUG了
解决的办法是,先count一下符合条件的记录数
int count = [db intForQuery:@"select count(1) from service_performance_day where enterprise_id = :eid and year = :year and month = :month and day = :day;", enterpriseId, [NSNumber numberWithLong:year], [NSNumber numberWithLong:month], [NSNumber numberWithLong:day]];
if(count == 0){
[db close];
return [NSMutableArray array];
}
分享到:
相关推荐
本文档包含了h2数据库的聚合函数的中文说明和举例
ResultSet的用法
Oracle9i 增加了此映射,允许从函数返回 ResultSet 或将其作为 OUT 参数传到某个过程。但它仍不支持逆向映射 (REF CURSOR->ResultSet),因此当前版本的数据库仍然不支持 IN 和 IN OUT 参数。 在本方法指南中,我们...
这是一个用来教你如何使用ResultSet 获取数据对象的文档,非常使用
ResultSet 转为listmap
java数据库连接ResultSet
ResultSet直接在JTable显示
JAVA 版本ResultSet 转换为JAVABEAN的工具类
获得结果集的字段名称,ResultSet的属性要调用ResultSetMetaData的方法
jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程jsp 三种查询分页 resultset,hibernate ,存储过程
JDBC通信原理 JDBC驱动类型 JDBC构成 JDBC程序5步走 滚动的结果集 可更新的结果集 SQL数据类型对应的Java类型 事务及批量处理 行集、连接池、LDAP
poi根据ResultSet到处Excle源码,包含项目所需jar包,可以直接运行
resultset 变成 XML 格式输出
ResultSet转化为json,json转化为List,轻松搞定
ResultSet转List
javaResultSet常用方法.pdf
次类对ResultSet进行封装,可以将其转化为List,Map,BO等
在java开发中常需要将ResultSet结果集转化为json格式以实现与客服端实现数据交互,但是这需要几个包,而且版本也要对应,因此我收集了全部的包,并测试可以运行,放在这里供大家下载。包括:commons-beanutils-1.7.0...
ResultSet常用方法,指针滚动,讲解很详细哦!
p6spy.jar 可配置是否需要resultset, excludecategories=info,debug,result,batch,resultset