-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert NASIS-related queries from RODBC->DBI #146
- Loading branch information
Showing
26 changed files
with
699 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Send queries to a NASIS DBIConnection | ||
#' | ||
#' @param conn A \code{DBIConnection} object, as returned by \code{DBI::dbConnect()}. | ||
#' @param q A statement to execute using \code{DBI::dbGetQuery} | ||
#' @param close Close connection after query? Default: \code{TRUE} | ||
#' @param ... Additional arguments to \code{DBI::dbGetQuery} | ||
#' | ||
#' @return Result of \code{DBI::dbGetQuery} | ||
#' @export | ||
#' | ||
#' @importFrom DBI dbGetQuery, dbDisconnect | ||
dbQueryNASIS <- function(conn, q, close = TRUE, ...) { | ||
|
||
if (inherits(conn, 'try-error')) | ||
stop("Failed to connect to NASIS database!") | ||
|
||
## exec query | ||
d <- DBI::dbGetQuery(conn, q, ...) | ||
# res <- DBI::dbSendQuery(conn, q) | ||
# d <- DBI::dbFetch(res) | ||
# d <- RODBC::sqlQuery(channel, q, stringsAsFactors=FALSE) | ||
|
||
dd <- data.frame(d) | ||
## close connection | ||
if (close == TRUE) | ||
DBI::dbDisconnect(conn) | ||
# RODBC::odbcClose(channel) | ||
|
||
return(dd) | ||
} | ||
|
||
#' Create a connection to a local NASIS database | ||
#' | ||
#' @return A \code{DBIConnection} object, as returned by \code{DBI::dbConnect()}. | ||
#' | ||
#' @export | ||
#' | ||
dbConnectNASIS <- function() { | ||
# TODO: NASIS sqlite snapshot connection via DBI/RSQLite | ||
|
||
# default connection uses DBI/odbc (historically RODBC) | ||
res <- .openNASISchannel() | ||
|
||
return(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.