dbHasCompleted始终返回TRUE [英] dbHasCompleted always returns TRUE

查看:125
本文介绍了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的事实似乎是一个已知问题,因为我在Internet上发现了其他人们苦苦挣扎的地方这个问题.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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