Fix devtools check errors and global variables

This commit is contained in:
Jonathan Zhu 2019-06-07 15:37:07 -07:00
Родитель af2e988fab
Коммит adc89c2f53
7 изменённых файлов: 26 добавлений и 17 удалений

Просмотреть файл

@ -1,2 +1,4 @@
^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^dist\*.zip$
^buildandinstall.cmd

Просмотреть файл

@ -6,6 +6,8 @@
# (the owner is used in CREATE EXTERAL LIBRARY AUTHORIZATION) # (the owner is used in CREATE EXTERAL LIBRARY AUTHORIZATION)
MAX_OWNER_SIZE_CONST <- 128 MAX_OWNER_SIZE_CONST <- 128
IS_TOP_PACKAGE_MISSING <- -1L IS_TOP_PACKAGE_MISSING <- -1L
test.env <- new.env()
local("g_scriptFile",env=test.env)
#' sql_installed.packages #' sql_installed.packages
#' #'
@ -35,7 +37,7 @@ sql_installed.packages <- function(connectionString,
subarch = NULL, scope = "private", owner = '', subarch = NULL, scope = "private", owner = '',
scriptFile = NULL) scriptFile = NULL)
{ {
g_scriptFile <<- scriptFile assign("g_scriptFile", scriptFile, envir = test.env)
enumResult <- NULL enumResult <- NULL
checkOwner(owner) checkOwner(owner)
@ -91,7 +93,7 @@ sql_install.packages <- function(connectionString,
verbose = getOption("verbose"), scope = "private", owner = '', verbose = getOption("verbose"), scope = "private", owner = '',
scriptFile = NULL) scriptFile = NULL)
{ {
g_scriptFile <<- scriptFile assign("g_scriptFile", scriptFile, envir = test.env)
checkOwner(owner) checkOwner(owner)
checkConnectionString(connectionString) checkConnectionString(connectionString)
serverVersion <- checkVersion(connectionString) serverVersion <- checkVersion(connectionString)
@ -132,7 +134,7 @@ sql_remove.packages <- function(connectionString, pkgs, dependencies = TRUE, che
verbose = getOption("verbose"), scope = "private", owner = '', verbose = getOption("verbose"), scope = "private", owner = '',
scriptFile = NULL) scriptFile = NULL)
{ {
g_scriptFile <<- scriptFile assign("g_scriptFile", scriptFile, envir = test.env)
checkOwner(owner) checkOwner(owner)
checkConnectionString(connectionString) checkConnectionString(connectionString)
checkVersion(connectionString) checkVersion(connectionString)
@ -250,6 +252,7 @@ sql_remove.packages <- function(connectionString, pkgs, dependencies = TRUE, che
# #
sqlRemoteExecuteFun <- function(connection, FUN, ..., useRemoteFun = FALSE, asuser = NULL, includeFun = list()) sqlRemoteExecuteFun <- function(connection, FUN, ..., useRemoteFun = FALSE, asuser = NULL, includeFun = list())
{ {
g_scriptFile <- local(g_scriptFile, test.env)
if (class(connection) == "character"){ if (class(connection) == "character"){
if (nchar(connection) < 1){ if (nchar(connection) < 1){
stop(paste0("Invalid connection string: ", connection), call. = FALSE) stop(paste0("Invalid connection string: ", connection), call. = FALSE)
@ -817,10 +820,6 @@ sqlServerProperties <- function(connectionString)
checkOdbcHandle(hodbc, connectionString) checkOdbcHandle(hodbc, connectionString)
on.exit(odbcClose(hodbc), add = TRUE) on.exit(odbcClose(hodbc), add = TRUE)
# if(!is.null(g_scriptFile)) {
# cat(query, file=g_scriptFile, append=TRUE)
# cat("\n", file=g_scriptFile, append=TRUE)
# }
sqlResult <- sqlQuery(hodbc, query, stringsAsFactors = FALSE) sqlResult <- sqlQuery(hodbc, query, stringsAsFactors = FALSE)
if (is.data.frame(sqlResult)) if (is.data.frame(sqlResult))
@ -1226,6 +1225,7 @@ sqlInstallPackagesExtLib <- function(connectionString,
scope = "private", owner = '', scope = "private", owner = '',
serverVersion = serverVersion) serverVersion = serverVersion)
{ {
g_scriptFile <- local(g_scriptFile, test.env)
# #
# check permissions # check permissions
# #
@ -1532,6 +1532,7 @@ sqlInstallPackagesExtLib <- function(connectionString,
# #
sqlCreateExternalLibrary <- function(hodbc, packageName, packageFile, user = "") sqlCreateExternalLibrary <- function(hodbc, packageName, packageFile, user = "")
{ {
g_scriptFile <- local(g_scriptFile, test.env)
# read zip file into binary format # read zip file into binary format
fileConnection <- file(packageFile, 'rb') fileConnection <- file(packageFile, 'rb')
pkgBin <- readBin(con = fileConnection, what = raw(), n = file.size(packageFile)) pkgBin <- readBin(con = fileConnection, what = raw(), n = file.size(packageFile))
@ -1568,6 +1569,7 @@ sqlCreateExternalLibrary <- function(hodbc, packageName, packageFile, user = "")
# #
sqlDropExternalLibrary <- function(hodbc, packageName, user = "") sqlDropExternalLibrary <- function(hodbc, packageName, user = "")
{ {
g_scriptFile <- local(g_scriptFile, test.env)
haveUser <- (user != '') haveUser <- (user != '')
query <- paste0("DROP EXTERNAL LIBRARY [", packageName, "]") query <- paste0("DROP EXTERNAL LIBRARY [", packageName, "]")
@ -1595,6 +1597,7 @@ sqlDropExternalLibrary <- function(hodbc, packageName, user = "")
# #
sqlAddExtendedProperty <- function(hodbc, packageName, attributes, user = "") sqlAddExtendedProperty <- function(hodbc, packageName, attributes, user = "")
{ {
g_scriptFile <- local(g_scriptFile, test.env)
isTopLevel <- attributes & 0x1; isTopLevel <- attributes & 0x1;
haveUser <- (user != '') haveUser <- (user != '')
@ -1693,10 +1696,6 @@ sqlQueryExternalLibraryId <- function(hodbc, packagesNames, scopeint, queryUser)
" ;" " ;"
) )
# if(!is.null(g_scriptFile)) {
# cat(query, file=g_scriptFile, append=TRUE)
# cat("\n", file=g_scriptFile, append=TRUE)
# }
sqlResult <- sqlQuery(hodbc, query, stringsAsFactors = FALSE) sqlResult <- sqlQuery(hodbc, query, stringsAsFactors = FALSE)
if (is.data.frame(sqlResult)) if (is.data.frame(sqlResult))
@ -1742,7 +1741,7 @@ sqlQueryExternalLibrarySetupErrors <- function(hodbc, externalLibraryIds, queryU
if(colnames(sqlResult)[[1]]=="OBJECT_NOT_FOUND"){ if(colnames(sqlResult)[[1]]=="OBJECT_NOT_FOUND"){
sqlResult <- NULL sqlResult <- NULL
} else { } else {
sqlResult <- cbind(sqlResult, name=externalLibraryIds[ externalLibraryIds[, "external_library_id"]==sqlResult[,"external_library_id"], "name"]) sqlResult <- merge(sqlResult, externalLibraryIds)
rownames(sqlResult) <- sqlResult[, "name"] rownames(sqlResult) <- sqlResult[, "name"]
} }
} }
@ -2077,6 +2076,7 @@ sqlSyncRemovePackages <- function(hodbc, pkgs, externalLibraryIds, scope, user,
# #
sqlEnumTable <- function(connectionString, packagesNames, owner, scopeint) sqlEnumTable <- function(connectionString, packagesNames, owner, scopeint)
{ {
g_scriptFile <- local(g_scriptFile, test.env)
queryUser <- "CURRENT_USER" queryUser <- "CURRENT_USER"
if (scopeint == 0) # public if (scopeint == 0) # public

Просмотреть файл

@ -95,7 +95,6 @@ createSprocFromFunction <- function (connectionString, name, func,
#'@describeIn createSprocFromFunction Create stored procedure from script file, returns output of final line #'@describeIn createSprocFromFunction Create stored procedure from script file, returns output of final line
#' #'
#'@param script character string. The path to the script to wrap in the stored procedure #'@param script character string. The path to the script to wrap in the stored procedure
#'@param getScript boolean. Return the tsql script that would be run on the server instead of running it
#'@export #'@export
createSprocFromScript <- function (connectionString, name, script, createSprocFromScript <- function (connectionString, name, script,
inputParams = NULL, outputParams = NULL, inputParams = NULL, outputParams = NULL,
@ -204,6 +203,7 @@ dropSproc <- function(connectionString, name, getScript = FALSE) {
#' #'
#'@param connectionString character string. The connectionString to the database #'@param connectionString character string. The connectionString to the database
#'@param name character string. The name of the stored procedure #'@param name character string. The name of the stored procedure
#'@param getScript boolean. Return the tsql script that would be run on the server instead of running it
#' #'
#'@return Whether the stored procedure exists in the database #'@return Whether the stored procedure exists in the database
#' #'
@ -263,6 +263,7 @@ checkSproc <- function(connectionString, name, getScript=FALSE) {
#'@param connectionString character string. The connectionString for the database with the stored procedure #'@param connectionString character string. The connectionString for the database with the stored procedure
#'@param name character string. The name of the stored procedure in the database to execute #'@param name character string. The name of the stored procedure in the database to execute
#'@param ... named list. Parameters to pass into the procedure. These MUST be named the same as the arguments to the function. #'@param ... named list. Parameters to pass into the procedure. These MUST be named the same as the arguments to the function.
#'@param getScript boolean. Return the tsql script that would be run on the server instead of running it
#' #'
#'@section Warning: #'@section Warning:
#'Even though you can create stored procedures with output parameters, you CANNOT execute them #'Even though you can create stored procedures with output parameters, you CANNOT execute them
@ -302,6 +303,10 @@ executeSproc <- function(connectionString, name, ..., getScript) {
paramOrder <- res$inputParams paramOrder <- res$inputParams
df = data.frame(...) df = data.frame(...)
if(getScript) {
return(query)
}
if (nrow(df) != 0 && ncol(df) != 0) { if (nrow(df) != 0 && ncol(df) != 0) {
df <- df[paramOrder] df <- df[paramOrder]
} }

Двоичные данные
R/dist/sqlmlutils_0.7.0.zip поставляемый

Двоичный файл не отображается.

Просмотреть файл

@ -10,6 +10,8 @@ checkSproc(connectionString, name, getScript = FALSE)
\item{connectionString}{character string. The connectionString to the database} \item{connectionString}{character string. The connectionString to the database}
\item{name}{character string. The name of the stored procedure} \item{name}{character string. The name of the stored procedure}
\item{getScript}{boolean. Return the tsql script that would be run on the server instead of running it}
} }
\value{ \value{
Whether the stored procedure exists in the database Whether the stored procedure exists in the database

Просмотреть файл

@ -27,8 +27,6 @@ where the names are the arguments and the values are the types}
\item{getScript}{boolean. Return the tsql script that would be run on the server instead of running it} \item{getScript}{boolean. Return the tsql script that would be run on the server instead of running it}
\item{script}{character string. The path to the script to wrap in the stored procedure} \item{script}{character string. The path to the script to wrap in the stored procedure}
\item{getScript}{boolean. Return the tsql script that would be run on the server instead of running it}
} }
\value{ \value{
Invisibly returns the script used to create the stored procedure Invisibly returns the script used to create the stored procedure

Просмотреть файл

@ -12,6 +12,8 @@ executeSproc(connectionString, name, ..., getScript)
\item{name}{character string. The name of the stored procedure in the database to execute} \item{name}{character string. The name of the stored procedure in the database to execute}
\item{...}{named list. Parameters to pass into the procedure. These MUST be named the same as the arguments to the function.} \item{...}{named list. Parameters to pass into the procedure. These MUST be named the same as the arguments to the function.}
\item{getScript}{boolean. Return the tsql script that would be run on the server instead of running it}
} }
\description{ \description{
Execute a Stored Procedure Execute a Stored Procedure