dbHasCompleted 始终返回 TRUE

dbHasCompleted always returns TRUE(dbHasCompleted 始终返回 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)