Skip to content
This repository has been archived by the owner on Apr 14, 2018. It is now read-only.

Commit

Permalink
dbColumnInfo() succeeds (#99)
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
r2evans authored and imanuelcostigan committed Aug 27, 2016
1 parent b47591e commit d5f5a75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,base_agg)
importFrom(dplyr,base_scalar)
importFrom(dplyr,base_win)
importFrom(dplyr,bind_rows)
importFrom(dplyr,build_sql)
importFrom(dplyr,compute)
importFrom(dplyr,copy_to)
Expand Down
23 changes: 13 additions & 10 deletions R/dbi-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -530,21 +530,24 @@ setMethod("fetch", c("SQLServerResult", "numeric"),
})

#' @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")
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)
if (cols < 1L) {
df <- data_frame(field.name = character(),
field.type = character(),
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
})
Expand Down

0 comments on commit d5f5a75

Please sign in to comment.