dbHasCompleted always returns TRUE(dbHasCompleted 始终返回 TRUE)
问题描述
我正在使用 R 对 SQL Server 2008 R2 数据库进行统计分析.我的数据库客户端(又名驱动程序)是 JDBC,因此我使用的是 RJDBC 包.
I'm using R to do a statistical analysis on a SQL Server 2008 R2 database. My database client (aka driver) is JDBC and thereby I'm using RJDBC package.
我的查询非常简单,我确信该查询会返回很多行(大约 200 万行).
My query is pretty simple and I'm sure that query would return a lot of rows (about 2 million rows).
SELECT * FROM [maindb].[dbo].[users]
我的R脚本如下.
library(RJDBC);
javaPackageName <- "com.microsoft.sqlserver.jdbc.SQLServerDriver";
clientJarFile <- "/home/abforce/mystuff/sqljdbc_3.0/enu/sqljdbc4.jar";
driver <- JDBC(javaPackageName, clientJarFile);
conn <- dbConnect(driver, "jdbc:sqlserver://192.168.56.101", "username", "password");
query <- "SELECT * FROM [maindb].[dbo].[users]";
result <- dbSendQuery(conn, query);
dbHasCompleted(result)
在上面的代码中,最后一行总是返回 TRUE
.这里有什么问题?
In the codes above, the last line always returns TRUE
. What could be wrong here?
推荐答案
函数 dbHasCompleted
总是返回 TRUE
的事实似乎是我发现的一个已知问题互联网上人们正在努力解决此问题的其他地方.
The fact of function dbHasCompleted
always returning TRUE
seems to be a known issue as I've found other places in the Internet where people were struggling with this issue.
所以,我想出了一个解决方法.代替函数dbHasCompleted
,我们可以使用条件语句nrow(result) == 0
.
So, I came with a workaround. Instead of function dbHasCompleted
, we can use conditional statement nrow(result) == 0
.
例如:
result <- dbSendQuery(conn, query);
repeat {
chunk <- dbFetch(result, n = 10);
if(nrow(chunk) == 0){
break;
}
# Do something with 'chunk';
}
dbClearResult(result);
这篇关于dbHasCompleted 始终返回 TRUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:dbHasCompleted 始终返回 TRUE


基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01