This repository has been archived by the owner on Apr 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
dbColumnInfo error #96
Comments
Does the issue persist when using 27ab759 (DBI 0.5 compatibility branch)? |
Yes. The relevant change to above: devtools::session_info()
# ...
# RSQLServer 0.2.099 2016-08-22 Github (imanuelcostigan/RSQLServer@27ab759)
# ... Trace from the session, if it helps: trace("dbColumnInfo", browser, exit = browser, signature = "SQLServerResult")
# [1] "dbColumnInfo"
dbColumnInfo(res)
# Tracing dbColumnInfo(res) on entry
# Called from: eval(expr, envir, enclos)
# Browse[1]>
# debug: {
# cols <- rJava::.jcall(res@md, "I", "getColumnCount")
# df <- data_frame(field.name = character(), field.type = character(),
# data.type = character())
# if (cols < 1)
# return(df)
# for (i in 1:cols) {
# df$field.name[i] <- rJava::.jcall(res@md, "S", "getColumnName",
# i)
# df$field.type[i] <- rJava::.jcall(res@md, "S", "getColumnTypeName",
# i)
# ct <- rJava::.jcall(res@md, "I", "getColumnType", i)
# df$data.type[i] <- jdbcToRType(ct)
# }
# df
# }
# Browse[2]>
n
# debug: cols <- rJava::.jcall(res@md, "I", "getColumnCount")
# Browse[2]>
n
# debug: df <- data_frame(field.name = character(), field.type = character(),
# data.type = character())
# Browse[2]>
cols
# [1] 2
# Browse[2]>
n
# debug: if (cols < 1) return(df)
# Browse[2]>
df
# # A tibble: 0 x 3
# # ... with 3 variables: field.name <chr>, field.type <chr>, data.type <chr>
# Browse[2]>
n
# debug: for (i in 1:cols) {
# df$field.name[i] <- rJava::.jcall(res@md, "S", "getColumnName",
# i)
# df$field.type[i] <- rJava::.jcall(res@md, "S", "getColumnTypeName",
# i)
# ct <- rJava::.jcall(res@md, "I", "getColumnType", i)
# df$data.type[i] <- jdbcToRType(ct)
# }
n
# Browse[2]>
# debug: df$field.name[i] <- rJava::.jcall(res@md, "S", "getColumnName",
# i)
# Browse[2]>
# Error in `$<-.data.frame`(`*tmp*`, "field.name", value = "a") :
# replacement has 1 row, data has 0
# Tracing dbColumnInfo(res) on exit
# Browse[3]>
rJava::.jcall(res@md, "S", "getColumnName", i)
# [1] "a"
# Browse[3]>
i
# [1] 1
# Browse[3]> If I don't run the df <- do.call("rbind", lapply(seq_len(cols), function(i) {
list(field.name = rJava::.jcall(res@md, "S", "getColumnName", i),
field.type = rJava::.jcall(res@md, "S", "getColumnTypeName", i),
data.type = jdbcToRType(rJava::.jcall(res@md, "I", "getColumnType", i)))
}))
df
# field.name field.type data.type
# [1,] "a" "int" "integer"
# [2,] "b" "int" "integer" which gives what I think the data.frame is supposed to be. (So the problem is with a |
Suggested patch: --- dbi-methods.R.orig 2016-08-22 16:22:07.659563100 -0700
+++ dbi-methods.R 2016-08-22 16:24:48.669131700 -0700
@@ -485,21 +485,24 @@
#' @rdname SQLServerResult-class
-#' @importFrom dplyr data_frame
+#' @importFrom dplyr bind_rows data_frame
#' @export
setMethod("dbColumnInfo", "SQLServerResult", def = function (res, ...) {
# Inspired by RJDBC method for JDBCResult
# https://github.com/s-u/RJDBC/blob/1b7ccd4677ea49a93d909d476acf34330275b9ad/R/class.R
cols <- rJava::.jcall(res@md, "I", "getColumnCount")
+ if (cols < 1) {
df <- data_frame(field.name = character(),
field.type = character(),
- data.type = character())
- if (cols < 1) return(df)
- for (i in 1:cols) {
- df$field.name[i] <- rJava::.jcall(res@md, "S", "getColumnName", i)
- df$field.type[i] <- rJava::.jcall(res@md, "S", "getColumnTypeName", i)
- ct <- rJava::.jcall(res@md, "I", "getColumnType", i)
- df$data.type[i] <- jdbcToRType(ct)
+ data.type = character()))
+ } else {
+ df <- dplyr::bind_rows(
+ lapply(seq_len(cols), function(i) {
+ list(field.name = rJava::.jcall(res@md, "S", "getColumnName", i),
+ field.type = rJava::.jcall(res@md, "S", "getColumnTypeName", i),
+ data.type = jdbcToRType(rJava::.jcall(res@md, "I", "getColumnType", i)))
+ })
+ )
}
df
}) Is there a vectorized version of "getColumnName" and friends? Seems like this should be able to be resolved in 3 calls to java and not i <- seq_len(cols)
data_frame(field.name = rJava::.jcall(res@md, "S+", "getColumnName", i),
field.type = rJava::.jcall(res@md, "S+", "getColumnTypeName", i),
field.type = jdbcToRType(rJava::.jcall(res@md, "S+", "getColumnType", i))) (The |
r2evans
added a commit
to r2evans/RSQLServer
that referenced
this issue
Aug 26, 2016
Merged
imanuelcostigan
pushed a commit
that referenced
this issue
Aug 27, 2016
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Expected behaviour
From
DBI.pdf
:Actual behaviour
Steps to reproduce behaviour
(as above)
The text was updated successfully, but these errors were encountered: