From e53cf688dff86fc6820dfed161d1eeeb5f79d798 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 13:46:12 +0200 Subject: [PATCH 01/28] Move is*() functions to new file logical.R - Add is64BitR() --- R/base.R | 70 -------------------------------------- R/logical.R | 76 ++++++++++++++++++++++++++++++++++++++++++ man/isExcel2003File.Rd | 2 +- man/isExcel2007File.Rd | 2 +- man/isExcelFile.Rd | 2 +- 5 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 R/logical.R diff --git a/R/base.R b/R/base.R index 76d5b2c..9620807 100644 --- a/R/base.R +++ b/R/base.R @@ -388,76 +388,6 @@ hsPutTable <- function( tblSafe } -# isOdbcDataSource ------------------------------------------------------------- - -isOdbcDataSource <- function(db) -{ - db %in% names(RODBC::odbcDataSources()) -} - -# isAccess2007File ------------------------------------------------------------- - -isAccess2007File <- function(filepath) -{ - grepl("\\.accdb$", filepath) -} - -# isAccess2003File ------------------------------------------------------------- - -isAccess2003File <- function(filepath) -{ - grepl("\\.mdb$", filepath) -} - -# isAccessFile ----------------------------------------------------------------- - -isAccessFile <- function(filepath) -{ - isAccess2003File(filepath) || isAccess2007File(filepath) -} - -# isExcel2007File -------------------------------------------------------------- - -#' Is this an XLSX file? -#' -#' @param filepath (vector of) path(s) to the file(s) to be checked for .xlsx -#' extension -#' -#' @return (vector of) logical. -#' -isExcel2007File <- function(filepath) -{ - grepl("\\.xlsx$", filepath, ignore.case = TRUE) -} - -# isExcel2003File -------------------------------------------------------------- - -#' Is this an XLS file? -#' -#' @param filepath (vector of) path(s) to the file(s) to be checked for .xls -#' extension -#' -#' @return (vector of) logical. -#' -isExcel2003File <- function(filepath) -{ - grepl("\\.xls$", filepath, ignore.case = TRUE) -} - -# isExcelFile ------------------------------------------------------------------ - -#' Is this an Excel file? -#' -#' @param filepath (vector of) path(s) to the file(s) to be checked for .xls -#' or .xlsx extension -#' -#' @return (vector of) logical. -#' -isExcelFile <- function(filepath) -{ - isExcel2003File(filepath) || isExcel2007File(filepath) -} - # hsGetTable ------------------------------------------------------------------- #' Get Table from MS Access Database diff --git a/R/logical.R b/R/logical.R new file mode 100644 index 0000000..215336c --- /dev/null +++ b/R/logical.R @@ -0,0 +1,76 @@ +# is64BitR --------------------------------------------------------------------- + +is64BitR <- function() +{ + .Machine$sizeof.pointer == 8 +} + +# isOdbcDataSource ------------------------------------------------------------- + +isOdbcDataSource <- function(db) +{ + db %in% names(RODBC::odbcDataSources()) +} + +# isAccess2007File ------------------------------------------------------------- + +isAccess2007File <- function(filepath) +{ + grepl("\\.accdb$", filepath) +} + +# isAccess2003File ------------------------------------------------------------- + +isAccess2003File <- function(filepath) +{ + grepl("\\.mdb$", filepath) +} + +# isAccessFile ----------------------------------------------------------------- + +isAccessFile <- function(filepath) +{ + isAccess2003File(filepath) || isAccess2007File(filepath) +} + +# isExcel2007File -------------------------------------------------------------- + +#' Is this an XLSX file? +#' +#' @param filepath (vector of) path(s) to the file(s) to be checked for .xlsx +#' extension +#' +#' @return (vector of) logical. +#' +isExcel2007File <- function(filepath) +{ + grepl("\\.xlsx$", filepath, ignore.case = TRUE) +} + +# isExcel2003File -------------------------------------------------------------- + +#' Is this an XLS file? +#' +#' @param filepath (vector of) path(s) to the file(s) to be checked for .xls +#' extension +#' +#' @return (vector of) logical. +#' +isExcel2003File <- function(filepath) +{ + grepl("\\.xls$", filepath, ignore.case = TRUE) +} + +# isExcelFile ------------------------------------------------------------------ + +#' Is this an Excel file? +#' +#' @param filepath (vector of) path(s) to the file(s) to be checked for .xls +#' or .xlsx extension +#' +#' @return (vector of) logical. +#' +isExcelFile <- function(filepath) +{ + isExcel2003File(filepath) || isExcel2007File(filepath) +} diff --git a/man/isExcel2003File.Rd b/man/isExcel2003File.Rd index 545b247..73cbf74 100644 --- a/man/isExcel2003File.Rd +++ b/man/isExcel2003File.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/logical.R \name{isExcel2003File} \alias{isExcel2003File} \title{Is this an XLS file?} diff --git a/man/isExcel2007File.Rd b/man/isExcel2007File.Rd index 6421565..ac14351 100644 --- a/man/isExcel2007File.Rd +++ b/man/isExcel2007File.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/logical.R \name{isExcel2007File} \alias{isExcel2007File} \title{Is this an XLSX file?} diff --git a/man/isExcelFile.Rd b/man/isExcelFile.Rd index df1286d..98f2946 100644 --- a/man/isExcelFile.Rd +++ b/man/isExcelFile.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/logical.R \name{isExcelFile} \alias{isExcelFile} \title{Is this an Excel file?} From e687e92219b8e11f5716d877665f8cffd7e24c8e Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 13:48:34 +0200 Subject: [PATCH 02/28] Move isMySQL() to logical.R - bring functions in logical.R into alphabetical order --- R/base.R | 25 ------------------------- R/logical.R | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/R/base.R b/R/base.R index 9620807..4644bb4 100644 --- a/R/base.R +++ b/R/base.R @@ -1,28 +1,3 @@ -# isMySQL ---------------------------------------------------------------------- - -#' Is the Given Database of Type MySQL? -#' -#' @param db database file (*.mdb, *.accdb, *.xls, *.xlsx) or name of ODBC -#' database -#' @param \dots arguments passed to \code{\link{hsOpenDb}}, e.g. -#' \emph{use2007Driver} -#' -#' @return TRUE if \emph{db} is a MySQL database, else FALSE -#' -isMySQL <- function(db, ...) -{ - sqlDialect <- getCurrentSqlDialect(warn = FALSE) - - connection <- hsOpenDb(db, ...) - - on.exit({ - hsCloseDb(connection) - setCurrentSqlDialect(sqlDialect) - }) - - attr(connection, "isMySQL") -} - # hsOpenMdb -------------------------------------------------------------------- #' Open Connection to MS Access Database diff --git a/R/logical.R b/R/logical.R index 215336c..f5270b3 100644 --- a/R/logical.R +++ b/R/logical.R @@ -5,13 +5,6 @@ is64BitR <- function() .Machine$sizeof.pointer == 8 } -# isOdbcDataSource ------------------------------------------------------------- - -isOdbcDataSource <- function(db) -{ - db %in% names(RODBC::odbcDataSources()) -} - # isAccess2007File ------------------------------------------------------------- isAccess2007File <- function(filepath) @@ -74,3 +67,35 @@ isExcelFile <- function(filepath) { isExcel2003File(filepath) || isExcel2007File(filepath) } + +# isMySQL ---------------------------------------------------------------------- + +#' Is the Given Database of Type MySQL? +#' +#' @param db database file (*.mdb, *.accdb, *.xls, *.xlsx) or name of ODBC +#' database +#' @param \dots arguments passed to \code{\link{hsOpenDb}}, e.g. +#' \emph{use2007Driver} +#' +#' @return TRUE if \emph{db} is a MySQL database, else FALSE +#' +isMySQL <- function(db, ...) +{ + sqlDialect <- getCurrentSqlDialect(warn = FALSE) + + connection <- hsOpenDb(db, ...) + + on.exit({ + hsCloseDb(connection) + setCurrentSqlDialect(sqlDialect) + }) + + attr(connection, "isMySQL") +} + +# isOdbcDataSource ------------------------------------------------------------- + +isOdbcDataSource <- function(db) +{ + db %in% names(RODBC::odbcDataSources()) +} From 42b3cec65d715cb32553e7dd61373cd418265bd9 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 13:53:03 +0200 Subject: [PATCH 03/28] Move functions to new file connect.R - functions related to opening and closing a connection - aim: reduce size of source files --- R/base.R | 235 ---------------------------------------------- R/connect.R | 234 +++++++++++++++++++++++++++++++++++++++++++++ man/hsCloseDb.Rd | 2 +- man/hsCloseMdb.Rd | 2 +- man/hsOpenDb.Rd | 2 +- man/hsOpenMdb.Rd | 2 +- man/isMySQL.Rd | 2 +- 7 files changed, 239 insertions(+), 240 deletions(-) create mode 100644 R/connect.R diff --git a/R/base.R b/R/base.R index 4644bb4..929ab89 100644 --- a/R/base.R +++ b/R/base.R @@ -1,238 +1,3 @@ -# hsOpenMdb -------------------------------------------------------------------- - -#' Open Connection to MS Access Database -#' -#' Deprecated. Use \code{\link{hsOpenDb}} instead. -#' -#' @param mdb full path to MS Access database file. -#' @param dbg if TRUE and if the connection could be established details of the -#' connection are shown. -#' -hsOpenMdb <- function(mdb, dbg = FALSE) -{ - hsOpenDb(mdb, dbg) -} - -# hsOpenDb --------------------------------------------------------------------- - -#' Open Connection to MS Access or Excel -#' -#' Opens database connection to MS Access or MS Excel, checks the connection and -#' stops on error. -#' -#' @param src full path to MS Access database file (extension \dQuote{.mdb} or -#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or -#' \dQuote{.xlsx}) or name of ODBC data source. -#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and -#' odbcConnectExcel2007 are used instead of odbcConnectAccess and -#' odbcConnectExcel, respectively -#' @param dbg if TRUE and if the connection could be established details of the -#' connection are shown. -#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", -#' You may want to use: "UTF-8" -#' @param \dots additional arguments passed to the odbcConnect...()-function -#' -#' @return On success an object of class RODBC describing the connection is -#' returned. On failure nothing is returned and program execution stops. -#' -#' @seealso \code{\link{hsCloseDb}} -#' -#' @examples -#' \dontrun{ -#' ## Open a connection to the example database -#' ## (only on Windows!) -#' -#' if (.Platform$OS.type == "windows") { -#' -#' con <- hsOpenDb(xmdb()) -#' con -#' } -#' -#' ## Details on the established connection are shown: -#' # RODBC Connection 9 -#' # Details: -#' # case=nochange -#' # DBQ=C:\Users\hsonne\Documents\R\win-library\2.14\kwb.base\... -#' # Driver={Microsoft Access Driver (*.mdb)} -#' # DriverId=25 -#' # FIL=MS Access -#' # MaxBufferSize=2048 -#' # PageTimeout=5 -#' # UID=admin -#' -#' ## Close the connection again -#' -#' if (.Platform$OS.type == "windows") { -#' -#' hsCloseDb(con) -#' } -#' } -#' -hsOpenDb <- function( - src, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... -) -{ - kwb.utils::catIf(dbg, "in hsOpenDb: use2007Driver =", use2007Driver, "\n") - - if (missing(src) || length(src) == 0) { - - stop("No source file (*.mdb, *.accdb, *.xls or *.xlsx) ", - "or name of ODBC data source given.") - } - - if (mode(src) != "character" || length(src) > 1) { - - stop("src must be a character vector of length one.") - } - - ## Open database connection - con <- openAdequateConnectionOrStop( - src, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... - ) - - ## Return if connection failed - if (con == -1) { - - stop("Could not connect to database: ", src) - } - - ## in debug mode, print connection - kwb.utils::printIf(dbg, con, "Connection") - - setCurrentSqlDialect(ifelse(attr(con, "isMySQL"), "mysql", "msaccess")) - - con -} - -# openAdequateConnectionOrStop ------------------------------------------------- - -#' Open Adequate Connection or Stop -#' -#' @param db database name or file -#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and -#' odbcConnectExcel2007 are used instead of odbcConnectAccess and -#' odbcConnectExcel, respectively -#' @param dbg if \code{TRUE}, debug messages are shown -#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", -#' You may want to use: "UTF-8" -#' @param \dots further arguments passed to \code{odbcConnectionAccess}, -#' \code{odbcConnectionExcel} or \code{\link[RODBC]{odbcConnect}} -#' -openAdequateConnectionOrStop <- function( - db, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... -) -{ - kwb.utils::catIf( - dbg, "in openAdequateConnectionOrStop: use2007Driver =", use2007Driver, "\n" - ) - - is.mdb <- isAccessFile(db) - is.xls <- isExcelFile(db) - - if ((is.mdb || is.xls) &&! file.exists(db)) { - - stop("No such file: '", db, "'! Please check the path!", call. = FALSE) - } - - if (is.mdb) { - - con <- odbcConnectionAccess( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) - - } else if (is.xls) { - - con <- odbcConnectionExcel( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) - - } else if (isOdbcDataSource(db)) { - - con <- RODBC::odbcConnect( - db, DBMSencoding = DBMSencoding, ...) - - } else { - - odbcSources <- names(RODBC::odbcDataSources()) - - stop( - "src must be a file name with extension .mdb, .accdb, .xls, .xlsx ", - "or the name of an existing ODBC data source. ", - "Available ODBC data sources are:\n * ", - paste(odbcSources, collapse = ",\n * ") - ) - } -} - -# odbcConnectionAccess --------------------------------------------------------- - -odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) -{ - if (is.null(use2007Driver)) { - - use2007Driver <- isAccess2007File(db) - } - - if (use2007Driver) { - - RODBC::odbcConnectAccess2007(db, ...) - - } else { - - RODBC::odbcConnectAccess(db, ...) - } -} - -# odbcConnectionExcel ---------------------------------------------------------- - -odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) -{ - if (is.null(use2007Driver)) { - - use2007Driver <- isExcel2007File(db) - } - - if (use2007Driver) { - - RODBC::odbcConnectExcel2007(db, ...) - - } else { - - RODBC::odbcConnectExcel(db, ...) - } -} - -# hsCloseMdb ------------------------------------------------------------------- - -#' Close Connection -#' -#' Deprecated. Use code{\link{hsCloseDb}} instead. -#' -#' @param con Open database connection as returned by -#' \link{hsOpenMdb}/odbcConnect -#' -hsCloseMdb <- function(con) -{ - hsCloseDb(con) -} - -# hsCloseDb -------------------------------------------------------------------- - -#' Close Connection to MS Access or Excel -#' -#' Closes the database connection. -#' -#' @param con Open database connection as returned by -#' \link{hsOpenDb}/\code{odbcConnect} -#' -#' @seealso \code{\link{hsOpenDb}} -#' -hsCloseDb <- function(con) -{ - ## Close database connection - RODBC::odbcClose(con) - - #options("kwb.db.current.sql.dialect" = NULL) -} - # hsPutTable ------------------------------------------------------------------- #' Save Data Frame to Database Table diff --git a/R/connect.R b/R/connect.R new file mode 100644 index 0000000..8f47bce --- /dev/null +++ b/R/connect.R @@ -0,0 +1,234 @@ +# hsOpenMdb -------------------------------------------------------------------- + +#' Open Connection to MS Access Database +#' +#' Deprecated. Use \code{\link{hsOpenDb}} instead. +#' +#' @param mdb full path to MS Access database file. +#' @param dbg if TRUE and if the connection could be established details of the +#' connection are shown. +#' +hsOpenMdb <- function(mdb, dbg = FALSE) +{ + hsOpenDb(mdb, dbg) +} + +# hsOpenDb --------------------------------------------------------------------- + +#' Open Connection to MS Access or Excel +#' +#' Opens database connection to MS Access or MS Excel, checks the connection and +#' stops on error. +#' +#' @param src full path to MS Access database file (extension \dQuote{.mdb} or +#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or +#' \dQuote{.xlsx}) or name of ODBC data source. +#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and +#' odbcConnectExcel2007 are used instead of odbcConnectAccess and +#' odbcConnectExcel, respectively +#' @param dbg if TRUE and if the connection could be established details of the +#' connection are shown. +#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", +#' You may want to use: "UTF-8" +#' @param \dots additional arguments passed to the odbcConnect...()-function +#' +#' @return On success an object of class RODBC describing the connection is +#' returned. On failure nothing is returned and program execution stops. +#' +#' @seealso \code{\link{hsCloseDb}} +#' +#' @examples +#' \dontrun{ +#' ## Open a connection to the example database +#' ## (only on Windows!) +#' +#' if (.Platform$OS.type == "windows") { +#' +#' con <- hsOpenDb(xmdb()) +#' con +#' } +#' +#' ## Details on the established connection are shown: +#' # RODBC Connection 9 +#' # Details: +#' # case=nochange +#' # DBQ=C:\Users\hsonne\Documents\R\win-library\2.14\kwb.base\... +#' # Driver={Microsoft Access Driver (*.mdb)} +#' # DriverId=25 +#' # FIL=MS Access +#' # MaxBufferSize=2048 +#' # PageTimeout=5 +#' # UID=admin +#' +#' ## Close the connection again +#' +#' if (.Platform$OS.type == "windows") { +#' +#' hsCloseDb(con) +#' } +#' } +#' +hsOpenDb <- function( + src, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... +) +{ + kwb.utils::catIf(dbg, "in hsOpenDb: use2007Driver =", use2007Driver, "\n") + + if (missing(src) || length(src) == 0) { + + stop("No source file (*.mdb, *.accdb, *.xls or *.xlsx) ", + "or name of ODBC data source given.") + } + + if (mode(src) != "character" || length(src) > 1) { + + stop("src must be a character vector of length one.") + } + + ## Open database connection + con <- openAdequateConnectionOrStop( + src, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... + ) + + ## Return if connection failed + if (con == -1) { + + stop("Could not connect to database: ", src) + } + + ## in debug mode, print connection + kwb.utils::printIf(dbg, con, "Connection") + + setCurrentSqlDialect(ifelse(attr(con, "isMySQL"), "mysql", "msaccess")) + + con +} + +# openAdequateConnectionOrStop ------------------------------------------------- + +#' Open Adequate Connection or Stop +#' +#' @param db database name or file +#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and +#' odbcConnectExcel2007 are used instead of odbcConnectAccess and +#' odbcConnectExcel, respectively +#' @param dbg if \code{TRUE}, debug messages are shown +#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", +#' You may want to use: "UTF-8" +#' @param \dots further arguments passed to \code{odbcConnectionAccess}, +#' \code{odbcConnectionExcel} or \code{\link[RODBC]{odbcConnect}} +#' +openAdequateConnectionOrStop <- function( + db, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... +) +{ + kwb.utils::catIf( + dbg, "in openAdequateConnectionOrStop: use2007Driver =", use2007Driver, "\n" + ) + + is.mdb <- isAccessFile(db) + is.xls <- isExcelFile(db) + + if ((is.mdb || is.xls) &&! file.exists(db)) { + + stop("No such file: '", db, "'! Please check the path!", call. = FALSE) + } + + if (is.mdb) { + + con <- odbcConnectionAccess( + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) + + } else if (is.xls) { + + con <- odbcConnectionExcel( + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) + + } else if (isOdbcDataSource(db)) { + + con <- RODBC::odbcConnect( + db, DBMSencoding = DBMSencoding, ...) + + } else { + + odbcSources <- names(RODBC::odbcDataSources()) + + stop( + "src must be a file name with extension .mdb, .accdb, .xls, .xlsx ", + "or the name of an existing ODBC data source. ", + "Available ODBC data sources are:\n * ", + paste(odbcSources, collapse = ",\n * ") + ) + } +} + +# odbcConnectionAccess --------------------------------------------------------- + +odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) +{ + if (is.null(use2007Driver)) { + + use2007Driver <- isAccess2007File(db) + } + + if (use2007Driver) { + + RODBC::odbcConnectAccess2007(db, ...) + + } else { + + RODBC::odbcConnectAccess(db, ...) + } +} + +# odbcConnectionExcel ---------------------------------------------------------- + +odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) +{ + if (is.null(use2007Driver)) { + + use2007Driver <- isExcel2007File(db) + } + + if (use2007Driver) { + + RODBC::odbcConnectExcel2007(db, ...) + + } else { + + RODBC::odbcConnectExcel(db, ...) + } +} + +# hsCloseMdb ------------------------------------------------------------------- + +#' Close Connection +#' +#' Deprecated. Use code{\link{hsCloseDb}} instead. +#' +#' @param con Open database connection as returned by +#' \link{hsOpenMdb}/odbcConnect +#' +hsCloseMdb <- function(con) +{ + hsCloseDb(con) +} + +# hsCloseDb -------------------------------------------------------------------- + +#' Close Connection to MS Access or Excel +#' +#' Closes the database connection. +#' +#' @param con Open database connection as returned by +#' \link{hsOpenDb}/\code{odbcConnect} +#' +#' @seealso \code{\link{hsOpenDb}} +#' +hsCloseDb <- function(con) +{ + ## Close database connection + RODBC::odbcClose(con) + + #options("kwb.db.current.sql.dialect" = NULL) +} diff --git a/man/hsCloseDb.Rd b/man/hsCloseDb.Rd index b17234c..f6c48d1 100644 --- a/man/hsCloseDb.Rd +++ b/man/hsCloseDb.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/connect.R \name{hsCloseDb} \alias{hsCloseDb} \title{Close Connection to MS Access or Excel} diff --git a/man/hsCloseMdb.Rd b/man/hsCloseMdb.Rd index 29d482a..c460cf8 100644 --- a/man/hsCloseMdb.Rd +++ b/man/hsCloseMdb.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/connect.R \name{hsCloseMdb} \alias{hsCloseMdb} \title{Close Connection} diff --git a/man/hsOpenDb.Rd b/man/hsOpenDb.Rd index 695ef5a..d2e02a7 100644 --- a/man/hsOpenDb.Rd +++ b/man/hsOpenDb.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/connect.R \name{hsOpenDb} \alias{hsOpenDb} \title{Open Connection to MS Access or Excel} diff --git a/man/hsOpenMdb.Rd b/man/hsOpenMdb.Rd index b91801c..3870414 100644 --- a/man/hsOpenMdb.Rd +++ b/man/hsOpenMdb.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/connect.R \name{hsOpenMdb} \alias{hsOpenMdb} \title{Open Connection to MS Access Database} diff --git a/man/isMySQL.Rd b/man/isMySQL.Rd index c262b8c..1f7a90e 100644 --- a/man/isMySQL.Rd +++ b/man/isMySQL.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/logical.R \name{isMySQL} \alias{isMySQL} \title{Is the Given Database of Type MySQL?} From 0049d10bf79d9dd06f9326d5dac5e46a195eadbb Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 13:58:47 +0200 Subject: [PATCH 04/28] Warn to use hsOpenDb() instead of hsOpenMdb() - rename is.mdb to is_mdb, is.xls to is_xls --- R/connect.R | 11 ++++++----- man/openAdequateConnectionOrStop.Rd | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/R/connect.R b/R/connect.R index 8f47bce..5a61c9e 100644 --- a/R/connect.R +++ b/R/connect.R @@ -10,6 +10,7 @@ #' hsOpenMdb <- function(mdb, dbg = FALSE) { + kwb.utils::warningDeprecated("kwb.db::hsOpenMdb", "kwb.db::hsOpenDb") hsOpenDb(mdb, dbg) } @@ -126,20 +127,20 @@ openAdequateConnectionOrStop <- function( dbg, "in openAdequateConnectionOrStop: use2007Driver =", use2007Driver, "\n" ) - is.mdb <- isAccessFile(db) - is.xls <- isExcelFile(db) + is_mdb <- isAccessFile(db) + is_xls <- isExcelFile(db) - if ((is.mdb || is.xls) &&! file.exists(db)) { + if ((is_mdb || is_xls) &&! file.exists(db)) { stop("No such file: '", db, "'! Please check the path!", call. = FALSE) } - if (is.mdb) { + if (is_mdb) { con <- odbcConnectionAccess( db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) - } else if (is.xls) { + } else if (is_xls) { con <- odbcConnectionExcel( db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) diff --git a/man/openAdequateConnectionOrStop.Rd b/man/openAdequateConnectionOrStop.Rd index e372d25..4689e90 100644 --- a/man/openAdequateConnectionOrStop.Rd +++ b/man/openAdequateConnectionOrStop.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/base.R +% Please edit documentation in R/connect.R \name{openAdequateConnectionOrStop} \alias{openAdequateConnectionOrStop} \title{Open Adequate Connection or Stop} From 953e7bcb785b0d8ea4cd8525d39de08d74027a78 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 16:28:50 +0200 Subject: [PATCH 05/28] Let Roxygen generate NAMESPACE, use importFrom - move kwb.utils from "Depends" to "Imports" - move kwb.datetime from "Suggests" to "Depends" --- DESCRIPTION | 8 +++-- NAMESPACE | 68 ++++++++++++------------------------ R/base.R | 11 +++--- R/connect.R | 4 ++- R/convert.R | 7 ++-- R/db_interface_select_from.R | 10 ++++++ R/getNamedExcelRanges.R | 7 ++-- R/logical.R | 1 + R/main.R | 29 +++++++++++---- R/schema.R | 3 ++ R/server_specifics.R | 4 ++- R/sql.R | 13 ++++--- R/sql_expressions.R | 8 ++--- R/sql_join.R | 5 +-- R/sql_top_level.R | 1 + man/renamesToFieldList.Rd | 2 +- 16 files changed, 103 insertions(+), 78 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 40de516..56b36e0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,15 +24,17 @@ Authors@R: comment = "0000-0003-0647-7726"), person(given = "Kompetenzzentrum Wasser Berlin gGmbH", role = "cph")) -Imports: kwb.utils, RODBC -Suggests: +Imports: RODBC +Depends: kwb.datetime, + kwb.utils +Suggests: testthat Remotes: github::kwb-r/kwb.datetime, github::kwb-r/kwb.utils Encoding: UTF-8 License: MIT + file LICENSE -RoxygenNote: 6.1.0 +RoxygenNote: 6.1.1 URL: https://github.com/KWB-R/kwb.db BugReports: https://github.com/KWB-R/kwb.db/issues diff --git a/NAMESPACE b/NAMESPACE index 9f490bb..9edf691 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,68 +1,44 @@ -export(connectionStringAccess) -export(createRDatabaseInterface) -export(currentDb) +# Generated by roxygen2: do not edit by hand + export(dataFrameToSqlTuples) -export(dumpDatabase) export(getCurrentSqlDialect) -export(getDatabaseSchema) -export(getFilteredRecords) -export(getSqlDialect) -export(getTypeIdentifier) -export(hsClearTable) -export(hsCloseDb) -export(hsCloseMdb) +export(getNamedExcelRanges) export(hsDropTable) -export(hsDumpMdb) export(hsFields) export(hsGetTable) export(hsGetTimeSeries) -export(hsJetDate) -export(hsLookupOrAddRecord) export(hsMdbTimeSeries) -export(hsOpenDb) -export(hsOpenMdb) export(hsPutTable) -export(hsSetForeignKey) -export(hsSetPrimaryKey) export(hsSqlExAnd) export(hsSqlExOr) -export(hsSqlExTimeCond) export(hsSqlExTimeGroup) export(hsSqlExTsFields) export(hsSqlQuery) export(hsTables) -export(hsTsField) -export(isExcel2007File) export(isExcelFile) -export(isMySQL) +export(keyValueToSql) export(keyValuesToSql) -export(keyValuesToSqlAssignment) -export(keyValuesToSqlAssignment2) -export(keyValuesToSqlFilter) export(listValuesToSql) -export(lookupRecord) -export(openAdequateConnectionOrStop) -export(printDatabaseSchema) -export(rcode_DatabaseInterface) -export(readSqlCommandsFromFile) export(renamesToFieldList) -export(renamesToQueries) -export(runSqlCommandsFromFile) -export(safeTableName) -export(selectFromDb) -export(selectFromTable) -export(setCurrentDb) export(setCurrentSqlDialect) -export(sqlForInsert) -export(sqlForInsertDataFrame) -export(sqlForInsertFromSelect) -export(sqlForInsertIgnoreInMsAccess) export(sqlForSelect) -export(sqlForSelectByKey) -export(sqlForUpdate) export(sqlFullLeftJoin) -export(sqlJoinExpression) -export(sqlLeftJoin) -export(sqlLeftJoinBody) export(sqlLeftJoinExpression) -export(xmdb) +importFrom(kwb.datetime,hsToPosix) +importFrom(kwb.utils,catAndRun) +importFrom(kwb.utils,catIf) +importFrom(kwb.utils,commaCollapsed) +importFrom(kwb.utils,createDirectory) +importFrom(kwb.utils,hsQuoteChr) +importFrom(kwb.utils,hsSafeName) +importFrom(kwb.utils,hsTrim) +importFrom(kwb.utils,inRange) +importFrom(kwb.utils,isNullOrEmpty) +importFrom(kwb.utils,printIf) +importFrom(kwb.utils,safePath) +importFrom(kwb.utils,warningDeprecated) +importFrom(kwb.utils,windowsPath) +importFrom(stats,setNames) +importFrom(utils,head) +importFrom(utils,str) +importFrom(utils,write.table) diff --git a/R/base.R b/R/base.R index 929ab89..ba5862f 100644 --- a/R/base.R +++ b/R/base.R @@ -22,7 +22,8 @@ #' @return In case of success the name of the created table is returned. #' #' @seealso \code{\link{hsSqlQuery}, \link{hsGetTable}} -#' +#' @importFrom kwb.utils hsSafeName +#' @export #' @examples #' \dontrun{ #' ## Create a data.frame @@ -156,7 +157,8 @@ hsPutTable <- function( #' #' @seealso \code{\link{hsSqlQuery}, \link{hsPutTable}, hsGetTimeSeries, #' hsMdbTimeSeries} -#' +#' @importFrom kwb.utils hsQuoteChr +#' @export #' @examples #' \dontrun{ #' ## Get all datasets from tbl_Hyd in example database where @@ -301,7 +303,8 @@ hsGetTable <- function( #' RODBC package. #' #' @seealso \code{\link{hsFields}} -#' +#' @importFrom kwb.utils catIf +#' @export #' @examples #' \dontrun{ #' ## Get names of tables in the example database @@ -384,7 +387,7 @@ hsTables <- function( #' the database fields in detail, otherwise. #' #' @seealso \code{\link{hsTables}} -#' +#' @export #' @examples #' \dontrun{ #' ## List the fields of table "tbl_Hyd" in the example database diff --git a/R/connect.R b/R/connect.R index 5a61c9e..cdfceb2 100644 --- a/R/connect.R +++ b/R/connect.R @@ -7,6 +7,7 @@ #' @param mdb full path to MS Access database file. #' @param dbg if TRUE and if the connection could be established details of the #' connection are shown. +#' @importFrom kwb.utils warningDeprecated #' hsOpenMdb <- function(mdb, dbg = FALSE) { @@ -37,7 +38,7 @@ hsOpenMdb <- function(mdb, dbg = FALSE) #' returned. On failure nothing is returned and program execution stops. #' #' @seealso \code{\link{hsCloseDb}} -#' +#' @importFrom kwb.utils catIf printIf #' @examples #' \dontrun{ #' ## Open a connection to the example database @@ -118,6 +119,7 @@ hsOpenDb <- function( #' You may want to use: "UTF-8" #' @param \dots further arguments passed to \code{odbcConnectionAccess}, #' \code{odbcConnectionExcel} or \code{\link[RODBC]{odbcConnect}} +#' @importFrom kwb.utils catIf #' openAdequateConnectionOrStop <- function( db, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... diff --git a/R/convert.R b/R/convert.R index 812b669..1b0e935 100644 --- a/R/convert.R +++ b/R/convert.R @@ -16,9 +16,9 @@ renamesToQueries <- function(renamesList) lapply(seq_along(renamesList), function(i) { - structure(alias = LETTERS[i], kwb.db::sqlForSelect( + structure(alias = LETTERS[i], sqlForSelect( tablename = names(renamesList)[i], - fields = kwb.db::renamesToFieldList(renamesList[[i]]) + fields = renamesToFieldList(renamesList[[i]]) )) }) } @@ -28,7 +28,7 @@ renamesToQueries <- function(renamesList) #' List of Renamings to Field Selection String #' #' Convert a list of renamings to a field selection string that can be used as -#' \code{fields} argument in a call to \code{kwb.db::hsGetTable} +#' \code{fields} argument in a call to \code{\link[kwb.db]{hsGetTable}} #' #' @param renames list of key = value pairs defining renamings from the keys to #' the values @@ -36,6 +36,7 @@ renamesToQueries <- function(renamesList) #' will be enclosed in square brackets: \code{[source] AS } #' @param target.in.brackets if \code{TRUE} (default) the target names will be #' enclosed in square brackets: \code{ AS [target]} +#' @export #' renamesToFieldList <- function( renames, source.in.brackets = TRUE, target.in.brackets = TRUE diff --git a/R/db_interface_select_from.R b/R/db_interface_select_from.R index 8631b82..bd4532c 100644 --- a/R/db_interface_select_from.R +++ b/R/db_interface_select_from.R @@ -55,6 +55,8 @@ argumentsToSqlParts <- function( # .argumentsToFieldNames ------------------------------------------------------- +#' @importFrom kwb.utils isNullOrEmpty hsTrim +#' .argumentsToFieldNames <- function(mainArgument, arguments, argumentPrefix) { #arguments <- list(...) @@ -98,6 +100,8 @@ argumentsToSqlParts <- function( # .argumentsToConditions ------------------------------------------------------- +#' @importFrom kwb.utils hsTrim +#' .argumentsToConditions <- function(mainArgument, arguments, argumentPrefix) { fieldNames <- .stripPrefix(names(arguments), argumentPrefix) @@ -169,6 +173,8 @@ argumentsToSqlParts <- function( # .toCondition ----------------------------------------------------------------- +#' @importFrom kwb.utils commaCollapsed hsQuoteChr +#' .toCondition <- function(fieldName, value) { if (mode(value) == "numeric") { @@ -217,6 +223,8 @@ argumentsToSqlParts <- function( # .looksLikeFullExpression ----------------------------------------------------- +#' @importFrom kwb.utils hsTrim +#' .looksLikeFullExpression <- function(x) { grepl( @@ -242,6 +250,8 @@ argumentsToSqlParts <- function( # .toSafeIndices --------------------------------------------------------------- +#' @importFrom kwb.utils inRange +#' .toSafeIndices <- function(mainArgument, argumentPrefix, maxIndex) { indices <- round(mainArgument) diff --git a/R/getNamedExcelRanges.R b/R/getNamedExcelRanges.R index ea39947..7e6e50d 100644 --- a/R/getNamedExcelRanges.R +++ b/R/getNamedExcelRanges.R @@ -12,21 +12,22 @@ #' @return list of data frames each of which represents the content a named cell #' range in the Excel \code{file} and each of which was read with #' \code{\link{hsGetTable}}. -#' +#' @importFrom kwb.utils catAndRun +#' @importFrom stats setNames #' @export #' getNamedExcelRanges <- function( file, pattern = "^range", dbg = TRUE, stringsAsFactors = FALSE, ... ) { - table_names <- kwb.db::hsTables(file) + table_names <- hsTables(file) range_names <- table_names[grepl(pattern, table_names)] ranges <- lapply(range_names, function(range_name) { kwb.utils::catAndRun( sprintf("Getting range '%s'", range_name), - kwb.db::hsGetTable( + hsGetTable( mdb = file, tbl = range_name, stringsAsFactors = stringsAsFactors, dbg = FALSE, ... ) diff --git a/R/logical.R b/R/logical.R index f5270b3..7760d4d 100644 --- a/R/logical.R +++ b/R/logical.R @@ -62,6 +62,7 @@ isExcel2003File <- function(filepath) #' or .xlsx extension #' #' @return (vector of) logical. +#' @export #' isExcelFile <- function(filepath) { diff --git a/R/main.R b/R/main.R index bad8b79..f6dd6cd 100644 --- a/R/main.R +++ b/R/main.R @@ -17,6 +17,7 @@ setCurrentDb <- function(db) #' \code{\link{setCurrentDb}}) #' #' @param dbg if TRUE, a message obout setting the current database is printed +#' @importFrom kwb.utils catIf #' currentDb <- function(dbg = TRUE) { @@ -90,7 +91,8 @@ readSqlCommandsFromFile <- function(sqlScript) #' the database file with dots substituted with underscores #' @param create_target_dir if \code{TRUE}, the target directory \code{tdir} #' is created if it does not exist. -#' +#' @importFrom kwb.utils warningDeprecated +#' hsDumpMdb <- function( mdb, ptrn = "^tbl", tdir = file.path(dirname(mdb), gsub("\\.", "_", basename(mdb))), @@ -125,6 +127,8 @@ hsDumpMdb <- function( #' @param qmethod passed to \code{\link[utils]{write.table}} #' @param row.names passed to \code{\link[utils]{write.table}} #' @param \dots further arguments passed to \code{\link[utils]{write.table}} +#' @importFrom kwb.utils createDirectory safePath +#' @importFrom utils write.table #' dumpDatabase <- function( db, pattern = "^tbl", target_dir = NULL, create_target_dir = FALSE, @@ -229,6 +233,7 @@ lookupRecord <- function( #' list(field1 = "value1", field2 = "value2"). #' @param idField name of ID field, default: name of first table field #' @param dbg if TRUE, debug messages are shown +#' @importFrom kwb.utils hsQuoteChr #' hsLookupOrAddRecord <- function ( mdb, tbl, keyAssigns, fieldAssigns = NULL, idField = hsFields(mdb, tbl)[1], @@ -435,7 +440,10 @@ hsSetForeignKey <- function( #' #' @seealso \code{\link{hsMdbTimeSeries}, \link{hsGetTable}, #' \link{hsSqlExTsFields}} -#' +#' @importFrom kwb.utils catIf +#' @importFrom kwb.datetime hsToPosix +#' +#' @export #' @examples #' \dontrun{ #' ## Get flow time series of 24 of July 2011 from tbl_Hyd in example database @@ -562,7 +570,9 @@ hsGetTimeSeries <- function( #' zone) and value columns as selected in #' #' @seealso \code{\link{hsGetTimeSeries}, \link{hsGetTable}} -#' +#' @importFrom kwb.utils printIf +#' @importFrom utils head +#' @export #' @examples #' \dontrun{ #' ## Get flow time series of 24 of August 2011 from tbl_Hyd in example database @@ -661,9 +671,11 @@ hsMdbTimeSeries <- function( #' @param isPtrn if TRUE, \emph{tbl} is interpreted as a regular expression #' matching the names of the tables to be deleted. #' @param dbg if TRUE, debug messages are shown -#' +#' #' @seealso \code{\link{hsClearTable}} -#' +#' @importFrom kwb.utils catIf +#' @export +#' hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) { existingTables <- hsTables(mdb, namesOnly = TRUE) @@ -802,7 +814,8 @@ selectFromDb <- function( #' anything. #' #' @seealso \code{\link{hsPutTable}, \link{hsGetTable}} -#' +#' @importFrom kwb.utils catIf +#' @export #' @examples #' \dontrun{ #' ## Get Q time series from table "tbl_Hyd" in example database @@ -890,6 +903,7 @@ hsSqlQuery <- function( #' = 2 #' #' @references \url{http://msdn.microsoft.com/en-us/library/office/aa140022\%28v=office.10\%29.aspx} +#' @importFrom kwb.utils windowsPath #' connectionStringAccess <- function( mdb, uid = "", pwd = "", globalPartialBulkOps = 0 @@ -936,6 +950,7 @@ getSqlDialect <- function(db, use2007Driver = NULL) #' Set Current SQL Dialect #' #' @param dialectName one of "msaccess", "mysql" +#' @export #' setCurrentSqlDialect <- function(dialectName) { @@ -949,6 +964,8 @@ setCurrentSqlDialect <- function(dialectName) #' @param warn if TRUE and if no current SQL dialog is stored in the options, #' the program stops with an error message #' @param dbg if TRUE, a message about the current SQL dialect is printed +#' @importFrom kwb.utils catIf +#' @export #' getCurrentSqlDialect <- function(warn = TRUE, dbg = FALSE) { diff --git a/R/schema.R b/R/schema.R index 0254484..d62e7ba 100644 --- a/R/schema.R +++ b/R/schema.R @@ -99,6 +99,8 @@ getDatabaseSchema <- function(db) # .getFieldSchema -------------------------------------------------------------- +#' @importFrom kwb.utils isNullOrEmpty hsQuoteChr +#' .getFieldSchema <- function(db, tableName, fieldName, sqlDialect) { sql <- sprintf( @@ -190,6 +192,7 @@ safeTableName <- function( #' #' @return Returns "int", "double", "text", "date_time" or "boolean" depending #' on the data type of \emph{x} +#' @importFrom utils str #' getTypeIdentifier <- function(x) { diff --git a/R/server_specifics.R b/R/server_specifics.R index 841fadd..1f17174 100644 --- a/R/server_specifics.R +++ b/R/server_specifics.R @@ -67,7 +67,9 @@ #' @param datetime Date (and time) information in forms of Date object or POSIX #' object or string. #' @param dbg if TRUE, debug messages are shown -#' +#' @importFrom kwb.utils catIf +#' @importFrom kwb.datetime hsToPosix +#' hsJetDate <- function(datetime, dbg = FALSE) { dFormat <- "%m/%d/%Y %H:%M:%S" # This is a date in MS Jet SQL syntax diff --git a/R/sql.R b/R/sql.R index f556918..c4dacfa 100644 --- a/R/sql.R +++ b/R/sql.R @@ -42,6 +42,7 @@ keyValuesToSqlAssignment <- function(keyValues) #' @param keyvalues list of \code{key = value pairs} #' #' @return list with elements \emph{fieldList} and \emph{valueList} +#' @importFrom kwb.utils commaCollapsed #' keyValuesToSqlAssignment2 <- function(keyvalues) { @@ -74,7 +75,7 @@ keyValuesToSqlFilter <- function(keyValues, like = FALSE) #' @param filter logical. If \code{TRUE} the target is an SQL filter expression, #' otherwise an SQL SET expression. #' @param like passed to \code{\link{keyValueToSql}} -#' +#' @export #' @examples #' keyValues <- list(name = "Peter", birth = as.POSIXct("1999-09-09")) #' @@ -119,7 +120,8 @@ keyValuesToSql <- function(keyValues, filter, like = filter) #' an SQL assignment expression #' #' @return (vector of) character representing an SQL expression -#' +#' @importFrom kwb.utils commaCollapsed +#' @export #' @examples #' cat(kwb.db:::keyValueToSql("age", 1)) #' cat(kwb.db:::keyValueToSql("name", "peter")) @@ -167,6 +169,8 @@ valueToSqlOperator <- function(x, like, filter) # singleValueToSql ------------------------------------------------------------- +#' @importFrom kwb.utils hsQuoteChr +#' singleValueToSql <- function(x) { stopifnot(length(x) < 2) @@ -209,7 +213,8 @@ singleValueToSql <- function(x) #' #' @return vector of character strings each of which represents one row in #' \code{newData} -#' +#' @importFrom kwb.utils commaCollapsed +#' @export #' @examples #' x <- data.frame( #' name = c("Peter", "Paul"), @@ -252,7 +257,7 @@ dataFrameToSqlTuples <- function(newData) #' #' @return vector of character strings each of which represents one assignment #' in \code{x} -#' +#' @export #' @examples #' x <- list(name = "Peter", birthday = as.POSIXct("1981-12-13")) #' diff --git a/R/sql_expressions.R b/R/sql_expressions.R index c79c1ce..ba9866d 100644 --- a/R/sql_expressions.R +++ b/R/sql_expressions.R @@ -12,7 +12,7 @@ #' element of \emph{x}. #' #' @seealso \code{\link{hsSqlExAnd}} -#' +#' @export #' @examples #' ## Build SQL query finding records in table t in which at least #' ## one of the table fields f1 to f100 is NULL. @@ -45,7 +45,7 @@ hsSqlExOr <- function(x, bFunc = "") #' element of \emph{x}. #' #' @seealso \code{\link{hsSqlExOr}} -#' +#' @export #' @examples #' ## Build SQL query finding records in table t in which all #' ## of the table fields f1 to f100 are NULL. @@ -176,7 +176,7 @@ sqlDateExpression <- function(dateObject, sqlDialect, dbg = FALSE) #' @return Returns SQL code for grouping timestamps by years, months or days #' #' @seealso \code{\link{hsSqlExTimeCond}} -#' +#' @export #' @examples #' ## Show SQL query that gets the number of datasets per #' ## day ("d") considering the condition "Q > 0" @@ -233,7 +233,7 @@ hsSqlExTimeGroup <- function(tbl, tsField, interval, cond = "TRUE") #' the time stamp. #' #' @seealso \code{\link{hsGetTimeSeries}} -#' +#' @export #' @examples #' hsSqlExTsFields("myTimestamp", c(6:11)) #' diff --git a/R/sql_join.R b/R/sql_join.R index ca83b70..cf5ed21 100644 --- a/R/sql_join.R +++ b/R/sql_join.R @@ -9,7 +9,7 @@ #' #' @return vector of character of length one representing the result of "left #' join"-ing all sub-queries given in \code{sqls} -#' +#' @export #' @examples #' sql <- sqlFullLeftJoin(key = "id", list( #' structure("SELECT id, field_1 from table_1", alias = "t1"), @@ -31,7 +31,7 @@ sqlFullLeftJoin <- function(sqls, key) condition <- sprintf("%s.%s = %s.%s", left_alias, key, right_alias, key) - full_sql <- kwb.db::sqlLeftJoinExpression(full_sql, sql, condition) + full_sql <- sqlLeftJoinExpression(full_sql, sql, condition) } full_sql @@ -100,6 +100,7 @@ sqlLeftJoinBody <- function( #' @param left left part of JOIN (e.g. table name) #' @param right right part of JOIN (e.g. table name) #' @param condition condition +#' @export #' sqlLeftJoinExpression <- function(left, right, condition) { diff --git a/R/sql_top_level.R b/R/sql_top_level.R index 984fb23..ddad22f 100644 --- a/R/sql_top_level.R +++ b/R/sql_top_level.R @@ -10,6 +10,7 @@ #' @param groupBy GROUP BY-clause, Default: "" (no grouping) #' @param orderBy ORDER BY-clause, Default: "" (no sorting of results) #' @param sqlDialect one of \code{c("mysql", "msaccess")} +#' @export #' sqlForSelect <- function( tablename, fields = "*", whereClause = "TRUE", groupBy = "", orderBy = "", diff --git a/man/renamesToFieldList.Rd b/man/renamesToFieldList.Rd index 642b5e9..48ad710 100644 --- a/man/renamesToFieldList.Rd +++ b/man/renamesToFieldList.Rd @@ -19,5 +19,5 @@ enclosed in square brackets: \code{ AS [target]}} } \description{ Convert a list of renamings to a field selection string that can be used as -\code{fields} argument in a call to \code{kwb.db::hsGetTable} +\code{fields} argument in a call to \code{\link[kwb.db]{hsGetTable}} } From c9ad9cb05e5164d351d2abf4ea7e720337cdabc8 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 16:40:29 +0200 Subject: [PATCH 06/28] Move RODBC from "Imports" to "Depends" - let Roxygen import RODBC functions explicitly - improve indenting --- DESCRIPTION | 4 ++-- NAMESPACE | 12 ++++++++++++ R/base.R | 3 +++ R/connect.R | 15 +++++++++++---- R/logical.R | 2 ++ R/main.R | 2 ++ 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 56b36e0..1efc95f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,10 +24,10 @@ Authors@R: comment = "0000-0003-0647-7726"), person(given = "Kompetenzzentrum Wasser Berlin gGmbH", role = "cph")) -Imports: RODBC Depends: kwb.datetime, - kwb.utils + kwb.utils, + RODBC Suggests: testthat Remotes: diff --git a/NAMESPACE b/NAMESPACE index 9edf691..99dd1c7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,18 @@ export(setCurrentSqlDialect) export(sqlForSelect) export(sqlFullLeftJoin) export(sqlLeftJoinExpression) +importFrom(RODBC,odbcClose) +importFrom(RODBC,odbcConnect) +importFrom(RODBC,odbcConnectAccess) +importFrom(RODBC,odbcConnectAccess2007) +importFrom(RODBC,odbcConnectExcel) +importFrom(RODBC,odbcConnectExcel2007) +importFrom(RODBC,odbcDataSources) +importFrom(RODBC,sqlColumns) +importFrom(RODBC,sqlDrop) +importFrom(RODBC,sqlQuery) +importFrom(RODBC,sqlSave) +importFrom(RODBC,sqlTables) importFrom(kwb.datetime,hsToPosix) importFrom(kwb.utils,catAndRun) importFrom(kwb.utils,catIf) diff --git a/R/base.R b/R/base.R index ba5862f..a61837c 100644 --- a/R/base.R +++ b/R/base.R @@ -23,6 +23,7 @@ #' #' @seealso \code{\link{hsSqlQuery}, \link{hsGetTable}} #' @importFrom kwb.utils hsSafeName +#' @importFrom RODBC sqlSave #' @export #' @examples #' \dontrun{ @@ -304,6 +305,7 @@ hsGetTable <- function( #' #' @seealso \code{\link{hsFields}} #' @importFrom kwb.utils catIf +#' @importFrom RODBC sqlTables #' @export #' @examples #' \dontrun{ @@ -387,6 +389,7 @@ hsTables <- function( #' the database fields in detail, otherwise. #' #' @seealso \code{\link{hsTables}} +#' @importFrom RODBC sqlColumns #' @export #' @examples #' \dontrun{ diff --git a/R/connect.R b/R/connect.R index cdfceb2..7d8d7a7 100644 --- a/R/connect.R +++ b/R/connect.R @@ -120,6 +120,7 @@ hsOpenDb <- function( #' @param \dots further arguments passed to \code{odbcConnectionAccess}, #' \code{odbcConnectionExcel} or \code{\link[RODBC]{odbcConnect}} #' @importFrom kwb.utils catIf +#' @importFrom RODBC odbcConnect odbcDataSources #' openAdequateConnectionOrStop <- function( db, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... @@ -140,17 +141,18 @@ openAdequateConnectionOrStop <- function( if (is_mdb) { con <- odbcConnectionAccess( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... + ) } else if (is_xls) { con <- odbcConnectionExcel( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ...) + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... + ) } else if (isOdbcDataSource(db)) { - con <- RODBC::odbcConnect( - db, DBMSencoding = DBMSencoding, ...) + con <- RODBC::odbcConnect(db, DBMSencoding = DBMSencoding, ...) } else { @@ -167,6 +169,8 @@ openAdequateConnectionOrStop <- function( # odbcConnectionAccess --------------------------------------------------------- +#' @importFrom RODBC odbcConnectAccess2007 odbcConnectAccess +#' odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) { if (is.null(use2007Driver)) { @@ -186,6 +190,8 @@ odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) # odbcConnectionExcel ---------------------------------------------------------- +#' @importFrom RODBC odbcConnectExcel2007 odbcConnectExcel +#' odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) { if (is.null(use2007Driver)) { @@ -227,6 +233,7 @@ hsCloseMdb <- function(con) #' \link{hsOpenDb}/\code{odbcConnect} #' #' @seealso \code{\link{hsOpenDb}} +#' @importFrom RODBC odbcClose #' hsCloseDb <- function(con) { diff --git a/R/logical.R b/R/logical.R index 7760d4d..9a735fa 100644 --- a/R/logical.R +++ b/R/logical.R @@ -96,6 +96,8 @@ isMySQL <- function(db, ...) # isOdbcDataSource ------------------------------------------------------------- +#' @importFrom RODBC odbcDataSources +#' isOdbcDataSource <- function(db) { db %in% names(RODBC::odbcDataSources()) diff --git a/R/main.R b/R/main.R index f6dd6cd..ac25c23 100644 --- a/R/main.R +++ b/R/main.R @@ -674,6 +674,7 @@ hsMdbTimeSeries <- function( #' #' @seealso \code{\link{hsClearTable}} #' @importFrom kwb.utils catIf +#' @importFrom RODBC sqlDrop #' @export #' hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) @@ -815,6 +816,7 @@ selectFromDb <- function( #' #' @seealso \code{\link{hsPutTable}, \link{hsGetTable}} #' @importFrom kwb.utils catIf +#' @importFrom RODBC sqlQuery #' @export #' @examples #' \dontrun{ From bde15dc20c519577645d25065a97f71d33f2f4e1 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 19:39:33 +0200 Subject: [PATCH 07/28] Start to use functions from odbc32 hsOpenDb() - check for 64 bit version, the connection objects returned by odbc32-functions look different from those returned by the RODBC functions openAdequateConnectionOrStop() - return() early instead of nested if-else odbcConnectionAccess() - call start_server() and run odbcConnectAccess2007() from the odbc32 package if we are using the 64 bit version of R --- DESCRIPTION | 1 + NAMESPACE | 2 ++ R/connect.R | 100 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1efc95f..fad2fb0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Authors@R: Depends: kwb.datetime, kwb.utils, + odbc32, RODBC Suggests: testthat diff --git a/NAMESPACE b/NAMESPACE index 99dd1c7..9dce7b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,6 +50,8 @@ importFrom(kwb.utils,printIf) importFrom(kwb.utils,safePath) importFrom(kwb.utils,warningDeprecated) importFrom(kwb.utils,windowsPath) +importFrom(odbc32,odbcClose) +importFrom(odbc32,odbcConnectAccess2007) importFrom(stats,setNames) importFrom(utils,head) importFrom(utils,str) diff --git a/R/connect.R b/R/connect.R index 7d8d7a7..e3ad76c 100644 --- a/R/connect.R +++ b/R/connect.R @@ -93,7 +93,7 @@ hsOpenDb <- function( ) ## Return if connection failed - if (con == -1) { + if (! is64BitR() && con == -1) { stop("Could not connect to database: ", src) } @@ -101,7 +101,13 @@ hsOpenDb <- function( ## in debug mode, print connection kwb.utils::printIf(dbg, con, "Connection") - setCurrentSqlDialect(ifelse(attr(con, "isMySQL"), "mysql", "msaccess")) + is_mysql <- if (! is64BitR()) { + attr(con, "isMySQL") + } else { + message("Do not know how to check if this is a MySQL connection") + } + + setCurrentSqlDialect(ifelse(is_mysql, "mysql", "msaccess")) con } @@ -138,38 +144,30 @@ openAdequateConnectionOrStop <- function( stop("No such file: '", db, "'! Please check the path!", call. = FALSE) } - if (is_mdb) { - - con <- odbcConnectionAccess( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... - ) - - } else if (is_xls) { - - con <- odbcConnectionExcel( - db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... - ) - - } else if (isOdbcDataSource(db)) { - - con <- RODBC::odbcConnect(db, DBMSencoding = DBMSencoding, ...) - - } else { - - odbcSources <- names(RODBC::odbcDataSources()) - - stop( - "src must be a file name with extension .mdb, .accdb, .xls, .xlsx ", - "or the name of an existing ODBC data source. ", - "Available ODBC data sources are:\n * ", - paste(odbcSources, collapse = ",\n * ") - ) - } + if (is_mdb) return(odbcConnectionAccess( + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... + )) + + if (is_xls) return(odbcConnectionExcel( + db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... + )) + + if (isOdbcDataSource(db)) return(RODBC::odbcConnect( + db, DBMSencoding = DBMSencoding, ... + )) + + stop( + "src must be a file name with extension .mdb, .accdb, .xls, .xlsx ", + "or the name of an existing ODBC data source. ", + "Available ODBC data sources are:\n * ", + paste(names(RODBC::odbcDataSources()), collapse = ",\n * ") + ) } # odbcConnectionAccess --------------------------------------------------------- #' @importFrom RODBC odbcConnectAccess2007 odbcConnectAccess +#' @importFrom odbc32 odbcConnectAccess2007 #' odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) { @@ -178,13 +176,33 @@ odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) use2007Driver <- isAccess2007File(db) } - if (use2007Driver) { + # Select the appropriate package + pkg <- ifelse(is64BitR(), "odbc32", "RODBC") + + # Select the appropriate function name + name <- ifelse(use2007Driver, "odbcConnectAccess2007", "odbcConnectAccess") + + if (is64BitR()) { + + if (! use2007Driver) stop( + "Cannot connect to ", db, " with 64 Bit-Version of R!", call. = FALSE + ) + + socket <- .GlobalEnv$.r2r_socket + + if (is.null(socket)) { + socket <- odbc32::start_server() + } - RODBC::odbcConnectAccess2007(db, ...) + odbc32::odbcConnectAccess2007(db, socket = socket) } else { - RODBC::odbcConnectAccess(db, ...) + if (use2007Driver){ + RODBC::odbcConnectAccess2007(db, ...) + } else { + RODBC::odbcConnectAccess(db, ...) + } } } @@ -234,11 +252,25 @@ hsCloseMdb <- function(con) #' #' @seealso \code{\link{hsOpenDb}} #' @importFrom RODBC odbcClose +#' @importFrom odbc32 odbcClose #' hsCloseDb <- function(con) { ## Close database connection - RODBC::odbcClose(con) - + if (is64BitR()) { + + odbc32::odbcClose(con) + + socket <- .GlobalEnv$.r2r_socket + + if (! is.null(socket)) { + odbc32::stop_server(socket = socket) + } + + } else { + + RODBC::odbcClose(con) + } + #options("kwb.db.current.sql.dialect" = NULL) } From 603551973837e86706690bb1add660bb1ff512c6 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 19:47:47 +0200 Subject: [PATCH 08/28] Remove global socket handle in hsCloseDb() - set "invisible = TRUE" in start_server() --- R/connect.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index e3ad76c..d0e0b64 100644 --- a/R/connect.R +++ b/R/connect.R @@ -191,7 +191,7 @@ odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) socket <- .GlobalEnv$.r2r_socket if (is.null(socket)) { - socket <- odbc32::start_server() + socket <- odbc32::start_server(invisible = TRUE) } odbc32::odbcConnectAccess2007(db, socket = socket) @@ -265,6 +265,7 @@ hsCloseDb <- function(con) if (! is.null(socket)) { odbc32::stop_server(socket = socket) + rm(".r2r_socket", envir = .GlobalEnv) } } else { From 230d9b5abf99016108b12dbbcdc88bb6fae666d7 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 6 Jun 2019 19:48:43 +0200 Subject: [PATCH 09/28] Use odbc32::sqlTables() in case of 64 bit R --- R/base.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/base.R b/R/base.R index a61837c..7f395a9 100644 --- a/R/base.R +++ b/R/base.R @@ -347,19 +347,20 @@ hsTables <- function( setCurrentSqlDialect(sqlDialect) }) - tblList <- RODBC::sqlTables(con) + tblList <- if (is64BitR()) { + odbc32::sqlTables(con) + } else { + RODBC::sqlTables(con) + } - if (excludeSystemTables) - + if (excludeSystemTables) { tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] - + } + if (namesOnly) { - - return(tblList$TABLE_NAME) - + tblList$TABLE_NAME } else { - - return(tblList) + tblList } } From 598b76567264e2aad7bf1108f4ec67ddab768da6 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 09:55:40 +0200 Subject: [PATCH 10/28] Add arg "con" to isMySQL() If there is already an open connection, try to read the attribute "isMySQL" Use try() around hsOpenDb() --- R/logical.R | 22 +++++++++++++++++++--- man/isMySQL.Rd | 5 ++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/R/logical.R b/R/logical.R index 9a735fa..219c8af 100644 --- a/R/logical.R +++ b/R/logical.R @@ -77,20 +77,36 @@ isExcelFile <- function(filepath) #' database #' @param \dots arguments passed to \code{\link{hsOpenDb}}, e.g. #' \emph{use2007Driver} -#' +#' @param con connection object as returned by \code{\link{hsOpenDb}}, if +#' already available. Default: \code{NULL} #' @return TRUE if \emph{db} is a MySQL database, else FALSE #' -isMySQL <- function(db, ...) +isMySQL <- function(db, ..., con = NULL) { + # If a connection is given and if it has an attribute "isMySQL", return the + # value of that attribute + if (! is.null(con) && ! is.null(is_mysql <- attr(con, "isMySQL"))) { + return(is_mysql) + } + + # Otherwise try to check by extension + if (isExcelFile(db) || isAccessFile(db)) { + return(FALSE) + } + sqlDialect <- getCurrentSqlDialect(warn = FALSE) - connection <- hsOpenDb(db, ...) + connection <- try(hsOpenDb(db, ...)) on.exit({ hsCloseDb(connection) setCurrentSqlDialect(sqlDialect) }) + if (inherits(connection, "try-error")) clean_stop(sprintf( + "Cannot open '%s' to check if this is a MySQL database!", db + )) + attr(connection, "isMySQL") } diff --git a/man/isMySQL.Rd b/man/isMySQL.Rd index 1f7a90e..3b951d2 100644 --- a/man/isMySQL.Rd +++ b/man/isMySQL.Rd @@ -4,7 +4,7 @@ \alias{isMySQL} \title{Is the Given Database of Type MySQL?} \usage{ -isMySQL(db, ...) +isMySQL(db, ..., con = NULL) } \arguments{ \item{db}{database file (*.mdb, *.accdb, *.xls, *.xlsx) or name of ODBC @@ -12,6 +12,9 @@ database} \item{\dots}{arguments passed to \code{\link{hsOpenDb}}, e.g. \emph{use2007Driver}} + +\item{con}{connection object as returned by \code{\link{hsOpenDb}}, if +already available. Default: \code{NULL}} } \value{ TRUE if \emph{db} is a MySQL database, else FALSE From 563dde55a71380efb1f78e8a9e8150f2bff14139 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 09:56:52 +0200 Subject: [PATCH 11/28] Add utility function clean_stop() --- R/utils.R | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 R/utils.R diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..44b721f --- /dev/null +++ b/R/utils.R @@ -0,0 +1,5 @@ +# clean_stop ------------------------------------------------------------------- +clean_stop <- function(...) +{ + stop(call. = FALSE, ...) +} From 79799babaeb1b72bbee52293342b08f296fc4928 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 09:57:36 +0200 Subject: [PATCH 12/28] Add further 64 Bit support --- NAMESPACE | 2 + NEWS | 6 +++ R/connect.R | 143 +++++++++++++++++++++++++++------------------------- R/main.R | 32 ++++++++---- 4 files changed, 104 insertions(+), 79 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 9dce7b1..5aa344c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,7 @@ importFrom(kwb.utils,catAndRun) importFrom(kwb.utils,catIf) importFrom(kwb.utils,commaCollapsed) importFrom(kwb.utils,createDirectory) +importFrom(kwb.utils,defaultIfNULL) importFrom(kwb.utils,hsQuoteChr) importFrom(kwb.utils,hsSafeName) importFrom(kwb.utils,hsTrim) @@ -52,6 +53,7 @@ importFrom(kwb.utils,warningDeprecated) importFrom(kwb.utils,windowsPath) importFrom(odbc32,odbcClose) importFrom(odbc32,odbcConnectAccess2007) +importFrom(odbc32,sqlQuery) importFrom(stats,setNames) importFrom(utils,head) importFrom(utils,str) diff --git a/NEWS b/NEWS index c796aea..3645f4a 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +2019-06-07 +- give a warning when using deprecated functions hsOpenMdb(), hsCloseMdb() + +2019-06-06 +- support 64 Bit in odbcConnectionAccess() + Changes in kwb.db 0.1.1 ========================= * xmdb now points to example database in this package not in kwb.base diff --git a/R/connect.R b/R/connect.R index d0e0b64..e47c225 100644 --- a/R/connect.R +++ b/R/connect.R @@ -11,7 +11,8 @@ #' hsOpenMdb <- function(mdb, dbg = FALSE) { - kwb.utils::warningDeprecated("kwb.db::hsOpenMdb", "kwb.db::hsOpenDb") + kwb.utils::warningDeprecated("kwb.db:::hsOpenMdb", "kwb.db:::hsOpenDb") + hsOpenDb(mdb, dbg) } @@ -76,16 +77,14 @@ hsOpenDb <- function( { kwb.utils::catIf(dbg, "in hsOpenDb: use2007Driver =", use2007Driver, "\n") - if (missing(src) || length(src) == 0) { - - stop("No source file (*.mdb, *.accdb, *.xls or *.xlsx) ", - "or name of ODBC data source given.") - } + if (missing(src) || length(src) == 0) stop( + "No source file (*.mdb, *.accdb, *.xls or *.xlsx) or name of ODBC data ", + "source given." + ) - if (mode(src) != "character" || length(src) > 1) { - - stop("src must be a character vector of length one.") - } + if (mode(src) != "character" || length(src) > 1) stop( + "src must be a character vector of length one." + ) ## Open database connection con <- openAdequateConnectionOrStop( @@ -93,20 +92,15 @@ hsOpenDb <- function( ) ## Return if connection failed - if (! is64BitR() && con == -1) { - - stop("Could not connect to database: ", src) - } - + if (! is64BitR() && con == -1) stop( + "Could not connect to database: ", src + ) + ## in debug mode, print connection kwb.utils::printIf(dbg, con, "Connection") - is_mysql <- if (! is64BitR()) { - attr(con, "isMySQL") - } else { - message("Do not know how to check if this is a MySQL connection") - } - + is_mysql <- isMySQL(src, con = con) + setCurrentSqlDialect(ifelse(is_mysql, "mysql", "msaccess")) con @@ -139,11 +133,10 @@ openAdequateConnectionOrStop <- function( is_mdb <- isAccessFile(db) is_xls <- isExcelFile(db) - if ((is_mdb || is_xls) &&! file.exists(db)) { - - stop("No such file: '", db, "'! Please check the path!", call. = FALSE) - } - + if ((is_mdb || is_xls) &&! file.exists(db)) clean_stop( + "No such file: '", db, "'! Please check the path!" + ) + if (is_mdb) return(odbcConnectionAccess( db, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... )) @@ -156,7 +149,7 @@ openAdequateConnectionOrStop <- function( db, DBMSencoding = DBMSencoding, ... )) - stop( + clean_stop( "src must be a file name with extension .mdb, .accdb, .xls, .xlsx ", "or the name of an existing ODBC data source. ", "Available ODBC data sources are:\n * ", @@ -166,65 +159,78 @@ openAdequateConnectionOrStop <- function( # odbcConnectionAccess --------------------------------------------------------- -#' @importFrom RODBC odbcConnectAccess2007 odbcConnectAccess -#' @importFrom odbc32 odbcConnectAccess2007 +#' @importFrom kwb.utils defaultIfNULL #' odbcConnectionAccess <- function(db, use2007Driver = NULL, ...) { - if (is.null(use2007Driver)) { - - use2007Driver <- isAccess2007File(db) - } - - # Select the appropriate package - pkg <- ifelse(is64BitR(), "odbc32", "RODBC") - - # Select the appropriate function name - name <- ifelse(use2007Driver, "odbcConnectAccess2007", "odbcConnectAccess") + use2007Driver <- kwb.utils::defaultIfNULL(use2007Driver, isAccess2007File(db)) if (is64BitR()) { - - if (! use2007Driver) stop( - "Cannot connect to ", db, " with 64 Bit-Version of R!", call. = FALSE - ) - - socket <- .GlobalEnv$.r2r_socket - - if (is.null(socket)) { - socket <- odbc32::start_server(invisible = TRUE) - } - - odbc32::odbcConnectAccess2007(db, socket = socket) - + odbcConnectionAccess64(db, use2007Driver) } else { - - if (use2007Driver){ - RODBC::odbcConnectAccess2007(db, ...) - } else { - RODBC::odbcConnectAccess(db, ...) - } + odbcConnectionAccess32(db, use2007Driver, ...) } } # odbcConnectionExcel ---------------------------------------------------------- -#' @importFrom RODBC odbcConnectExcel2007 odbcConnectExcel +#' @importFrom kwb.utils defaultIfNULL #' odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) { - if (is.null(use2007Driver)) { - - use2007Driver <- isExcel2007File(db) + use2007Driver <- kwb.utils::defaultIfNULL(use2007Driver, isExcel2007File(db)) + + if (is64BitR()) { + clean_stop("odbcConnectionExcel() is not implemented for 64 Bit!") + } else { + odbcConnectionExcel32(db, use2007Driver, ...) + } +} + +# odbcConnectionAccess32 ------------------------------------------------------- + +#' @importFrom RODBC odbcConnectAccess2007 odbcConnectAccess +#' +odbcConnectionAccess32 <- function(db, use2007Driver, ...) +{ + FUN <- if (use2007Driver){ + RODBC::odbcConnectAccess2007 + } else { + RODBC::odbcConnectAccess } - if (use2007Driver) { - - RODBC::odbcConnectExcel2007(db, ...) - + FUN(db, ...) +} + +# odbcConnectionExcel32 -------------------------------------------------------- + +#' @importFrom RODBC odbcConnectExcel2007 odbcConnectExcel +#' +odbcConnectionExcel32 <- function(db, use2007Driver, ...) +{ + FUN <- if (use2007Driver) { + RODBC::odbcConnectExcel2007 } else { - - RODBC::odbcConnectExcel(db, ...) + RODBC::odbcConnectExcel } + + FUN(db, ...) +} + +# odbcConnectionAccess64 ------------------------------------------------------- + +#' @importFrom odbc32 odbcConnectAccess2007 +#' +odbcConnectionAccess64 <- function(db, use2007Driver) +{ + if (! use2007Driver) clean_stop( + "Cannot connect to ", db, " with 64 Bit-Version of R!" + ) + + odbc32::odbcConnectAccess2007(db, socket = kwb.utils::defaultIfNULL( + x = .GlobalEnv$.r2r_socket, + default = odbc32::start_server(invisible = TRUE) + )) } # hsCloseMdb ------------------------------------------------------------------- @@ -238,6 +244,7 @@ odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) #' hsCloseMdb <- function(con) { + kwb.utils::warningDeprecated("kwb.db:::hsCloseMdb", "kwb.db:::hsCloseDb") hsCloseDb(con) } diff --git a/R/main.R b/R/main.R index ac25c23..a430bf4 100644 --- a/R/main.R +++ b/R/main.R @@ -682,11 +682,8 @@ hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) existingTables <- hsTables(mdb, namesOnly = TRUE) tbls <- if (isPtrn) { - grep(tbl, existingTables, value = TRUE) - } else { - tbl } @@ -698,12 +695,15 @@ hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) if (tbl %in% existingTables) { - kwb.utils::catIf(dbg, sprintf("Dropping table '%s'... ", tbl)) - RODBC::sqlDrop(con, tbl) - kwb.utils::catIf(dbg, "ok.\n") - + kwb.utils::catAndRun(dbg = dbg, sprintf("Dropping table '%s'", tbl), { + RODBC::sqlDrop(con, tbl) + }) + } else { - cat("Table '", tbl, "' does not exist in database. No need to drop.\n") + + cat(sprintf( + "Table '%s' does not exist in database. No need to drop.\n", tbl + )) } } } @@ -817,6 +817,7 @@ selectFromDb <- function( #' @seealso \code{\link{hsPutTable}, \link{hsGetTable}} #' @importFrom kwb.utils catIf #' @importFrom RODBC sqlQuery +#' @importFrom odbc32 sqlQuery #' @export #' @examples #' \dontrun{ @@ -861,15 +862,24 @@ hsSqlQuery <- function( ## Send SQL query kwb.utils::catIf(dbg, sprintf("\nRunning SQL: %s\n\n", sql)) - res <- RODBC::sqlQuery(con, sql, ...) + + res <- if (is64BitR()) { + odbc32::sqlQuery(con, sql, ...) + } else { + RODBC::sqlQuery(con, sql, ...) + } # Did an error occur? if ((class(res) == "character") && (length(res) > 0)) { + msg <- paste(res, collapse = "\n") + if (stopOnError) { + stop(msg) - } - else { + + } else { + warning(msg) return (NULL) } From 3bf083a0a25580a3cc0868e30344670d626fc39e Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 14:58:15 +0200 Subject: [PATCH 13/28] Import packages instead of Depending on them! --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fad2fb0..feb10a7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ Authors@R: comment = "0000-0003-0647-7726"), person(given = "Kompetenzzentrum Wasser Berlin gGmbH", role = "cph")) -Depends: +Imports: kwb.datetime, kwb.utils, odbc32, From 24da15a7b459dcac60897a37fafb1e2b27e231a2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 15:01:40 +0200 Subject: [PATCH 14/28] Re-export functions (that are used in RScripts) - find names of used functions with kwb.fakin::get_package_function_usage() - do not use Roxygen's importFrom for functions that have the same names in RODBC and odbc32. Otherwise there are warnings. Recommendation by Hadley Wickham (found on StackOverflow) --- NAMESPACE | 25 ++++++++++++++++++++----- R/connect.R | 5 +---- R/convert.R | 1 + R/logical.R | 1 + R/main.R | 11 +++++++++-- R/sql.R | 2 ++ R/sql_join.R | 1 + R/sql_top_level.R | 4 ++++ R/to_R_interface.R | 2 ++ 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 5aa344c..7f65325 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,14 +1,21 @@ # Generated by roxygen2: do not edit by hand +export(createRDatabaseInterface) +export(currentDb) export(dataFrameToSqlTuples) export(getCurrentSqlDialect) export(getNamedExcelRanges) +export(hsClearTable) +export(hsCloseMdb) export(hsDropTable) export(hsFields) export(hsGetTable) export(hsGetTimeSeries) +export(hsLookupOrAddRecord) export(hsMdbTimeSeries) export(hsPutTable) +export(hsSetForeignKey) +export(hsSetPrimaryKey) export(hsSqlExAnd) export(hsSqlExOr) export(hsSqlExTimeGroup) @@ -16,15 +23,27 @@ export(hsSqlExTsFields) export(hsSqlQuery) export(hsTables) export(isExcelFile) +export(isMySQL) export(keyValueToSql) export(keyValuesToSql) +export(keyValuesToSqlAssignment) +export(keyValuesToSqlAssignment2) export(listValuesToSql) +export(lookupRecord) export(renamesToFieldList) +export(renamesToQueries) +export(selectFromTable) +export(setCurrentDb) export(setCurrentSqlDialect) +export(sqlForInsert) +export(sqlForInsertDataFrame) +export(sqlForInsertFromSelect) +export(sqlForInsertIgnoreInMsAccess) export(sqlForSelect) export(sqlFullLeftJoin) +export(sqlJoinExpression) export(sqlLeftJoinExpression) -importFrom(RODBC,odbcClose) +export(xmdb) importFrom(RODBC,odbcConnect) importFrom(RODBC,odbcConnectAccess) importFrom(RODBC,odbcConnectAccess2007) @@ -33,7 +52,6 @@ importFrom(RODBC,odbcConnectExcel2007) importFrom(RODBC,odbcDataSources) importFrom(RODBC,sqlColumns) importFrom(RODBC,sqlDrop) -importFrom(RODBC,sqlQuery) importFrom(RODBC,sqlSave) importFrom(RODBC,sqlTables) importFrom(kwb.datetime,hsToPosix) @@ -51,9 +69,6 @@ importFrom(kwb.utils,printIf) importFrom(kwb.utils,safePath) importFrom(kwb.utils,warningDeprecated) importFrom(kwb.utils,windowsPath) -importFrom(odbc32,odbcClose) -importFrom(odbc32,odbcConnectAccess2007) -importFrom(odbc32,sqlQuery) importFrom(stats,setNames) importFrom(utils,head) importFrom(utils,str) diff --git a/R/connect.R b/R/connect.R index e47c225..a18c23a 100644 --- a/R/connect.R +++ b/R/connect.R @@ -219,8 +219,6 @@ odbcConnectionExcel32 <- function(db, use2007Driver, ...) # odbcConnectionAccess64 ------------------------------------------------------- -#' @importFrom odbc32 odbcConnectAccess2007 -#' odbcConnectionAccess64 <- function(db, use2007Driver) { if (! use2007Driver) clean_stop( @@ -241,6 +239,7 @@ odbcConnectionAccess64 <- function(db, use2007Driver) #' #' @param con Open database connection as returned by #' \link{hsOpenMdb}/odbcConnect +#' @export #' hsCloseMdb <- function(con) { @@ -258,8 +257,6 @@ hsCloseMdb <- function(con) #' \link{hsOpenDb}/\code{odbcConnect} #' #' @seealso \code{\link{hsOpenDb}} -#' @importFrom RODBC odbcClose -#' @importFrom odbc32 odbcClose #' hsCloseDb <- function(con) { diff --git a/R/convert.R b/R/convert.R index 1b0e935..505104d 100644 --- a/R/convert.R +++ b/R/convert.R @@ -9,6 +9,7 @@ #' \code{key = value} pairs defining renamings from the keys to the values. #' #' @return list of character each of which represents an SQL query +#' @export #' renamesToQueries <- function(renamesList) { diff --git a/R/logical.R b/R/logical.R index 219c8af..23abea3 100644 --- a/R/logical.R +++ b/R/logical.R @@ -80,6 +80,7 @@ isExcelFile <- function(filepath) #' @param con connection object as returned by \code{\link{hsOpenDb}}, if #' already available. Default: \code{NULL} #' @return TRUE if \emph{db} is a MySQL database, else FALSE +#' @export #' isMySQL <- function(db, ..., con = NULL) { diff --git a/R/main.R b/R/main.R index a430bf4..02fcd71 100644 --- a/R/main.R +++ b/R/main.R @@ -3,6 +3,7 @@ #' Set Current Database #' #' @param db full path to MS Access database or ODBC database name +#' @export #' setCurrentDb <- function(db) { @@ -18,6 +19,7 @@ setCurrentDb <- function(db) #' #' @param dbg if TRUE, a message obout setting the current database is printed #' @importFrom kwb.utils catIf +#' @export #' currentDb <- function(dbg = TRUE) { @@ -182,6 +184,7 @@ dumpDatabase <- function( #' @param idField name of ID field, default: name of first table field #' @param dbg if TRUE, debug messages are shown #' @param use2007Driver passed to \code{\link{isMySQL}} +#' @export #' lookupRecord <- function( db, tableName, keyAssignments, idField = hsFields(db, tableName)[1], @@ -234,6 +237,7 @@ lookupRecord <- function( #' @param idField name of ID field, default: name of first table field #' @param dbg if TRUE, debug messages are shown #' @importFrom kwb.utils hsQuoteChr +#' @export #' hsLookupOrAddRecord <- function ( mdb, tbl, keyAssigns, fieldAssigns = NULL, idField = hsFields(mdb, tbl)[1], @@ -333,6 +337,7 @@ hsTsField <- function(src, tbl, namesOnly = TRUE, all = FALSE) #' @param tbl Name of table in which key fields are to be defined. #' @param keyFields (Vector of) key field name(s) #' @param dbg if TRUE, debug messages are shown +#' @export #' hsSetPrimaryKey <- function(mdb, tbl, keyFields, dbg = FALSE) { @@ -375,6 +380,7 @@ hsSetPrimaryKey <- function(mdb, tbl, keyFields, dbg = FALSE) #' @param ref.field name of foreign key field in ref.tbl #' @param key.name optional. Name to be given to the foreign key #' @param dbg passed to \code{\link{hsSqlQuery}} +#' @export #' hsSetForeignKey <- function( mdb, tbl, field, ref.tbl, ref.field, @@ -722,6 +728,7 @@ hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) #' @param \dots additional arguments passed to hsSqlQuery, e.g. "errors=TRUE" #' #' @seealso \code{\link{hsDropTable}} +#' @export #' hsClearTable <- function(mdb, tbl, cond = TRUE, ...) { @@ -816,8 +823,6 @@ selectFromDb <- function( #' #' @seealso \code{\link{hsPutTable}, \link{hsGetTable}} #' @importFrom kwb.utils catIf -#' @importFrom RODBC sqlQuery -#' @importFrom odbc32 sqlQuery #' @export #' @examples #' \dontrun{ @@ -936,6 +941,8 @@ connectionStringAccess <- function( #' #' Returns full path to MS Access example database #' +#' @export +#' xmdb <- function() { system.file("extdata", "RExKwbBase.mdb", package = "kwb.db") diff --git a/R/sql.R b/R/sql.R index c4dacfa..e979879 100644 --- a/R/sql.R +++ b/R/sql.R @@ -29,6 +29,7 @@ #' List of Key = Value Pairs to SQL Assignment #' #' @param keyValues list of \code{key = value} pairs +#' @export #' keyValuesToSqlAssignment <- function(keyValues) { @@ -43,6 +44,7 @@ keyValuesToSqlAssignment <- function(keyValues) #' #' @return list with elements \emph{fieldList} and \emph{valueList} #' @importFrom kwb.utils commaCollapsed +#' @export #' keyValuesToSqlAssignment2 <- function(keyvalues) { diff --git a/R/sql_join.R b/R/sql_join.R index cf5ed21..37a14c6 100644 --- a/R/sql_join.R +++ b/R/sql_join.R @@ -115,6 +115,7 @@ sqlLeftJoinExpression <- function(left, right, condition) #' @param right right part of JOIN (e.g. table name) #' @param condition condition #' @param type one of c("LEFT", "RIGHT", "INNER") +#' @export #' sqlJoinExpression <- function(left, right, condition, type = "INNER") { diff --git a/R/sql_top_level.R b/R/sql_top_level.R index ddad22f..9a0bff5 100644 --- a/R/sql_top_level.R +++ b/R/sql_top_level.R @@ -74,6 +74,7 @@ sqlForSelectByKey <- function( #' @param table.source name of source table #' @param table.target name of target table #' @param uniqueFields names of unique fields +#' @export #' sqlForInsertIgnoreInMsAccess <- function( db, table.source, table.target, uniqueFields = NA @@ -131,6 +132,7 @@ sqlForInsertIgnoreInMsAccess <- function( #' @param ignore if TRUE the keyword IGNORE is inserted between INSERT and INTO #' in the SQL statement -> no error will be given if data to insert already #' exists +#' @export #' sqlForInsert <- function( tablename, fields, sqlSource, sourceAreValues = ! grepl(sqlSource, "^SELECT"), @@ -156,6 +158,7 @@ sqlForInsert <- function( #' @param target.table name of target table #' @param source.table name of source table or SQL providing source data #' @param fields vector of character with field names +#' @export #' sqlForInsertFromSelect <- function(target.table, source.table, fields) { @@ -179,6 +182,7 @@ sqlForInsertFromSelect <- function(target.table, source.table, fields) #' in the SQL statement -> no error will be given if data to insert already #' exists #' @param \dots further arguments passed to \code{\link{sqlForInsert}} +#' @export #' sqlForInsertDataFrame <- function(tablename, dataFrame, ignore = FALSE, ...) { diff --git a/R/to_R_interface.R b/R/to_R_interface.R index 80ecfbb..8054f85 100644 --- a/R/to_R_interface.R +++ b/R/to_R_interface.R @@ -38,6 +38,7 @@ #' interface functions #' @param sql.dbg if TRUE, SQL strings used to access the database are shown #' when calling the interface functions +#' @export #' createRDatabaseInterface <- function ( @@ -473,6 +474,7 @@ getFilteredRecords <- function(db, tableName, keyValues, fields, like, ...) #' @param run if TRUE (default) the SQL SELECT statement is run otherwise #' returned as character string #' @param \dots further arguments passed to \code{\link{hsSqlQuery}} +#' @export #' selectFromTable <- function(db, tableName, arguments, run = TRUE, ...) { From a5a52d478b8a77ee3990636d45bf1f31d2b7c615 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 15:25:47 +0200 Subject: [PATCH 15/28] Support 64 bit in hsPutTable() - use debug functions from kwb.utils --- R/base.R | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/R/base.R b/R/base.R index 7f395a9..8d6de7a 100644 --- a/R/base.R +++ b/R/base.R @@ -98,32 +98,33 @@ hsPutTable <- function( } } - if (dbg) { - cat("Given/generated field types:\n") - print(types) - cat(sprintf("Writing data to table '%s' in '%s'\n", tblSafe, mdb)) - } + kwb.utils::printIf( + dbg && ! is.null(types), types, "Given/generated field types" + ) - ## Save the data to the database table - if (is.null(types)) { - - res <- RODBC::sqlSave(con, myData, tblSafe, rownames = FALSE, verbose = dbg) - + # Provide arguments to sqlSave() + arguments <- list(con, myData, tblSafe, rownames = FALSE, verbose = dbg) + + if (! is.null(types)) { + arguments <- c(arguments, list(varTypes = types)) + } + + # Select the appropriate function + FUN <- if (is64BitR()) { + RODBC::sqlSave } else { - - if (dbg) { - - print(names(types)) - } - - res <- RODBC::sqlSave( - con, myData, tblSafe, varTypes = types, rownames = FALSE, verbose = dbg - ) + odbc32::sqlSave } + # Call the function that saves the data to the database table + result <- kwb.utils::catAndRun( + dbg = dbg, + messageText = sprintf("Writing data to table '%s' in '%s'\n", tblSafe, mdb), + expr = do.call(FUN, arguments) + ) + # Did an error occur? - if (res != 1) { - + if (result != 1) { stop("sqlSave returned with error.\n") } From b82ae50bf7f6be6bfd8b2373d63a2db1b67bc955 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 15:42:54 +0200 Subject: [PATCH 16/28] Reindent Description, add github remotes --- DESCRIPTION | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index feb10a7..04abc60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,18 @@ Package: kwb.db Version: 0.3.0.9000 Title: Functions supporting data base access -Description: This package contains some useful functions, especially for simplifying data transfer - between MS Access databases and R. With the functions of this package it is not needed - any more to open and close a database connection explicitely; this is done 'behind the - scenes' in the functions. Instead of a database connection the path to the database file - needs to be passed to the functions as an argument. The main functions are hsGetTable - and hsPutTable which transfer data from an MS Access database to a data frame in R and - save data from a data frame in R into a table in an MS Access database, respectively. - Take care when getting time series data from an MS Access database, see therefore - hsMdbTimeSeries. Use hsTables to get a list of tables that are available in a database - and hsFields to get a list of table fields that are contained in a database table. +Description: This package contains some useful functions, especially for + simplifying data transfer between MS Access databases and R. With the + functions of this package it is not needed any more to open and close a + database connection explicitely; this is done 'behind the scenes' in the + functions. Instead of a database connection the path to the database file + needs to be passed to the functions as an argument. The main functions are + hsGetTable and hsPutTable which transfer data from an MS Access database to + a data frame in R and save data from a data frame in R into a table in an MS + Access database, respectively. Take care when getting time series data from + an MS Access database, see therefore hsMdbTimeSeries. Use hsTables to get a + list of tables that are available in a database and hsFields to get a list + of table fields that are contained in a database table. Authors@R: c(person(given = "Hauke", family = "Sonnenberg", @@ -33,7 +35,8 @@ Suggests: testthat Remotes: github::kwb-r/kwb.datetime, - github::kwb-r/kwb.utils + github::kwb-r/kwb.utils, + github::vh-d/odbc32 Encoding: UTF-8 License: MIT + file LICENSE RoxygenNote: 6.1.1 From b3615a5e1f8a972e94d15b2a9cdf2da7c0c80bdc Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 15:43:38 +0200 Subject: [PATCH 17/28] Call the appropriate function in hsPutTable() --- R/base.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/R/base.R b/R/base.R index 8d6de7a..deb9230 100644 --- a/R/base.R +++ b/R/base.R @@ -84,16 +84,17 @@ hsPutTable <- function( if (is.null(types)) { - if (dbg) { - cat("No field types given.\n") - } - - if (! attr(con, "isMySQL")) { + kwb.utils::catIf(dbg, "No field types given.\n") + + if (! isMySQL(mdb, con = con)) { + for (colname in colnames(myData)) { + className <- class(myData[[colname]])[1] dbClassName <- .hsJetType(className) types <- c(types, dbClassName) } + names(types) <- colnames(myData) } } @@ -111,9 +112,9 @@ hsPutTable <- function( # Select the appropriate function FUN <- if (is64BitR()) { - RODBC::sqlSave - } else { odbc32::sqlSave + } else { + RODBC::sqlSave } # Call the function that saves the data to the database table From 51aef1b6e11d2ede4c9fa0f374f5290ace2d0c48 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 7 Jun 2019 15:51:59 +0200 Subject: [PATCH 18/28] Give error message (no 64 bit!) in hsFields() --- R/base.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/base.R b/R/base.R index deb9230..0f97546 100644 --- a/R/base.R +++ b/R/base.R @@ -424,14 +424,14 @@ hsFields <- function( if (missing(tbl)) { - stop("No table name given. ", msg) + clean_stop("No table name given. ", msg) } pattern <- paste("^", tbl, "$", sep = "") if (length(grep(pattern, tbls, ignore.case = ignore.case)) != 1) { - stop(sprintf('Table "%s" not found in %s. ', tbl, mdb), msg) + clean_stop(sprintf('Table "%s" not found in %s. ', tbl, mdb), msg) } sqlDialect <- getCurrentSqlDialect(warn = FALSE) @@ -448,7 +448,11 @@ hsFields <- function( tbl <- sub("\\$$", "", tbl) } - fieldInfo <- RODBC::sqlColumns(con, tbl) + fieldInfo <- if (kwb.db:::is64BitR()) { + clean_stop("Sorry. There is no equivalent to sqlColumns() in odbc32!") + } else { + RODBC::sqlColumns(con, tbl) + } if (namesOnly) { From f9ec19fd7492539e3f612998140505654c161b01 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 11 Jun 2019 12:20:59 +0200 Subject: [PATCH 19/28] Get odbc32 from hsonne (fixed dependencies) --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 04abc60..ab9c8ea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: Remotes: github::kwb-r/kwb.datetime, github::kwb-r/kwb.utils, - github::vh-d/odbc32 + github::hsonne/odbc32 Encoding: UTF-8 License: MIT + file LICENSE RoxygenNote: 6.1.1 From 1264786d3d86ac591f72d3aad22955ddfd573ffc Mon Sep 17 00:00:00 2001 From: Michael Rustler Date: Tue, 11 Jun 2019 13:13:34 +0200 Subject: [PATCH 20/28] Rollback to package author after he merged our pull request in master --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ab9c8ea..1259fad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: Remotes: github::kwb-r/kwb.datetime, github::kwb-r/kwb.utils, - github::hsonne/odbc32 + github::vh/odbc32 Encoding: UTF-8 License: MIT + file LICENSE RoxygenNote: 6.1.1 From 405d9003109285145502fa291b7d1c84b980a64d Mon Sep 17 00:00:00 2001 From: mrustl Date: Fri, 6 Sep 2019 15:50:21 +0200 Subject: [PATCH 21/28] Improve :book: deployment run kwb.pkgbuild::use_travis() and kwb.pkgbuild::use_appveyor --- .Rbuildignore | 3 +- .travis.yml | 35 +++++++++++++++---- LICENSE | 2 +- LICENSE.md | 2 +- README.Rmd | 96 --------------------------------------------------- README.md | 29 +++++++++------- appveyor.yml | 22 ++++++++++++ index.md | 56 ++++++++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 119 deletions(-) delete mode 100644 README.Rmd create mode 100644 index.md diff --git a/.Rbuildignore b/.Rbuildignore index 24a9ab4..9fac54a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,4 +8,5 @@ _pkgdown.yaml LICENSE\.md$ .gitlab-ci.yml -README\.Rmd$ +^index\.md$ +^\.travis\.yml$ diff --git a/.travis.yml b/.travis.yml index eed0afb..d306eb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,31 @@ +############################################################################## +### Autogenerated with R package kwb.pkgbuild v0.1.1 +### (installed from 'Github (kwb-r/kwb.pkgbuild@0ac3694)' source code on 2019-09-06) +### by calling the function kwb.pkgbuild::use_travis() +### (file created at: 2019-09-06 15:48:52) +############################################################################## + + language: r -r: - - oldrel - - release sudo: required +cache: packages r_packages: - - devtools - - covr -after_success: - - Rscript -e 'covr::codecov()' +- remotes +- covr +matrix: + include: + - r: devel + - r: release + after_success: + - Rscript -e 'covr::codecov()' + before_deploy: + - Rscript -e 'remotes::install_cran("pkgdown")' + deploy: + provider: script + script: Rscript -e 'pkgdown::deploy_site_github(verbose = TRUE)' + skip_cleanup: 'true' + on: + branch: + - master + - dev + - r: oldrel diff --git a/LICENSE b/LICENSE index 67c2565..f0fe8fd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB) +Copyright (c) 2014-2019 Kompetenzzentrum Wasser Berlin gGmbH (KWB) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.md b/LICENSE.md index 529cb03..9284dbd 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB) +Copyright (c) 2014-2019 Kompetenzzentrum Wasser Berlin gGmbH (KWB) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.Rmd b/README.Rmd deleted file mode 100644 index e7321f5..0000000 --- a/README.Rmd +++ /dev/null @@ -1,96 +0,0 @@ ---- -output: github_document ---- - - - -```{r, echo = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "README-" -) -``` - -[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) -[![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) -[![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) - - -# kwb.db - -This repository contains the R package kwb.db. The package provides functions -that aim at simplifying the data transfer between databases and R. It is based -on the [RODBC](https://cran.r-project.org/web/packages/RODBC/) package that -gives access to databases that provide an -[ODBC](https://docs.microsoft.com/en-us/sql/odbc/reference/what-is-odbc) -interface. Databases may be Microsoft Access files, Microsoft Excel files or -any other database that is registered as an ODBC data source on your local -machine. See e.g. -[here](https://docs.microsoft.com/en-us/sql/odbc/admin/odbc-data-source-administrator) -for how to setup ODBC data sources in Windows. - -## Installation - -Once you have the devtools package installed, you can install the package kwb.db -like this: - -```{r eval = FALSE} -# If required, install the devtools package... -# install.packages("devtools") - -# Install kwb.db (and dependent packages) from this GitHub repository -devtools::install(github("kwb-r/kwb.db", dependencies = TRUE) -``` - -## Database Access in RODBC - -With the RODBC package, you need to open a database connection, send one or more -requests to the database and finally close the dabase connection. - -## Database Access with this package - -With the functions of this package it is not needed to open and close a database -connection explicitly; this is done behind the scenes in the functions. Instead -of a database connection the path to the database file needs to be passed to the -functions as an argument. - -The main functions are -[`hsGetTable()`](https://kwb-r.github.io/kwb.db/reference/hsGetTable.html) and -[`hsPutTable()`](https://kwb-r.github.io/kwb.db/reference/hsPutTable.html). -They transfer data from a database to a data frame in R and save data from a -data frame in R into a new table in a database, respectively. - -Use [`hsTables()`](https://kwb-r.github.io/kwb.db/reference/hsTables.html) to -get a list of tables that are available in a database and [`hsFields()`](https://kwb-r.github.io/kwb.db/reference/hsFields.html) to get a -list of table fields that are contained in a database table. - -A general workflow could look like this: - -```{r eval = FALSE} -# Define the path to a MS Access datbase file -mdb <- "/path/to/your/database.mdb" - -# Have a look at what tables are contained in the database -(tables <- kwb.db::hsTables(mdb)) - -# For each table, get the vector of available fields (= columns) -lapply(tables, kwb.db::hsFields, mdb = mdb) - -# Get the content of the first table -data <- kwb.db::hsGetTable(mdb, tables[1]) - -# Do some modifiactions or create somehow else a new data frame -data_new <- do_some_fancy_stuff(data) - -# Save the new data frame as a new "fancy_table" in the database -kwb.db::hsPutTable(mdb, data_new, "fancy_table") -``` - -In each of the `kwb.db::`-function calls above a database connection is opened, -a request to the database is sent and the connection is closed again. Thus, the -user does not have to care about open database connections. - -Take care when getting time series data from an MS Access database, see -therefore -[`hsMdbTimeSeries()`](https://kwb-r.github.io/kwb.db/reference/hsMdbTimeSeries.html). diff --git a/README.md b/README.md index 97b4f31..2409edf 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,15 @@ +[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) +[![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) [![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) - -[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) [![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) [![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) - -kwb.db -====== +# kwb.db This repository contains the R package kwb.db. The package provides functions that aim at simplifying the data transfer between databases and R. It is based on the [RODBC](https://cran.r-project.org/web/packages/RODBC/) package that gives access to databases that provide an [ODBC](https://docs.microsoft.com/en-us/sql/odbc/reference/what-is-odbc) interface. Databases may be Microsoft Access files, Microsoft Excel files or any other database that is registered as an ODBC data source on your local machine. See e.g. [here](https://docs.microsoft.com/en-us/sql/odbc/admin/odbc-data-source-administrator) for how to setup ODBC data sources in Windows. -Installation ------------- +# Installation Once you have the devtools package installed, you can install the package kwb.db like this: -``` r +```r # If required, install the devtools package... # install.packages("devtools") @@ -20,13 +17,13 @@ Once you have the devtools package installed, you can install the package kwb.db devtools::install_github("kwb-r/kwb.db", dependencies = TRUE) ``` -Database Access in RODBC ------------------------- +## Database Access in RODBC + With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the dabase connection. -Database Access with this package ---------------------------------- +## Database Access with this package + With the functions of this package it is not needed to open and close a database connection explicitly; this is done behind the scenes in the functions. Instead of a database connection the path to the database file needs to be passed to the functions as an argument. @@ -36,7 +33,7 @@ Use [`hsTables()`](https://kwb-r.github.io/kwb.db/reference/hsTables.html) to ge A general workflow could look like this: -``` r +```r # Define the path to a MS Access datbase file mdb <- "/path/to/your/database.mdb" @@ -59,3 +56,9 @@ kwb.db::hsPutTable(mdb, data_new, "fancy_table") In each of the `kwb.db::`-function calls above a database connection is opened, a request to the database is sent and the connection is closed again. Thus, the user does not have to care about open database connections. Take care when getting time series data from an MS Access database, see therefore [`hsMdbTimeSeries()`](https://kwb-r.github.io/kwb.db/reference/hsMdbTimeSeries.html). + +# Documentation + +Release: [https://kwb-r.github.io/kwb.db](https://kwb-r.github.io/kwb.db) + +Development: [https://kwb-r.github.io/kwb.db/dev](https://kwb-r.github.io/kwb.db/dev) diff --git a/appveyor.yml b/appveyor.yml index c6c1438..2fef893 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,18 @@ +############################################################################## +### Autogenerated with R package kwb.pkgbuild v0.1.1 +### (installed from 'Github (kwb-r/kwb.pkgbuild@0ac3694)' source code on 2019-09-06) +### by calling the function kwb.pkgbuild::use_appveyor() +### (file created at: 2019-09-06 15:48:46) +############################################################################## + + + +### Configuration copied from: +### https://raw.githubusercontent.com/tidyverse/readxl/5649e2643d25bb5b6353797fc48bbcbb0eb72f6d/appveyor.yml" +### But in addition also use two environment variables: +### - USE_RTools = true(for details see: https://github.com/KWB-R/kwb.pkgbuild/issues/37) +### - R_REMOTES_STANDALONE = true (for details see: https://github.com/r-lib/remotes#standalone-mode, https://github.com/krlmlr/r-appveyor/issues/135) + # DO NOT CHANGE the "init" and "install" sections below # Download script file from GitHub @@ -15,6 +30,13 @@ cache: # Adapt as necessary starting from here +environment: +### Add RTools (for details see: https://github.com/KWB-R/kwb.pkgbuild/issues/37) + USE_RTOOLS: true +### Add R_REMOTES_STANDALONE(for details see: https://github.com/krlmlr/r-appveyor/issues/135 +### or https://github.com/r-lib/remotes#standalone-mode) + R_REMOTES_STANDALONE: true + build_script: - travis-tool.sh install_deps diff --git a/index.md b/index.md new file mode 100644 index 0000000..8610205 --- /dev/null +++ b/index.md @@ -0,0 +1,56 @@ +[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) +[![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) [![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) + +This repository contains the R package kwb.db. The package provides functions that aim at simplifying the data transfer between databases and R. It is based on the [RODBC](https://cran.r-project.org/web/packages/RODBC/) package that gives access to databases that provide an [ODBC](https://docs.microsoft.com/en-us/sql/odbc/reference/what-is-odbc) interface. Databases may be Microsoft Access files, Microsoft Excel files or any other database that is registered as an ODBC data source on your local machine. See e.g. [here](https://docs.microsoft.com/en-us/sql/odbc/admin/odbc-data-source-administrator) for how to setup ODBC data sources in Windows. + +# Installation + +Once you have the devtools package installed, you can install the package kwb.db like this: + +```r +# If required, install the devtools package... +# install.packages("devtools") + +# Install kwb.db (and dependent packages) from this GitHub repository +devtools::install_github("kwb-r/kwb.db", dependencies = TRUE) +``` + +## Database Access in RODBC + + +With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the dabase connection. + +## Database Access with this package + + +With the functions of this package it is not needed to open and close a database connection explicitly; this is done behind the scenes in the functions. Instead of a database connection the path to the database file needs to be passed to the functions as an argument. + +The main functions are [`hsGetTable()`](https://kwb-r.github.io/kwb.db/reference/hsGetTable.html) and [`hsPutTable()`](https://kwb-r.github.io/kwb.db/reference/hsPutTable.html). They transfer data from a database to a data frame in R and save data from a data frame in R into a new table in a database, respectively. + +Use [`hsTables()`](https://kwb-r.github.io/kwb.db/reference/hsTables.html) to get a list of tables that are available in a database and [`hsFields()`](https://kwb-r.github.io/kwb.db/reference/hsFields.html) to get a list of table fields that are contained in a database table. + +A general workflow could look like this: + +```r +# Define the path to a MS Access datbase file +mdb <- "/path/to/your/database.mdb" + +# Have a look at what tables are contained in the database +(tables <- kwb.db::hsTables(mdb)) + +# For each table, get the vector of available fields (= columns) +lapply(tables, kwb.db::hsFields, mdb = mdb) + +# Get the content of the first table +data <- kwb.db::hsGetTable(mdb, tables[1]) + +# Do some modifiactions or create somehow else a new data frame +data_new <- do_some_fancy_stuff(data) + +# Save the new data frame as a new "fancy_table" in the database +kwb.db::hsPutTable(mdb, data_new, "fancy_table") +``` + +In each of the `kwb.db::`-function calls above a database connection is opened, a request to the database is sent and the connection is closed again. Thus, the user does not have to care about open database connections. + +Take care when getting time series data from an MS Access database, see therefore [`hsMdbTimeSeries()`](https://kwb-r.github.io/kwb.db/reference/hsMdbTimeSeries.html). From 72fcd4b1d8098bffc62f7f1f4aca591c94b306f1 Mon Sep 17 00:00:00 2001 From: mrustl Date: Mon, 9 Sep 2019 08:38:10 +0200 Subject: [PATCH 22/28] docs: deleted as now deployed from gh-pages --- docs/LICENSE-text.html | 173 ------ docs/LICENSE.html | 158 ----- docs/authors.html | 161 ----- docs/dev/LICENSE-text.html | 143 ----- docs/dev/LICENSE.html | 128 ---- docs/dev/authors.html | 131 ---- docs/dev/docsearch.css | 145 ----- docs/dev/index.html | 183 ------ docs/dev/jquery.sticky-kit.min.js | 11 - docs/dev/link.svg | 12 - docs/dev/pkgdown.css | 227 ------- docs/dev/pkgdown.js | 174 ------ docs/dev/pkgdown.yml | 5 - .../dev/reference/connectionStringAccess.html | 177 ------ .../reference/createRDatabaseInterface.html | 198 ------ docs/dev/reference/currentDb.html | 150 ----- docs/dev/reference/dataFrameToSqlTuples.html | 169 ----- docs/dev/reference/dumpDatabase.html | 188 ------ docs/dev/reference/getCurrentSqlDialect.html | 153 ----- docs/dev/reference/getDatabaseSchema.html | 156 ----- docs/dev/reference/getFilteredRecords.html | 171 ------ docs/dev/reference/getNamedExcelRanges.html | 174 ------ docs/dev/reference/getSqlDialect.html | 152 ----- docs/dev/reference/getTypeIdentifier.html | 155 ----- docs/dev/reference/get_namedExcelRanges.html | 174 ------ docs/dev/reference/hsClearTable.html | 170 ------ docs/dev/reference/hsCloseDb.html | 155 ----- docs/dev/reference/hsCloseMdb.html | 149 ----- docs/dev/reference/hsDropTable.html | 171 ------ docs/dev/reference/hsDumpMdb.html | 165 ----- docs/dev/reference/hsFields.html | 212 ------- docs/dev/reference/hsGetTable.html | 273 --------- docs/dev/reference/hsGetTimeSeries.html | 284 --------- docs/dev/reference/hsJetDate.html | 153 ----- docs/dev/reference/hsLookupOrAddRecord.html | 177 ------ docs/dev/reference/hsMdbTimeSeries.html | 256 -------- docs/dev/reference/hsOpenDb.html | 219 ------- docs/dev/reference/hsOpenMdb.html | 153 ----- docs/dev/reference/hsPutTable.html | 230 ------- docs/dev/reference/hsSetForeignKey.html | 176 ------ docs/dev/reference/hsSetPrimaryKey.html | 162 ----- docs/dev/reference/hsSqlExAnd.html | 180 ------ docs/dev/reference/hsSqlExOr.html | 180 ------ docs/dev/reference/hsSqlExTimeCond.html | 221 ------- docs/dev/reference/hsSqlExTimeGroup.html | 189 ------ docs/dev/reference/hsSqlExTsFields.html | 184 ------ docs/dev/reference/hsSqlQuery.html | 226 ------- docs/dev/reference/hsTables.html | 215 ------- docs/dev/reference/hsTsField.html | 162 ----- docs/dev/reference/index.html | 568 ----------------- docs/dev/reference/isExcel2003File.html | 155 ----- docs/dev/reference/isExcel2007File.html | 155 ----- docs/dev/reference/isExcelFile.html | 155 ----- docs/dev/reference/isMySQL.html | 160 ----- docs/dev/reference/keyValueToSql.html | 173 ------ docs/dev/reference/keyValuesToSql.html | 167 ----- .../reference/keyValuesToSqlAssignment.html | 148 ----- .../reference/keyValuesToSqlAssignment2.html | 154 ----- docs/dev/reference/keyValuesToSqlFilter.html | 153 ----- docs/dev/reference/listValuesToSql.html | 166 ----- docs/dev/reference/lookupRecord.html | 173 ------ .../openAdequateConnectionOrStop.html | 169 ----- docs/dev/reference/printDatabaseSchema.html | 149 ----- .../reference/rcode_DatabaseInterface.html | 186 ------ .../reference/readSqlCommandsFromFile.html | 150 ----- docs/dev/reference/renamesToFieldList.html | 162 ----- docs/dev/reference/renamesToQueries.html | 157 ----- .../dev/reference/runSqlCommandsFromFile.html | 156 ----- docs/dev/reference/safeTableName.html | 154 ----- docs/dev/reference/selectFromDb.html | 169 ----- docs/dev/reference/selectFromTable.html | 167 ----- docs/dev/reference/setCurrentDb.html | 148 ----- docs/dev/reference/setCurrentSqlDialect.html | 148 ----- docs/dev/reference/sqlForInsert.html | 171 ------ docs/dev/reference/sqlForInsertDataFrame.html | 162 ----- .../dev/reference/sqlForInsertFromSelect.html | 158 ----- .../sqlForInsertIgnoreInMsAccess.html | 163 ----- docs/dev/reference/sqlForSelect.html | 171 ------ docs/dev/reference/sqlForSelectByKey.html | 159 ----- docs/dev/reference/sqlForUpdate.html | 163 ----- docs/dev/reference/sqlFullLeftJoin.html | 176 ------ docs/dev/reference/sqlJoinExpression.html | 160 ----- docs/dev/reference/sqlLeftJoin.html | 158 ----- docs/dev/reference/sqlLeftJoinBody.html | 172 ------ docs/dev/reference/sqlLeftJoinExpression.html | 156 ----- docs/dev/reference/xmdb.html | 138 ----- docs/docsearch.css | 148 ----- docs/docsearch.js | 85 --- docs/docsearch.json | 94 --- docs/index.html | 204 ------- docs/link.svg | 12 - docs/pkgdown.css | 232 ------- docs/pkgdown.js | 110 ---- docs/pkgdown.yml | 5 - docs/reference/connectionStringAccess.html | 207 ------- docs/reference/createRDatabaseInterface.html | 228 ------- docs/reference/currentDb.html | 180 ------ docs/reference/dataFrameToSqlTuples.html | 199 ------ docs/reference/getCurrentSqlDialect.html | 183 ------ docs/reference/getDatabaseSchema.html | 186 ------ docs/reference/getFilteredRecords.html | 201 ------ docs/reference/getSqlDialect.html | 182 ------ docs/reference/getTypeIdentifier.html | 185 ------ docs/reference/hsClearTable.html | 200 ------ docs/reference/hsCloseDb.html | 185 ------ docs/reference/hsCloseMdb.html | 179 ------ docs/reference/hsDropTable.html | 201 ------ docs/reference/hsDumpMdb.html | 192 ------ docs/reference/hsFields.html | 242 -------- docs/reference/hsGetTable.html | 303 --------- docs/reference/hsGetTimeSeries.html | 314 ---------- docs/reference/hsJetDate.html | 183 ------ docs/reference/hsLookupOrAddRecord.html | 207 ------- docs/reference/hsMdbTimeSeries.html | 286 --------- docs/reference/hsOpenDb.html | 249 -------- docs/reference/hsOpenMdb.html | 183 ------ docs/reference/hsPutTable.html | 260 -------- docs/reference/hsSetForeignKey.html | 206 ------- docs/reference/hsSetPrimaryKey.html | 192 ------ docs/reference/hsSqlExAnd.html | 210 ------- docs/reference/hsSqlExOr.html | 210 ------- docs/reference/hsSqlExTimeCond.html | 251 -------- docs/reference/hsSqlExTimeGroup.html | 219 ------- docs/reference/hsSqlExTsFields.html | 214 ------- docs/reference/hsSqlQuery.html | 256 -------- docs/reference/hsTables.html | 245 -------- docs/reference/hsTsField.html | 192 ------ docs/reference/index.html | 575 ------------------ docs/reference/isExcel2003File.html | 185 ------ docs/reference/isExcel2007File.html | 185 ------ docs/reference/isExcelFile.html | 185 ------ docs/reference/isMySQL.html | 190 ------ docs/reference/keyValueToSql.html | 203 ------- docs/reference/keyValuesToSql.html | 197 ------ docs/reference/keyValuesToSqlAssignment.html | 178 ------ docs/reference/keyValuesToSqlAssignment2.html | 184 ------ docs/reference/keyValuesToSqlFilter.html | 183 ------ docs/reference/listValuesToSql.html | 196 ------ docs/reference/lookupRecord.html | 203 ------- .../openAdequateConnectionOrStop.html | 199 ------ docs/reference/printDatabaseSchema.html | 179 ------ docs/reference/rcode_DatabaseInterface.html | 216 ------- docs/reference/readSqlCommandsFromFile.html | 180 ------ docs/reference/renamesToFieldList.html | 192 ------ docs/reference/runSqlCommandsFromFile.html | 186 ------ docs/reference/safeTableName.html | 184 ------ docs/reference/selectFromDb.html | 199 ------ docs/reference/selectFromTable.html | 197 ------ docs/reference/setCurrentDb.html | 178 ------ docs/reference/setCurrentSqlDialect.html | 178 ------ docs/reference/sqlForInsert.html | 201 ------ docs/reference/sqlForInsertDataFrame.html | 192 ------ docs/reference/sqlForInsertFromSelect.html | 188 ------ .../sqlForInsertIgnoreInMsAccess.html | 193 ------ docs/reference/sqlForSelect.html | 201 ------ docs/reference/sqlForSelectByKey.html | 189 ------ docs/reference/sqlForUpdate.html | 193 ------ docs/reference/sqlJoinExpression.html | 190 ------ docs/reference/sqlLeftJoin.html | 188 ------ docs/reference/sqlLeftJoinBody.html | 202 ------ docs/reference/sqlLeftJoinExpression.html | 186 ------ docs/reference/xmdb.html | 168 ----- 162 files changed, 29742 deletions(-) delete mode 100644 docs/LICENSE-text.html delete mode 100644 docs/LICENSE.html delete mode 100644 docs/authors.html delete mode 100644 docs/dev/LICENSE-text.html delete mode 100644 docs/dev/LICENSE.html delete mode 100644 docs/dev/authors.html delete mode 100644 docs/dev/docsearch.css delete mode 100644 docs/dev/index.html delete mode 100644 docs/dev/jquery.sticky-kit.min.js delete mode 100644 docs/dev/link.svg delete mode 100644 docs/dev/pkgdown.css delete mode 100644 docs/dev/pkgdown.js delete mode 100644 docs/dev/pkgdown.yml delete mode 100644 docs/dev/reference/connectionStringAccess.html delete mode 100644 docs/dev/reference/createRDatabaseInterface.html delete mode 100644 docs/dev/reference/currentDb.html delete mode 100644 docs/dev/reference/dataFrameToSqlTuples.html delete mode 100644 docs/dev/reference/dumpDatabase.html delete mode 100644 docs/dev/reference/getCurrentSqlDialect.html delete mode 100644 docs/dev/reference/getDatabaseSchema.html delete mode 100644 docs/dev/reference/getFilteredRecords.html delete mode 100644 docs/dev/reference/getNamedExcelRanges.html delete mode 100644 docs/dev/reference/getSqlDialect.html delete mode 100644 docs/dev/reference/getTypeIdentifier.html delete mode 100644 docs/dev/reference/get_namedExcelRanges.html delete mode 100644 docs/dev/reference/hsClearTable.html delete mode 100644 docs/dev/reference/hsCloseDb.html delete mode 100644 docs/dev/reference/hsCloseMdb.html delete mode 100644 docs/dev/reference/hsDropTable.html delete mode 100644 docs/dev/reference/hsDumpMdb.html delete mode 100644 docs/dev/reference/hsFields.html delete mode 100644 docs/dev/reference/hsGetTable.html delete mode 100644 docs/dev/reference/hsGetTimeSeries.html delete mode 100644 docs/dev/reference/hsJetDate.html delete mode 100644 docs/dev/reference/hsLookupOrAddRecord.html delete mode 100644 docs/dev/reference/hsMdbTimeSeries.html delete mode 100644 docs/dev/reference/hsOpenDb.html delete mode 100644 docs/dev/reference/hsOpenMdb.html delete mode 100644 docs/dev/reference/hsPutTable.html delete mode 100644 docs/dev/reference/hsSetForeignKey.html delete mode 100644 docs/dev/reference/hsSetPrimaryKey.html delete mode 100644 docs/dev/reference/hsSqlExAnd.html delete mode 100644 docs/dev/reference/hsSqlExOr.html delete mode 100644 docs/dev/reference/hsSqlExTimeCond.html delete mode 100644 docs/dev/reference/hsSqlExTimeGroup.html delete mode 100644 docs/dev/reference/hsSqlExTsFields.html delete mode 100644 docs/dev/reference/hsSqlQuery.html delete mode 100644 docs/dev/reference/hsTables.html delete mode 100644 docs/dev/reference/hsTsField.html delete mode 100644 docs/dev/reference/index.html delete mode 100644 docs/dev/reference/isExcel2003File.html delete mode 100644 docs/dev/reference/isExcel2007File.html delete mode 100644 docs/dev/reference/isExcelFile.html delete mode 100644 docs/dev/reference/isMySQL.html delete mode 100644 docs/dev/reference/keyValueToSql.html delete mode 100644 docs/dev/reference/keyValuesToSql.html delete mode 100644 docs/dev/reference/keyValuesToSqlAssignment.html delete mode 100644 docs/dev/reference/keyValuesToSqlAssignment2.html delete mode 100644 docs/dev/reference/keyValuesToSqlFilter.html delete mode 100644 docs/dev/reference/listValuesToSql.html delete mode 100644 docs/dev/reference/lookupRecord.html delete mode 100644 docs/dev/reference/openAdequateConnectionOrStop.html delete mode 100644 docs/dev/reference/printDatabaseSchema.html delete mode 100644 docs/dev/reference/rcode_DatabaseInterface.html delete mode 100644 docs/dev/reference/readSqlCommandsFromFile.html delete mode 100644 docs/dev/reference/renamesToFieldList.html delete mode 100644 docs/dev/reference/renamesToQueries.html delete mode 100644 docs/dev/reference/runSqlCommandsFromFile.html delete mode 100644 docs/dev/reference/safeTableName.html delete mode 100644 docs/dev/reference/selectFromDb.html delete mode 100644 docs/dev/reference/selectFromTable.html delete mode 100644 docs/dev/reference/setCurrentDb.html delete mode 100644 docs/dev/reference/setCurrentSqlDialect.html delete mode 100644 docs/dev/reference/sqlForInsert.html delete mode 100644 docs/dev/reference/sqlForInsertDataFrame.html delete mode 100644 docs/dev/reference/sqlForInsertFromSelect.html delete mode 100644 docs/dev/reference/sqlForInsertIgnoreInMsAccess.html delete mode 100644 docs/dev/reference/sqlForSelect.html delete mode 100644 docs/dev/reference/sqlForSelectByKey.html delete mode 100644 docs/dev/reference/sqlForUpdate.html delete mode 100644 docs/dev/reference/sqlFullLeftJoin.html delete mode 100644 docs/dev/reference/sqlJoinExpression.html delete mode 100644 docs/dev/reference/sqlLeftJoin.html delete mode 100644 docs/dev/reference/sqlLeftJoinBody.html delete mode 100644 docs/dev/reference/sqlLeftJoinExpression.html delete mode 100644 docs/dev/reference/xmdb.html delete mode 100644 docs/docsearch.css delete mode 100644 docs/docsearch.js delete mode 100644 docs/docsearch.json delete mode 100644 docs/index.html delete mode 100644 docs/link.svg delete mode 100644 docs/pkgdown.css delete mode 100644 docs/pkgdown.js delete mode 100644 docs/pkgdown.yml delete mode 100644 docs/reference/connectionStringAccess.html delete mode 100644 docs/reference/createRDatabaseInterface.html delete mode 100644 docs/reference/currentDb.html delete mode 100644 docs/reference/dataFrameToSqlTuples.html delete mode 100644 docs/reference/getCurrentSqlDialect.html delete mode 100644 docs/reference/getDatabaseSchema.html delete mode 100644 docs/reference/getFilteredRecords.html delete mode 100644 docs/reference/getSqlDialect.html delete mode 100644 docs/reference/getTypeIdentifier.html delete mode 100644 docs/reference/hsClearTable.html delete mode 100644 docs/reference/hsCloseDb.html delete mode 100644 docs/reference/hsCloseMdb.html delete mode 100644 docs/reference/hsDropTable.html delete mode 100644 docs/reference/hsDumpMdb.html delete mode 100644 docs/reference/hsFields.html delete mode 100644 docs/reference/hsGetTable.html delete mode 100644 docs/reference/hsGetTimeSeries.html delete mode 100644 docs/reference/hsJetDate.html delete mode 100644 docs/reference/hsLookupOrAddRecord.html delete mode 100644 docs/reference/hsMdbTimeSeries.html delete mode 100644 docs/reference/hsOpenDb.html delete mode 100644 docs/reference/hsOpenMdb.html delete mode 100644 docs/reference/hsPutTable.html delete mode 100644 docs/reference/hsSetForeignKey.html delete mode 100644 docs/reference/hsSetPrimaryKey.html delete mode 100644 docs/reference/hsSqlExAnd.html delete mode 100644 docs/reference/hsSqlExOr.html delete mode 100644 docs/reference/hsSqlExTimeCond.html delete mode 100644 docs/reference/hsSqlExTimeGroup.html delete mode 100644 docs/reference/hsSqlExTsFields.html delete mode 100644 docs/reference/hsSqlQuery.html delete mode 100644 docs/reference/hsTables.html delete mode 100644 docs/reference/hsTsField.html delete mode 100644 docs/reference/index.html delete mode 100644 docs/reference/isExcel2003File.html delete mode 100644 docs/reference/isExcel2007File.html delete mode 100644 docs/reference/isExcelFile.html delete mode 100644 docs/reference/isMySQL.html delete mode 100644 docs/reference/keyValueToSql.html delete mode 100644 docs/reference/keyValuesToSql.html delete mode 100644 docs/reference/keyValuesToSqlAssignment.html delete mode 100644 docs/reference/keyValuesToSqlAssignment2.html delete mode 100644 docs/reference/keyValuesToSqlFilter.html delete mode 100644 docs/reference/listValuesToSql.html delete mode 100644 docs/reference/lookupRecord.html delete mode 100644 docs/reference/openAdequateConnectionOrStop.html delete mode 100644 docs/reference/printDatabaseSchema.html delete mode 100644 docs/reference/rcode_DatabaseInterface.html delete mode 100644 docs/reference/readSqlCommandsFromFile.html delete mode 100644 docs/reference/renamesToFieldList.html delete mode 100644 docs/reference/runSqlCommandsFromFile.html delete mode 100644 docs/reference/safeTableName.html delete mode 100644 docs/reference/selectFromDb.html delete mode 100644 docs/reference/selectFromTable.html delete mode 100644 docs/reference/setCurrentDb.html delete mode 100644 docs/reference/setCurrentSqlDialect.html delete mode 100644 docs/reference/sqlForInsert.html delete mode 100644 docs/reference/sqlForInsertDataFrame.html delete mode 100644 docs/reference/sqlForInsertFromSelect.html delete mode 100644 docs/reference/sqlForInsertIgnoreInMsAccess.html delete mode 100644 docs/reference/sqlForSelect.html delete mode 100644 docs/reference/sqlForSelectByKey.html delete mode 100644 docs/reference/sqlForUpdate.html delete mode 100644 docs/reference/sqlJoinExpression.html delete mode 100644 docs/reference/sqlLeftJoin.html delete mode 100644 docs/reference/sqlLeftJoinBody.html delete mode 100644 docs/reference/sqlLeftJoinExpression.html delete mode 100644 docs/reference/xmdb.html diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html deleted file mode 100644 index 9d95110..0000000 --- a/docs/LICENSE-text.html +++ /dev/null @@ -1,173 +0,0 @@ - - - - - - - - -License • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
MIT License
-
-Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - - - - diff --git a/docs/LICENSE.html b/docs/LICENSE.html deleted file mode 100644 index 4f1f8b5..0000000 --- a/docs/LICENSE.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - -MIT License • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
- -

Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB)

-

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

-

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

-

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - - - - diff --git a/docs/authors.html b/docs/authors.html deleted file mode 100644 index d92dd9a..0000000 --- a/docs/authors.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - -Authors • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
    -
  • -

    Hauke Sonnenberg. Author, maintainer. -

    -
  • -
  • -

    . Copyright holder. -

    -
  • -
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - - - - diff --git a/docs/dev/LICENSE-text.html b/docs/dev/LICENSE-text.html deleted file mode 100644 index 591361f..0000000 --- a/docs/dev/LICENSE-text.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - -License • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
MIT License
-
-Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - diff --git a/docs/dev/LICENSE.html b/docs/dev/LICENSE.html deleted file mode 100644 index cf6cce8..0000000 --- a/docs/dev/LICENSE.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - -MIT License • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
- -

Copyright (c) 2014-2018 Kompetenzzentrum Wasser Berlin gGmbH (KWB)

-

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

-

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

-

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - diff --git a/docs/dev/authors.html b/docs/dev/authors.html deleted file mode 100644 index b654b17..0000000 --- a/docs/dev/authors.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - -Authors • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- -
-
- - -
    -
  • -

    Hauke Sonnenberg. Author, maintainer. -

    -
  • -
  • -

    . Copyright holder. -

    -
  • -
- -
- -
- - -
- - -
-

Site built with pkgdown.

-
- -
-
- - - - - - diff --git a/docs/dev/docsearch.css b/docs/dev/docsearch.css deleted file mode 100644 index c524034..0000000 --- a/docs/dev/docsearch.css +++ /dev/null @@ -1,145 +0,0 @@ -/* Docsearch -------------------------------------------------------------- */ -/* - Source: https://github.com/algolia/docsearch/ - License: MIT -*/ - -.algolia-autocomplete { - display: block; - -webkit-box-flex: 1; - -ms-flex: 1; - flex: 1 -} - -.algolia-autocomplete .ds-dropdown-menu { - width: 100%; - min-width: none; - max-width: none; - padding: .75rem 0; - background-color: #fff; - background-clip: padding-box; - border: 1px solid rgba(0, 0, 0, .1); - box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); -} - -@media (min-width:768px) { - .algolia-autocomplete .ds-dropdown-menu { - width: 175% - } -} - -.algolia-autocomplete .ds-dropdown-menu::before { - display: none -} - -.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { - padding: 0; - background-color: rgb(255,255,255); - border: 0; - max-height: 80vh; -} - -.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { - margin-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion { - padding: 0; - overflow: visible -} - -.algolia-autocomplete .algolia-docsearch-suggestion--category-header { - padding: .125rem 1rem; - margin-top: 0; - font-size: 1.3em; - font-weight: 500; - color: #00008B; - border-bottom: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { - float: none; - padding-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { - float: none; - width: auto; - padding: 0; - text-align: left -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content { - float: none; - width: auto; - padding: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content::before { - display: none -} - -.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { - padding-top: .75rem; - margin-top: .75rem; - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { - display: block; - padding: .1rem 1rem; - margin-bottom: 0.1; - font-size: 1.0em; - font-weight: 400 - /* display: none */ -} - -.algolia-autocomplete .algolia-docsearch-suggestion--title { - display: block; - padding: .25rem 1rem; - margin-bottom: 0; - font-size: 0.9em; - font-weight: 400 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--text { - padding: 0 1rem .5rem; - margin-top: -.25rem; - font-size: 0.8em; - font-weight: 400; - line-height: 1.25 -} - -.algolia-autocomplete .algolia-docsearch-footer { - float: none; - width: auto; - height: auto; - padding: .75rem 1rem 0; - font-size: .95rem; - line-height: 1; - color: #767676; - background-color: rgb(255, 255, 255); - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .algolia-docsearch-footer--logo { - display: inline; - overflow: visible; - color: inherit; - text-indent: 0; - background: 0 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--highlight { - color: #FF8C00; - background: rgba(232, 189, 54, 0.1) -} - - -.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { - box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) -} - -.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { - background-color: rgba(192, 192, 192, .15) -} diff --git a/docs/dev/index.html b/docs/dev/index.html deleted file mode 100644 index 6d92f5b..0000000 --- a/docs/dev/index.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - -Functions supporting data base access • kwb.db - - - - - - - - - - -
-
- - - -
-
- - - - - - -
- -

This repository contains the R package kwb.db. The package provides functions that aim at simplifying the data transfer between databases and R. It is based on the RODBC package that gives access to databases that provide an ODBC interface. Databases may be Microsoft Access files, Microsoft Excel files or any other database that is registered as an ODBC data source on your local machine. See e.g. here for how to setup ODBC data sources in Windows.

-
-

-Installation

-

Once you have the devtools package installed, you can install the package kwb.db like this:

-
# If required, install the devtools package...
-# install.packages("devtools")
-
-# Install kwb.db (and dependent packages) from this GitHub repository
-devtools::install(github("kwb-r/kwb.db", dependencies = TRUE)
-
-
-

-Database Access in RODBC

-

With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the dabase connection.

-
-
-

-Database Access with this package

-

With the functions of this package it is not needed to open and close a database connection explicitly; this is done behind the scenes in the functions. Instead of a database connection the path to the database file needs to be passed to the functions as an argument.

-

The main functions are hsGetTable() and hsPutTable(). They transfer data from a database to a data frame in R and save data from a data frame in R into a new table in a database, respectively.

-

Use hsTables() to get a list of tables that are available in a database and hsFields() to get a list of table fields that are contained in a database table.

-

A general workflow could look like this:

-
# Define the path to a MS Access datbase file
-mdb <- "/path/to/your/database.mdb"
-
-# Have a look at what tables are contained in the database
-(tables <- kwb.db::hsTables(mdb))
-
-# For each table, get the vector of available fields (= columns)
-lapply(tables, kwb.db::hsFields, mdb = mdb)
-
-# Get the content of the first table
-data <- kwb.db::hsGetTable(mdb, tables[1])
-
-# Do some modifiactions or create somehow else a new data frame
-data_new <- do_some_fancy_stuff(data)
-
-# Save the new data frame as a new "fancy_table" in the database
-kwb.db::hsPutTable(mdb, data_new, "fancy_table")
-

In each of the kwb.db::-function calls above a database connection is opened, a request to the database is sent and the connection is closed again. Thus, the user does not have to care about open database connections.

-

Take care when getting time series data from an MS Access database, see therefore hsMdbTimeSeries().

-
-
-
- - - -
- - -
- -
-

Site built with pkgdown.

-
- -
-
- - - - - diff --git a/docs/dev/jquery.sticky-kit.min.js b/docs/dev/jquery.sticky-kit.min.js deleted file mode 100644 index 1c16271..0000000 --- a/docs/dev/jquery.sticky-kit.min.js +++ /dev/null @@ -1,11 +0,0 @@ -/* Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | */ -/* - Source: https://github.com/leafo/sticky-kit - License: MIT -*/ -(function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); -if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, -u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), -a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", -y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n - - - - - diff --git a/docs/dev/pkgdown.css b/docs/dev/pkgdown.css deleted file mode 100644 index c5ab586..0000000 --- a/docs/dev/pkgdown.css +++ /dev/null @@ -1,227 +0,0 @@ -/* Sticky footer */ - -/** - * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ - * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css - * - * .Site -> body > .container - * .Site-content -> body > .container .row - * .footer -> footer - * - * Key idea seems to be to ensure that .container and __all its parents__ - * have height set to 100% - * - */ - -html, body { - height: 100%; -} - -body > .container { - display: flex; - height: 100%; - flex-direction: column; - - padding-top: 60px; -} - -body > .container .row { - flex: 1 0 auto; -} - -footer { - margin-top: 45px; - padding: 35px 0 36px; - border-top: 1px solid #e5e5e5; - color: #666; - display: flex; - flex-shrink: 0; -} -footer p { - margin-bottom: 0; -} -footer div { - flex: 1; -} -footer .pkgdown { - text-align: right; -} -footer p { - margin-bottom: 0; -} - -img.icon { - float: right; -} - -img { - max-width: 100%; -} - -/* Typographic tweaking ---------------------------------*/ - -.contents h1.page-header { - margin-top: calc(-60px + 1em); -} - -/* Section anchors ---------------------------------*/ - -a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; - - background-image: url(./link.svg); - background-repeat: no-repeat; - background-size: 20px 20px; - background-position: center center; -} - -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } -} - - -/* Fixes for fixed navbar --------------------------*/ - -.contents h1, .contents h2, .contents h3, .contents h4 { - padding-top: 60px; - margin-top: -40px; -} - -/* Static header placement on mobile devices */ -@media (max-width: 767px) { - .navbar-fixed-top { - position: absolute; - } - .navbar { - padding: 0; - } -} - - -/* Sidebar --------------------------*/ - -#sidebar { - margin-top: 30px; -} -#sidebar h2 { - font-size: 1.5em; - margin-top: 1em; -} - -#sidebar h2:first-child { - margin-top: 0; -} - -#sidebar .list-unstyled li { - margin-bottom: 0.5em; -} - -.orcid { - height: 16px; - vertical-align: middle; -} - -/* Reference index & topics ----------------------------------------------- */ - -.ref-index th {font-weight: normal;} - -.ref-index td {vertical-align: top;} -.ref-index .alias {width: 40%;} -.ref-index .title {width: 60%;} - -.ref-index .alias {width: 40%;} -.ref-index .title {width: 60%;} - -.ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top;} -.ref-arguments .name {width: 20%;} -.ref-arguments .desc {width: 80%;} - -/* Nice scrolling for wide elements --------------------------------------- */ - -table { - display: block; - overflow: auto; -} - -/* Syntax highlighting ---------------------------------------------------- */ - -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { - background-color: #f8f8f8; - color: #333; -} - -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; -} - -pre .img { - margin: 5px 0; -} - -pre .img img { - background-color: #fff; - display: block; - height: auto; -} - -code a, pre a { - color: #375f84; -} - -a.sourceLine:hover { - text-decoration: none; -} - -.fl {color: #1514b5;} -.fu {color: #000000;} /* function */ -.ch,.st {color: #036a07;} /* string */ -.kw {color: #264D66;} /* keyword */ -.co {color: #888888;} /* comment */ - -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} - -/* Clipboard --------------------------*/ - -.hasCopyButton { - position: relative; -} - -.btn-copy-ex { - position: absolute; - right: 0; - top: 0; - visibility: hidden; -} - -.hasCopyButton:hover button.btn-copy-ex { - visibility: visible; -} - -/* mark.js ----------------------------*/ - -mark { - background-color: rgba(255, 255, 51, 0.5); - border-bottom: 2px solid rgba(255, 153, 51, 0.3); - padding: 1px; -} diff --git a/docs/dev/pkgdown.js b/docs/dev/pkgdown.js deleted file mode 100644 index 16d5750..0000000 --- a/docs/dev/pkgdown.js +++ /dev/null @@ -1,174 +0,0 @@ -$(function() { - - $("#sidebar") - .stick_in_parent({offset_top: 40}) - .on('sticky_kit:bottom', function(e) { - $(this).parent().css('position', 'static'); - }) - .on('sticky_kit:unbottom', function(e) { - $(this).parent().css('position', 'relative'); - }); - - $('body').scrollspy({ - target: '#sidebar', - offset: 60 - }); - - $('[data-toggle="tooltip"]').tooltip(); - - var cur_path = paths(location.pathname); - $("#navbar ul li a").each(function(index, value) { - if (value.text == "Home") - return; - if (value.getAttribute("href") === "#") - return; - - var path = paths(value.pathname); - if (is_prefix(cur_path, path)) { - // Add class to parent
  • , and enclosing
  • if in dropdown - var menu_anchor = $(value); - menu_anchor.parent().addClass("active"); - menu_anchor.closest("li.dropdown").addClass("active"); - } - }); -}); - -$(document).ready(function() { - // do keyword highlighting - /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ - var mark = function() { - - var referrer = document.URL ; - var paramKey = "q" ; - - if (referrer.indexOf("?") !== -1) { - var qs = referrer.substr(referrer.indexOf('?') + 1); - var qs_noanchor = qs.split('#')[0]; - var qsa = qs_noanchor.split('&'); - var keyword = ""; - - for (var i = 0; i < qsa.length; i++) { - var currentParam = qsa[i].split('='); - - if (currentParam.length !== 2) { - continue; - } - - if (currentParam[0] == paramKey) { - keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); - } - } - - if (keyword !== "") { - $(".contents").unmark({ - done: function() { - $(".contents").mark(keyword); - } - }); - } - } - }; - - mark(); -}); - -function paths(pathname) { - var pieces = pathname.split("/"); - pieces.shift(); // always starts with / - - var end = pieces[pieces.length - 1]; - if (end === "index.html" || end === "") - pieces.pop(); - return(pieces); -} - -function is_prefix(needle, haystack) { - if (needle.length > haystack.lengh) - return(false); - - // Special case for length-0 haystack, since for loop won't run - if (haystack.length === 0) { - return(needle.length === 0); - } - - for (var i = 0; i < haystack.length; i++) { - if (needle[i] != haystack[i]) - return(false); - } - - return(true); -} - -/* Clipboard --------------------------*/ - -function changeTooltipMessage(element, msg) { - var tooltipOriginalTitle=element.getAttribute('data-original-title'); - element.setAttribute('data-original-title', msg); - $(element).tooltip('show'); - element.setAttribute('data-original-title', tooltipOriginalTitle); -} - -if(Clipboard.isSupported()) { - $(document).ready(function() { - var copyButton = ""; - - $(".examples").addClass("hasCopyButton"); - - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); - - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); - - // Initialize clipboard: - var clipboardBtnCopies = new Clipboard('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent; - } - }); - - clipboardBtnCopies.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); - - clipboardBtnCopies.on('error', function() { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); - }); -} - -/* Search term highlighting ------------------------------*/ - -function matchedWords(hit) { - var words = []; - - var hierarchy = hit._highlightResult.hierarchy; - // loop to fetch from lvl0, lvl1, etc. - for (var idx in hierarchy) { - words = words.concat(hierarchy[idx].matchedWords); - } - - var content = hit._highlightResult.content; - if (content) { - words = words.concat(content.matchedWords); - } - - // return unique words - var words_uniq = [...new Set(words)]; - return words_uniq; -} - -function updateHitURL(hit) { - - var words = matchedWords(hit); - var url = ""; - - if (hit.anchor) { - url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; - } else { - url = hit.url + '?q=' + escape(words.join(" ")); - } - - return url; -} diff --git a/docs/dev/pkgdown.yml b/docs/dev/pkgdown.yml deleted file mode 100644 index f5a46cd..0000000 --- a/docs/dev/pkgdown.yml +++ /dev/null @@ -1,5 +0,0 @@ -pandoc: 1.19.2.1 -pkgdown: 1.0.0 -pkgdown_sha: ~ -articles: [] - diff --git a/docs/dev/reference/connectionStringAccess.html b/docs/dev/reference/connectionStringAccess.html deleted file mode 100644 index 5d98784..0000000 --- a/docs/dev/reference/connectionStringAccess.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - -Connection String Access — connectionStringAccess • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Connection String Access

    - -
    - -
    connectionStringAccess(mdb, uid = "", pwd = "",
    -  globalPartialBulkOps = 0)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access file

    uid

    user id, if any

    pwd

    password, if any

    globalPartialBulkOps

    A Long value (read/write) that determines the -behavior of the Jet database engine when SQL DML bulk operations fail. When -set to allow partial completion of bulk operations, inconsistent changes -can occur, because operations on some records could succeed and others -could fail. When set to allow no partial completion of bulk operations, all -changes are rolled back if a single error occurs. The Jet OLEDB:Global -Partial Bulk Ops property setting can be overridden for the current -Recordset object by setting the Jet OLEDB:Partial Bulk Ops property.The Jet -OLEDB:Global Partial Bulk Ops and Jet OLEDB:Partial Bulk Ops properties can -be set to any of the following values: Default = 0, Partial = 1, No Partial -= 2

    - -

    References

    - -

    http://msdn.microsoft.com/en-us/library/office/aa140022%28v=office.10%29.aspx

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/createRDatabaseInterface.html b/docs/dev/reference/createRDatabaseInterface.html deleted file mode 100644 index 8b67b7e..0000000 --- a/docs/dev/reference/createRDatabaseInterface.html +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - -Create R-Function Interface to Database — createRDatabaseInterface • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create R-Function Interface to Database

    - -
    - -
    createRDatabaseInterface(db = NULL, dbSchema = NULL,
    -  tableNamePattern = "", functionPrefix = "db_", pattern = "^",
    -  rfile = file.path(tempdir(), "dbInterface.R"),
    -  rfile.create = file.path(tempdir(), "dbInterfaceCreate.R"),
    -  create.create.functions = FALSE, dbg = TRUE, sql.dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    name of ODBC data source or full path to MS Access or Excel file

    dbSchema

    list structure describing the database schema, as returned by -kwb.odm::dbSchema_ODM()

    tableNamePattern

    pattern matching the names of tables/views for which -an accessor function is to be generated

    functionPrefix

    prefix to be given to each generated function. Default: -"db_"

    pattern

    pattern matching the part of the table name that will be -replaced with functionPrefix. Default: "^", i.e. the prefix will be -appended to the start of the table name

    rfile

    full path to the file in which to store the data access -functions

    rfile.create

    full path to the file in which to store the data creation -functions (only relevant if crete.create.functions is TRUE)

    create.create.functions

    logical. If TRUE (the default if FALSE) not -only data access but also data creation functions are generated

    dbg

    if TRUE, progress messages are shown during the creation of the -interface functions

    sql.dbg

    if TRUE, SQL strings used to access the database are shown -when calling the interface functions

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/currentDb.html b/docs/dev/reference/currentDb.html deleted file mode 100644 index 66982a5..0000000 --- a/docs/dev/reference/currentDb.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - -Get Path to or Name of Current Database — currentDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Path to or name of current database (as set with -setCurrentDb)

    - -
    - -
    currentDb(dbg = TRUE)
    - -

    Arguments

    - - - - - - -
    dbg

    if TRUE, a message obout setting the current database is printed

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/dataFrameToSqlTuples.html b/docs/dev/reference/dataFrameToSqlTuples.html deleted file mode 100644 index edb5f13..0000000 --- a/docs/dev/reference/dataFrameToSqlTuples.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - -Create SQL Tuples from Data Frame — dataFrameToSqlTuples • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create SQL Tuples from Data Frame

    - -
    - -
    dataFrameToSqlTuples(newData)
    - -

    Arguments

    - - - - - - -
    newData

    a data frame

    - -

    Value

    - -

    vector of character strings each of which represents one row in - newData

    - - -

    Examples

    -
    x <- data.frame( - name = c("Peter", "Paul"), - birthday = as.POSIXct(c("1981-12-13", "2003-01-16")) -) - -setCurrentSqlDialect("msaccess") -dataFrameToSqlTuples(x)
    #> [1] "(Peter,#1981-12-13#)" "(Paul,#2003-01-16#)"
    -# Note that the representation of a date and time is different in MySQL -setCurrentSqlDialect("mysql") -dataFrameToSqlTuples(x)
    #> [1] "(Peter,'1981-12-13')" "(Paul,'2003-01-16')"
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/dumpDatabase.html b/docs/dev/reference/dumpDatabase.html deleted file mode 100644 index 4351492..0000000 --- a/docs/dev/reference/dumpDatabase.html +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - -Export Database Tables to CSV Files — dumpDatabase • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Exports all tables of a database of which the names match a given pattern to -csv files.

    - -
    - -
    dumpDatabase(db, pattern = "^tbl", target_dir = NULL,
    -  create_target_dir = FALSE, sep = ",", dec = ".",
    -  qmethod = "double", row.names = FALSE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    full path to database or name of ODBC data source

    pattern

    pattern matching names of tables to be exported. Default: -"^tbl", i.e. tables starting with "tbl"

    target_dir

    target directory. By default a new directory is created in -the same directory as mdb resides in. The new directory has the same name -as the database file with dots substituted with underscores

    create_target_dir

    if TRUE, the target directory tdir is -created if it does not exist.

    sep

    passed to write.table

    dec

    passed to write.table

    qmethod

    passed to write.table

    row.names

    passed to write.table

    further arguments passed to write.table

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getCurrentSqlDialect.html b/docs/dev/reference/getCurrentSqlDialect.html deleted file mode 100644 index 3caef27..0000000 --- a/docs/dev/reference/getCurrentSqlDialect.html +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - -Get Current SQL Dialect — getCurrentSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Current SQL Dialect

    - -
    - -
    getCurrentSqlDialect(warn = TRUE, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    warn

    if TRUE and if no current SQL dialog is stored in the options, -the program stops with an error message

    dbg

    if TRUE, a message about the current SQL dialect is printed

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getDatabaseSchema.html b/docs/dev/reference/getDatabaseSchema.html deleted file mode 100644 index 98931c9..0000000 --- a/docs/dev/reference/getDatabaseSchema.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - -Get Database Schema — getDatabaseSchema • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Database Schema

    - -
    - -
    getDatabaseSchema(db)
    - -

    Arguments

    - - - - - - -
    db

    full path to database (*.mdb, *.xls) or name of ODBC database

    - -

    Value

    - -

    list with elements tables and relationships. Element - tables is a list o named elements with the name representing the - table names and the elements being lists describing the table...

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getFilteredRecords.html b/docs/dev/reference/getFilteredRecords.html deleted file mode 100644 index 62f1ecc..0000000 --- a/docs/dev/reference/getFilteredRecords.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - -Get Filtered Records — getFilteredRecords • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Filtered Records

    - -
    - -
    getFilteredRecords(db, tableName, keyValues, fields, like, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or database file

    tableName

    name of the table from which to read records

    keyValues

    list of key = value pairs with the keys representing -field names of the table tableName, defining filter criteria

    fields

    table fields to be selected

    like

    if TRUE the SQL LIKE operator is used instead of -the equal operator = when matching the values in keyValues -with the table fields

    additonal arguments passed to selectFromDb

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getNamedExcelRanges.html b/docs/dev/reference/getNamedExcelRanges.html deleted file mode 100644 index ad99071..0000000 --- a/docs/dev/reference/getNamedExcelRanges.html +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - -Get Named Ranges from Excel File — getNamedExcelRanges • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Named Ranges from Excel File

    - -
    - -
    getNamedExcelRanges(file, pattern = "^range", dbg = TRUE,
    -  stringsAsFactors = FALSE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    file

    path to Excel file

    pattern

    pattern matching the names of named cell ranges to be read. -By default, all ranges starting with range are read.

    dbg

    logical. If TRUE debug messages are shown

    stringsAsFactors

    passed to hsGetTable

    further arguments passed to hsGetTable

    - -

    Value

    - -

    list of data frames each of which represents the content a named cell - range in the Excel file and each of which was read with - hsGetTable.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getSqlDialect.html b/docs/dev/reference/getSqlDialect.html deleted file mode 100644 index 5f075c2..0000000 --- a/docs/dev/reference/getSqlDialect.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - -Get SQL Dialect from Given Database — getSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    get SQL dialect ("mysql" or "msaccess") from given database

    - -
    - -
    getSqlDialect(db, use2007Driver = NULL)
    - -

    Arguments

    - - - - - - - - - - -
    db

    ODBC database name or full path to database (mdb or xls)

    use2007Driver

    passed to isMySQL

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/getTypeIdentifier.html b/docs/dev/reference/getTypeIdentifier.html deleted file mode 100644 index 6838474..0000000 --- a/docs/dev/reference/getTypeIdentifier.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - -Get Type Identifier — getTypeIdentifier • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Type Identifier

    - -
    - -
    getTypeIdentifier(x)
    - -

    Arguments

    - - - - - - -
    x

    R object for which to find an adequate database object type

    - -

    Value

    - -

    Returns "int", "double", "text", "date_time" or "boolean" depending - on the data type of x

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/get_namedExcelRanges.html b/docs/dev/reference/get_namedExcelRanges.html deleted file mode 100644 index b0363fa..0000000 --- a/docs/dev/reference/get_namedExcelRanges.html +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - -Get Named Ranges from Excel File — get_namedExcelRanges • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Named Ranges from Excel File

    - -
    - -
    get_namedExcelRanges(file, pattern = "^range", dbg = TRUE,
    -  stringsAsFactors = FALSE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    file

    path to Excel file

    pattern

    pattern matching the names of named cell ranges to be read. -By default, all ranges starting with range are read.

    dbg

    logical. If TRUE debug messages are shown

    stringsAsFactors

    passed to hsGetTable

    further arguments passed to hsGetTable

    - -

    Value

    - -

    list of data frames each of which represents the content a named cell - range in the Excel file and each of which was read with - hsGetTable.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsClearTable.html b/docs/dev/reference/hsClearTable.html deleted file mode 100644 index 8bcbb8c..0000000 --- a/docs/dev/reference/hsClearTable.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - -Clear a Database Table — hsClearTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deletes all the rows of the table \(tbl\). This function performs opening -of the connection, clearing of the table and closing of the connection. If -an error occurs the program stops and an error description is shown.

    - -
    - -
    hsClearTable(mdb, tbl, cond = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database (*.mdb).

    tbl

    table name.

    cond

    optional: condition.

    additional arguments passed to hsSqlQuery, e.g. "errors=TRUE"

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsCloseDb.html b/docs/dev/reference/hsCloseDb.html deleted file mode 100644 index 8e3116d..0000000 --- a/docs/dev/reference/hsCloseDb.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - -Close Connection to MS Access or Excel — hsCloseDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Closes the database connection.

    - -
    - -
    hsCloseDb(con)
    - -

    Arguments

    - - - - - - -
    con

    Open database connection as returned by -hsOpenDb/odbcConnect

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsCloseMdb.html b/docs/dev/reference/hsCloseMdb.html deleted file mode 100644 index f2fefba..0000000 --- a/docs/dev/reference/hsCloseMdb.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - -Close Connection — hsCloseMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deprecated. Use codehsCloseDb instead.

    - -
    - -
    hsCloseMdb(con)
    - -

    Arguments

    - - - - - - -
    con

    Open database connection as returned by -hsOpenMdb/odbcConnect

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsDropTable.html b/docs/dev/reference/hsDropTable.html deleted file mode 100644 index 1424d12..0000000 --- a/docs/dev/reference/hsDropTable.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - -Drop Database Table(s) — hsDropTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Removes the table \(tbl\) (if permitted). This function performs opening of -the connection, dropping of the table and closing of the connection. If an -error occurs the program stops and an error description is shown.

    - -
    - -
    hsDropTable(mdb, tbl, isPtrn = FALSE, dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database (*.mdb).

    tbl

    table name.

    isPtrn

    if TRUE, tbl is interpreted as a regular expression -matching the names of the tables to be deleted.

    dbg

    if TRUE, debug messages are shown

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsDumpMdb.html b/docs/dev/reference/hsDumpMdb.html deleted file mode 100644 index fbdc01c..0000000 --- a/docs/dev/reference/hsDumpMdb.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - -Export Database Tables to CSV Files — hsDumpMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deprecated. Please use dumpDatabase instead.

    - -
    - -
    hsDumpMdb(mdb, ptrn = "^tbl", tdir = file.path(dirname(mdb),
    -  gsub("\\.", "_", basename(mdb))), create_target_dir = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to database

    ptrn

    pattern matching names of tables to be exported. Default: "^tbl", -i.e. tables starting with "tbl"

    tdir

    target directory. By default a new directory is created in the -same directory as mdb resides in. The new directory has the same name as -the database file with dots substituted with underscores

    create_target_dir

    if TRUE, the target directory tdir -is created if it does not exist.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsFields.html b/docs/dev/reference/hsFields.html deleted file mode 100644 index 4ddc128..0000000 --- a/docs/dev/reference/hsFields.html +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - - -Available Fields in Database Table — hsFields • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a vector containing the field names of a database table.

    - -
    - -
    hsFields(mdb, tbl, namesOnly = TRUE, chopDollar = TRUE,
    -  ignore.case = (!isMySQL(mdb, use2007Driver = use2007Driver)),
    -  use2007Driver = NULL, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    tbl

    table name.

    namesOnly

    if TRUE, only field names are returned, otherwise all -available information on the fields. Default: TRUE

    chopDollar

    if TRUE (default), a dollar sign at the end of the table -name is removed before sending it to sqlColumns,

    ignore.case

    if TRUE, case is ignored when comparing the given table -with the names of the existing tables. Default: FALSE

    use2007Driver

    passed to isMySQL

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    Vector containing the field names of the database table (if namesOnly - = TRUE) or data.frame with columns COLUMN_NAME, DATA_TYPE, - TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, - DECIMAL_DIGITS, NUM_PREC_RADIX, NULLABLE describing - the database fields in detail, otherwise.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## List the fields of table "tbl_Hyd" in the example database
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -  setCurrentSqlDialect("msaccess")
    -  fields <- hsFields(xmdb(), "tbl_Hyd")
    -  fields
    -}
    -
    -## Ouput:
    -# [1] "Zeitst"  "Q"       "v"       "H"       "T_Kanal"
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsGetTable.html b/docs/dev/reference/hsGetTable.html deleted file mode 100644 index ff8e0fd..0000000 --- a/docs/dev/reference/hsGetTable.html +++ /dev/null @@ -1,273 +0,0 @@ - - - - - - - - -Get Table from MS Access Database — hsGetTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Provides data from an MS Access database table in forms of a data frame.

    - -
    - -
    hsGetTable(mdb, tbl, cond = "TRUE", fields = "*", dbg = TRUE,
    -  check = TRUE, use2007Driver = NULL, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    tbl

    Table name. Put it into brackets [] if it contains spaces and if -it mdb does not point to a MySQL database

    cond

    Condition string.

    fields

    Comma separated list of names of fields to be selected.

    dbg

    if TRUE, debug messages are shown, else not

    check

    if TRUE (default), tbl is checked for existence in -mdb before trying to get the data and a list of available tables is -shown in the case that the table does not exist.

    use2007Driver

    passed to hsTables and -hsSqlQuery

    Additional arguments to be passed to hsSqlQuery

    - -

    Value

    - -

    data.frame containing data from table in database

    - -

    Details

    - -

    ATTENTION: This function may not return what you want if the table contains a -timestamp field. Use hsMdbTimeSeries instead.

    - -

    See also

    - -

    hsSqlQuery, hsPutTable, hsGetTimeSeries, - hsMdbTimeSeries

    - - -

    Examples

    -
    # NOT RUN {
    -## Get all datasets from tbl_Hyd in example database where
    -## Q > 1.0 m3/s and temperature > 20 degree Celsius
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -  ts <- hsGetTable(xmdb(), "tbl_Hyd", "Q > 1.0 AND T_Kanal > 20")
    -  head(ts)
    -}
    -
    -## Output:
    -# Zeitst     Q     v     H T_Kanal
    -# 1 2011-08-24 22:33:00 1.075 0.459 1.366    20.1
    -# 2 2011-08-24 22:34:00 1.062 0.453 1.370    20.2
    -# 3 2011-08-24 22:35:00 1.050 0.449 1.364    20.2
    -# 4 2011-08-24 22:36:00 1.042 0.446 1.361    20.3
    -# 5 2011-08-24 22:37:00 1.032 0.443 1.354    20.3
    -# 6 2011-08-24 22:38:00 1.010 0.436 1.348    20.4
    -
    -## TAKE CARE when getting time-series data:
    -if (.Platform$OS.type == "windows") {
    -  hsGetTable(xmdb(), "tblTimestampTest_DST")
    -}
    -
    -## Output:
    -#                tstamp
    -# 1 2011-03-27 01:00:00
    -# 2 2011-03-27 01:30:00
    -# 3                <NA>
    -# 4                <NA>
    -# 5 2011-03-27 03:00:00
    -# 6 2011-03-27 03:30:00
    -
    -## As the output shows the timestamps between 02:00:00 and
    -## 02:59:59 have been set to <NA>. Reason: When retrieving
    -## date/time data from MS Access, R converts the timestamps
    -## from a text representation into POSIXct objects. As POSIXct's
    -## standard time zone seems to be taken from the Windows system
    -## R tries to convert to Central European Time (CET) which
    -## does not exist for the hour in which time is switched to
    -## daylight-saving time (as in the example).
    -
    -## This standard behaviour can be changed by setting the
    -## standard time zone:
    -tz <- Sys.getenv("tz") # save current standard time zone
    -Sys.setenv(tz = "UTC") # set standard time zone to UTC
    -
    -## The same command as above now delivers all timestamps
    -## (in Coordinated Universal Time, UTC):
    -
    -if (.Platform$OS.type == "windows") {
    -  hsGetTable(xmdb(), "tblTimestampTest_DST")
    -}
    -
    -## Output:
    -#                tstamp
    -# 1 2011-03-27 01:00:00
    -# 2 2011-03-27 01:30:00
    -# 3 2011-03-27 02:00:00
    -# 4 2011-03-27 02:30:00
    -# 5 2011-03-27 03:00:00
    -# 6 2011-03-27 03:30:00
    -
    -## Reset standard time zone
    -Sys.setenv(tz = tz)
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsGetTimeSeries.html b/docs/dev/reference/hsGetTimeSeries.html deleted file mode 100644 index 75b4984..0000000 --- a/docs/dev/reference/hsGetTimeSeries.html +++ /dev/null @@ -1,284 +0,0 @@ - - - - - - - - -Get Time Series With Timestamp Info — hsGetTimeSeries • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Reads time-series data from an MS Access database table and returns a data -frame containing the data. In the data frame the timestamp column contains -the timestamps as they are converted to by R from (text versions of) the -original timestamps read from MS ACCESS. As this conversion may fail (e.g. -the time information gets lost when transferring timestamps from large data -sets between R and MS Access) this function may return different pieces of -information on the timestamp in forms of additional columns, preceding the -timestamp column, in the result data frame. Per default, eleven additional -columns are returned: 1. <ts>_txt (timestamp as text), 2. <ts>_Date (date -only), 3. <ts>_dSince18991230 (number of days since 1899-12-30), 4. -<ts>_secInDay (number of seconds within the day), 5. <ts>_minInDay (number of -minutes within the day), 6. <ts>_year (year), 7. <ts>_month (number of -month), 8. <ts>_day (number of day within the month), 9. <ts>_h (hours within -day), 10. <ts>_min (minutes within hour), 11. <ts>_s (seconds within minute) -where in each case <ts> is the name of the timestamp field.

    - -
    - -
    hsGetTimeSeries(mdb, tbl, tsField = hsTsField(mdb, tbl), fields = "*",
    -  minDate = NULL, maxDate = NULL, xTsFields = c(1:11),
    -  inclLast = TRUE, sqlFilter = "TRUE", dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb)

    tbl

    Name of table containing the time-series data.

    tsField

    Name of table field containing the timestamps.

    fields

    Vector containing names of value fields to be selected from the -table. This vector may or may not contain the name of the timetamp field.

    minDate

    Minimum date (and time) of time interval to be selected in -ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets in optional.

    maxDate

    Day following the maximum date of the time interval to be -selected, in ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets -in optional.

    xTsFields

    Extra timestamp fields to be selected. Vector containing -numbers between 1 and 11, where each number represents a type of date/time -information as described for function hsSqlExTsFields.

    inclLast

    If TRUE, maxDate will be included in result data set, -else excluded.

    sqlFilter

    additional SQL filter criterion

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    data frame containing the requested data (timestamp and value - columns) and additional columns preceding the timestamp column containing - different pieces of information on the timestamp.

    - -

    Details

    - -

    This function is called internally by the higher-level function -hsMdbTimeSeries that reconstructs the correct timestamps from -the different pieces of timestamp information and provides them in forms of -POSIXct objects in UTC timezone.

    -

    Use hsMdbTimeSeries instead if you do not want to care about -any timestamp conversion problems!

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get flow time series of 24 of July 2011 from tbl_Hyd in example database
    -## Additionally to the timestamp that is created by R, return the date only
    -## (timestamp info id = 2) and the number of minutes within the day
    -## (timestamp info id = 5).
    -
    -setCurrentSqlDialect("msaccess")
    -
    -if (.Platform$OS.type == "windows") {
    -  ts <- hsGetTimeSeries(
    -    mdb = xmdb(),
    -    tbl = "tbl_Hyd",
    -    tsField = "Zeitst",
    -    fields = c("Q", "v"),
    -    minDate = "2011-08-24",
    -    maxDate = "2011-08-25",
    -    xTsFields = c(2, 5),
    -    dbg = TRUE
    -  )
    -
    -  ## Show the last records of the returned dataset.
    -  tail(ts)
    -}
    -
    -## Output:
    -#      Zeitst_Date Zeitst_minInDay              Zeitst     Q     v
    -# 1435  2011-08-24            1435 2011-08-24 23:55:00 0.638 0.281
    -# 1436  2011-08-24            1436 2011-08-24 23:56:00 0.601 0.265
    -# 1437  2011-08-24            1437 2011-08-24 23:57:00 0.564 0.249
    -# 1438  2011-08-24            1438 2011-08-24 23:58:00 0.536 0.237
    -# 1439  2011-08-24            1439 2011-08-24 23:59:00 0.504 0.223
    -# 1440  2011-08-25               0 2011-08-25 00:00:00 0.483 0.214
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsJetDate.html b/docs/dev/reference/hsJetDate.html deleted file mode 100644 index 3a5fb28..0000000 --- a/docs/dev/reference/hsJetDate.html +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - -Date to “mm/dd/yyyy HH:MM:SS” — hsJetDate • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a date in MS Jet SQL syntax: mm/dd/yyyy HH:MM:SS

    - -
    - -
    hsJetDate(datetime, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    datetime

    Date (and time) information in forms of Date object or POSIX -object or string.

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsLookupOrAddRecord.html b/docs/dev/reference/hsLookupOrAddRecord.html deleted file mode 100644 index 2bedb47..0000000 --- a/docs/dev/reference/hsLookupOrAddRecord.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - -Lookup or Add Record — hsLookupOrAddRecord • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Looks up a record in a database table and returns the ID of the record. If -the record is not found it is inserted to the table and the ID of the new -record is returned.

    - -
    - -
    hsLookupOrAddRecord(mdb, tbl, keyAssigns, fieldAssigns = NULL,
    -  idField = hsFields(mdb, tbl)[1], dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database

    tbl

    name of table in which record is to be looked up

    keyAssigns

    key-value-assignements used to identify the record to be -looked up. The assignments are defined in forms of a list, e.g. list(key1 = -"value1", key2 = "value2").

    fieldAssigns

    further field-value-assignements used when a new record -needs to be inserted. The assignments are defined in forms of a list, e.g. -list(field1 = "value1", field2 = "value2").

    idField

    name of ID field, default: name of first table field

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsMdbTimeSeries.html b/docs/dev/reference/hsMdbTimeSeries.html deleted file mode 100644 index 5699cc2..0000000 --- a/docs/dev/reference/hsMdbTimeSeries.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - -Get Mdb time series in UTC — hsMdbTimeSeries • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Reads time-series data from an MS Access database table and returns a data -frame containing the data. The name of the timestamp field must be given in -tsField and the names of the value fields to be selected from the -table must be given in vector fields. Instead of an ODBC channel the -name of the database must be given. This function takes care that the -timestamps are transferred correctly between MS Access and R by requesting -date and time information separately from MS Access and putting both together -to a POSIXct object in UTC timezone. This is necessary because with very long -data sets the RODBC function sqlQuery (or the function -hsSqlQuery that calls this function) may deliver timestamps in -which time information is lacking!

    - -
    - -
    hsMdbTimeSeries(mdb, tbl, tsField = hsTsField(mdb, tbl), fields = "*",
    -  minDate = NULL, maxDate = NULL, resolution = "min",
    -  inclLast = TRUE, sqlFilter = "TRUE", dbg = FALSE, calcType = 1)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb)

    tbl

    Name of table containing the time-series data.

    tsField

    Name of table field containing the timestamps.

    fields

    Vector containing names of value fields to be selected from the -table. This vector may or may not contain the name of the timetamp field.

    minDate

    Minimum date (and time) of time interval to be selected in -ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets in optional.

    maxDate

    Day following the maximum date of the time interval to be -selected, in ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets -in optional.

    resolution

    time resolution: “min” = minutes, “s” = -seconds. If time resolution is “min” timestamps are rounded to the -next full minute.

    inclLast

    If TRUE, maxDate will be included in result data set, -else excluded.

    sqlFilter

    additional SQL filter criterion

    dbg

    if TRUE, debug messages are shown

    calcType

    for internal use only, do not change!

    - -

    Value

    - -

    data.frame with POSIXct timestamp column <strTimestamp> (UTC time - zone) and value columns as selected in <strFieldList>

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get flow time series of 24 of August 2011 from tbl_Hyd in example database
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  ts <- hsMdbTimeSeries(
    -    xmdb(), "tbl_Hyd", "Zeitst", c("Q", "v"), "2011-08-24", "2011-08-25"
    -  )
    -
    -  ## Show the last records of the returned dataset.
    -  tail(ts)
    -}
    -
    -## Output:
    -#                   Zeitst     Q     v
    -# 1435 2011-08-24 23:55:00 0.638 0.281
    -# 1436 2011-08-24 23:56:00 0.601 0.265
    -# 1437 2011-08-24 23:57:00 0.564 0.249
    -# 1438 2011-08-24 23:58:00 0.536 0.237
    -# 1439 2011-08-24 23:59:00 0.504 0.223
    -# 1440 2011-08-25 00:00:00 0.483 0.214
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsOpenDb.html b/docs/dev/reference/hsOpenDb.html deleted file mode 100644 index b594cba..0000000 --- a/docs/dev/reference/hsOpenDb.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - -Open Connection to MS Access or Excel — hsOpenDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Opens database connection to MS Access or MS Excel, checks the connection and -stops on error.

    - -
    - -
    hsOpenDb(src, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "",
    -  ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    src

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”) or name of ODBC data source.

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE and if the connection could be established details of the -connection are shown.

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    additional arguments passed to the odbcConnect...()-function

    - -

    Value

    - -

    On success an object of class RODBC describing the connection is - returned. On failure nothing is returned and program execution stops.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Open a connection to the example database
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  con <- hsOpenDb(xmdb())
    -  con
    -}
    -
    -## Details on the established connection are shown:
    -# RODBC Connection 9
    -# Details:
    -#   case=nochange
    -#   DBQ=C:\Users\hsonne\Documents\R\win-library\2.14\kwb.base\...
    -#   Driver={Microsoft Access Driver (*.mdb)}
    -#   DriverId=25
    -#   FIL=MS Access
    -#   MaxBufferSize=2048
    -#   PageTimeout=5
    -#   UID=admin
    -
    -## Close the connection again
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  hsCloseDb(con)
    -}
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsOpenMdb.html b/docs/dev/reference/hsOpenMdb.html deleted file mode 100644 index 79f8623..0000000 --- a/docs/dev/reference/hsOpenMdb.html +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - -Open Connection to MS Access Database — hsOpenMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deprecated. Use hsOpenDb instead.

    - -
    - -
    hsOpenMdb(mdb, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    mdb

    full path to MS Access database file.

    dbg

    if TRUE and if the connection could be established details of the -connection are shown.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsPutTable.html b/docs/dev/reference/hsPutTable.html deleted file mode 100644 index d0a4901..0000000 --- a/docs/dev/reference/hsPutTable.html +++ /dev/null @@ -1,230 +0,0 @@ - - - - - - - - -Save Data Frame to Database Table — hsPutTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Writes data to a database table. This function performs opening of the -connection, saving of the data to a table and closing of the connection. If -an error occurs the program stops and an error description is shown. If a -table named tbl already exists in the database mdb the existing -table is only overwritten if overwrite is TRUE. Otherwise a -hsSafeName will be found for the table.

    - -
    - -
    hsPutTable(mdb, myData, tbl = "tblTmp", types = NULL,
    -  overwrite = FALSE, DBMSencoding = "", dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (*.mdb)

    myData

    data.frame containing data to be written to database table

    tbl

    Name of table to be created in the database

    types

    field types to be passed to sqlSave as argument varTypes, -see ?sqlSave for details.

    overwrite

    shall existing table be overwritten?

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    In case of success the name of the created table is returned.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Create a data.frame
    -df1 <- data.frame(id = 1:4, rnd = sample(1:100)[1:4])
    -
    -## Write data.frame into a table in the example database; as no
    -## table name is specified, a table name is generated. The name
    -## of the table is returned.
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tbl <- hsPutTable(xmdb(), df1)
    -  tbl # table name here: [1] "tblTmp"
    -
    -
    -  ## Get the data from the created table back again and print the
    -  ## data. As we see, a table containing four different random
    -  ## numbers between one and 100 has been created.
    -  df2 <- hsGetTable(xmdb(), tbl)
    -  df2
    -}
    -
    -## Output:
    -#   id rnd
    -# 1  1  82
    -# 2  2  14
    -# 3  3  99
    -# 4  4   6
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSetForeignKey.html b/docs/dev/reference/hsSetForeignKey.html deleted file mode 100644 index c4c872c..0000000 --- a/docs/dev/reference/hsSetForeignKey.html +++ /dev/null @@ -1,176 +0,0 @@ - - - - - - - - -Set Foreign Key for Table Field — hsSetForeignKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set foreign key constraint for a table field

    - -
    - -
    hsSetForeignKey(mdb, tbl, field, ref.tbl, ref.field,
    -  key.name = .getForeignKeyName(tbl, field, ref.tbl, ref.field),
    -  dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (*.mdb)

    tbl

    name of table containing the field for which the foreign key -constraint is to be defined

    field

    name of table field for which the foreign key constraint is to -be defined

    ref.tbl

    name of table containing the referenced foreign key field

    ref.field

    name of foreign key field in ref.tbl

    key.name

    optional. Name to be given to the foreign key

    dbg

    passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSetPrimaryKey.html b/docs/dev/reference/hsSetPrimaryKey.html deleted file mode 100644 index 380ebf4..0000000 --- a/docs/dev/reference/hsSetPrimaryKey.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - -Set Primary Key of Database Table — hsSetPrimaryKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Sets fields with names given in vector keyFields as key fields of -table tbl in MS ACCESS database mdb.

    - -
    - -
    hsSetPrimaryKey(mdb, tbl, keyFields, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb).

    tbl

    Name of table in which key fields are to be defined.

    keyFields

    (Vector of) key field name(s)

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlExAnd.html b/docs/dev/reference/hsSqlExAnd.html deleted file mode 100644 index f8bf9f3..0000000 --- a/docs/dev/reference/hsSqlExAnd.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - -SQL Expression “AND” — hsSqlExAnd • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Creates a boolean expression of the form
    bFunc(x1) AND bFunc(x2) -AND ... AND bFunc(xn). This function can be used to create SQL queries where -many table fields have to be checked in the same way for some criterion (see -example).

    - -
    - -
    hsSqlExAnd(x, bFunc)
    - -

    Arguments

    - - - - - - - - - - -
    x

    vector of strings, e.g. representing table field names.

    bFunc

    name of a boolean function to be “applied” to each -element of x.

    - -

    See also

    - - - - -

    Examples

    -
    ## Build SQL query finding records in table t in which all -## of the table fields f1 to f100 are NULL. -sql <- sprintf("SELECT * FROM t WHERE %s", - hsSqlExAnd(paste("f", 1:100, sep = ""), "isNull")) - -## Show the SQL string -sql
    #> [1] "SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND isNull(f2) AND isNull(f3) AND isNull(f4) AND isNull(f5) AND isNull(f6) AND isNull(f7) AND isNull(f8) AND isNull(f9) AND isNull(f10) AND isNull(f11) AND isNull(f12) AND isNull(f13) AND isNull(f14) AND isNull(f15) AND isNull(f16) AND isNull(f17) AND isNull(f18) AND isNull(f19) AND isNull(f20) AND isNull(f21) AND isNull(f22) AND isNull(f23) AND isNull(f24) AND isNull(f25) AND isNull(f26) AND isNull(f27) AND isNull(f28) AND isNull(f29) AND isNull(f30) AND isNull(f31) AND isNull(f32) AND isNull(f33) AND isNull(f34) AND isNull(f35) AND isNull(f36) AND isNull(f37) AND isNull(f38) AND isNull(f39) AND isNull(f40) AND isNull(f41) AND isNull(f42) AND isNull(f43) AND isNull(f44) AND isNull(f45) AND isNull(f46) AND isNull(f47) AND isNull(f48) AND isNull(f49) AND isNull(f50) AND isNull(f51) AND isNull(f52) AND isNull(f53) AND isNull(f54) AND isNull(f55) AND isNull(f56) AND isNull(f57) AND isNull(f58) AND isNull(f59) AND isNull(f60) AND isNull(f61) AND isNull(f62) AND isNull(f63) AND isNull(f64) AND isNull(f65) AND isNull(f66) AND isNull(f67) AND isNull(f68) AND isNull(f69) AND isNull(f70) AND isNull(f71) AND isNull(f72) AND isNull(f73) AND isNull(f74) AND isNull(f75) AND isNull(f76) AND isNull(f77) AND isNull(f78) AND isNull(f79) AND isNull(f80) AND isNull(f81) AND isNull(f82) AND isNull(f83) AND isNull(f84) AND isNull(f85) AND isNull(f86) AND isNull(f87) AND isNull(f88) AND isNull(f89) AND isNull(f90) AND isNull(f91) AND isNull(f92) AND isNull(f93) AND isNull(f94) AND isNull(f95) AND isNull(f96) AND isNull(f97) AND isNull(f98) AND isNull(f99) AND isNull(f100)"
    -## Output (middle part omitted): -# SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND -# isNull(f2) AND isNull(f3) AND ... AND isNull(f100) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlExOr.html b/docs/dev/reference/hsSqlExOr.html deleted file mode 100644 index bc471bb..0000000 --- a/docs/dev/reference/hsSqlExOr.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - -SQL Expression “OR” — hsSqlExOr • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Creates a boolean expression of the form
    bFunc(x1) OR bFunc(x2) OR -... OR bFunc(xn). This function can be used to create SQL queries where many -table fields have to be checked in the same way for some criterion (see -example).

    - -
    - -
    hsSqlExOr(x, bFunc = "")
    - -

    Arguments

    - - - - - - - - - - -
    x

    vector of strings, e.g. representing table field names.

    bFunc

    name of a boolean function to be “applied” to each -element of x.

    - -

    See also

    - - - - -

    Examples

    -
    ## Build SQL query finding records in table t in which at least -## one of the table fields f1 to f100 is NULL. -sql <- sprintf("SELECT * FROM t WHERE %s", - hsSqlExOr(paste("f", 1:100, sep = ""), "isNull")) - -## Show the SQL string -sql
    #> [1] "SELECT * FROM t WHERE (FALSE) OR isNull(f1) OR isNull(f2) OR isNull(f3) OR isNull(f4) OR isNull(f5) OR isNull(f6) OR isNull(f7) OR isNull(f8) OR isNull(f9) OR isNull(f10) OR isNull(f11) OR isNull(f12) OR isNull(f13) OR isNull(f14) OR isNull(f15) OR isNull(f16) OR isNull(f17) OR isNull(f18) OR isNull(f19) OR isNull(f20) OR isNull(f21) OR isNull(f22) OR isNull(f23) OR isNull(f24) OR isNull(f25) OR isNull(f26) OR isNull(f27) OR isNull(f28) OR isNull(f29) OR isNull(f30) OR isNull(f31) OR isNull(f32) OR isNull(f33) OR isNull(f34) OR isNull(f35) OR isNull(f36) OR isNull(f37) OR isNull(f38) OR isNull(f39) OR isNull(f40) OR isNull(f41) OR isNull(f42) OR isNull(f43) OR isNull(f44) OR isNull(f45) OR isNull(f46) OR isNull(f47) OR isNull(f48) OR isNull(f49) OR isNull(f50) OR isNull(f51) OR isNull(f52) OR isNull(f53) OR isNull(f54) OR isNull(f55) OR isNull(f56) OR isNull(f57) OR isNull(f58) OR isNull(f59) OR isNull(f60) OR isNull(f61) OR isNull(f62) OR isNull(f63) OR isNull(f64) OR isNull(f65) OR isNull(f66) OR isNull(f67) OR isNull(f68) OR isNull(f69) OR isNull(f70) OR isNull(f71) OR isNull(f72) OR isNull(f73) OR isNull(f74) OR isNull(f75) OR isNull(f76) OR isNull(f77) OR isNull(f78) OR isNull(f79) OR isNull(f80) OR isNull(f81) OR isNull(f82) OR isNull(f83) OR isNull(f84) OR isNull(f85) OR isNull(f86) OR isNull(f87) OR isNull(f88) OR isNull(f89) OR isNull(f90) OR isNull(f91) OR isNull(f92) OR isNull(f93) OR isNull(f94) OR isNull(f95) OR isNull(f96) OR isNull(f97) OR isNull(f98) OR isNull(f99) OR isNull(f100)"
    -## Output (middle part omitted): -# SELECT * FROM t WHERE (FALSE) OR isNull(f1) OR -# isNull(f2) OR isNull(f3) OR ... OR isNull(f100) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlExTimeCond.html b/docs/dev/reference/hsSqlExTimeCond.html deleted file mode 100644 index ea83947..0000000 --- a/docs/dev/reference/hsSqlExTimeCond.html +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - - - -SQL Expression: Time Period — hsSqlExTimeCond • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    WHERE-condition string in MS Jet SQL syntax filtering for a specific - time interval

    - -
    - -
    hsSqlExTimeCond(tsField, dateFirst = NULL, dateLast = NULL,
    -  inclLast = TRUE, sqlDialect = getCurrentSqlDialect(), dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tsField

    name of timestamp field

    dateFirst

    Date object representing the first date of the time interval -to be selected.

    dateLast

    Date object representing the last date of the time interval -to be selected.

    inclLast

    if TRUE, dateLast will be included in result data set, -else excluded.

    sqlDialect

    one of c("mysql", "msaccess")

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    Condition string in MS Jet SQL syntax to be used in WHERE clause

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Condition string to filter field "datetime" for timestamps 
    -## between 21 and 22 of July 2010
    -from <- as.Date("2011-08-23")
    -to   <- as.Date("2011-08-24")
    -cond <- hsSqlExTimeCond("Zeitst", from, to)
    -cond
    -
    -## Output:
    -# TRUE  AND Zeitst >= #08/23/2011 00:00:00#  
    -#       AND Zeitst <= #08/24/2011 00:00:00#
    -
    -## The condition string may now be used in an SQL query 
    -## to select data from within the time interval. 
    -sql <- sprintf("SELECT * FROM tbl_Hyd WHERE %s", cond)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  res <- hsSqlQuery(xmdb(), sql)
    -  head(res)
    -}
    -
    -## Output:
    -# Zeitst Q v     H T_Kanal
    -# 1 2011-08-23 00:00:00 0 0 1.260    19.5
    -# 2 2011-08-23 00:01:00 0 0 1.259    19.5
    -# 3 2011-08-23 00:02:00 0 0 1.259    19.5
    -# 4 2011-08-23 00:03:00 0 0 1.259    19.5
    -# 5 2011-08-23 00:04:00 0 0 1.260    19.5
    -# 6 2011-08-23 00:05:00 0 0 1.260    19.5
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlExTimeGroup.html b/docs/dev/reference/hsSqlExTimeGroup.html deleted file mode 100644 index 359f70a..0000000 --- a/docs/dev/reference/hsSqlExTimeGroup.html +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - -SQL Expression: Time Grouping — hsSqlExTimeGroup • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generates SQL code for grouping timestamps by years, months or days

    - -
    - -
    hsSqlExTimeGroup(tbl, tsField, interval, cond = "TRUE")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tbl

    name of the table

    tsField

    name of the table field containing the timestamp

    interval

    specifies the time period to group by ("y": years, "m": -months, "d": days)

    cond

    additional condition in SQL syntax

    - -

    Value

    - -

    Returns SQL code for grouping timestamps by years, months or days

    - -

    See also

    - - - - -

    Examples

    -
    ## Show SQL query that gets the number of datasets per -## day ("d") considering the condition "Q > 0" -hsSqlExTimeGroup("myTable", "myTimestamp", "d", "Q > 0")
    #> [1] "SELECT DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) AS myInterval, Count(*) AS myCount FROM (SELECT myTimestamp AS hsTS FROM [myTable] WHERE Q > 0) GROUP BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) ORDER BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS))"
    -## Output (reformatted): -## SELECT DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) -## AS myInterval, Count(*) AS myCount -## FROM ( -## SELECT myTimestamp AS hsTS FROM myTable WHERE Q > 0 -## ) -## GROUP BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) -## ORDER BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlExTsFields.html b/docs/dev/reference/hsSqlExTsFields.html deleted file mode 100644 index 8615170..0000000 --- a/docs/dev/reference/hsSqlExTsFields.html +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - -SQL Expression: Timestamp Info — hsSqlExTsFields • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generates SQL code for selecting different parts of the timestamp

    - -
    - -
    hsSqlExTsFields(tsField, extraTsFields = 0:11)
    - -

    Arguments

    - - - - - - - - - - -
    tsField

    name of the table field containing the timestamp

    extraTsFields

    vector of integers representing different types of -time-stamp information:
    0 = the timestamp in POSIXct as it is converted -to by R from the text representation delivered by MS Access,
    1 = -Timestamp as character string,
    2 = Date,
    3 = number of days since -1899-12-30,
    4 = number of seconds since midnight of Date
    5 = number -of minutes since midnight of Date
    6:8 = year, month, day
    9:11 = -hours, minutes, seconds

    - -

    Value

    - -

    Returns SQL code for selecting different types of information on - the time stamp.

    - -

    See also

    - - - - -

    Examples

    -
    hsSqlExTsFields("myTimestamp", c(6:11))
    #> [1] "Year(myTimestamp) AS myTimestamp_year, Month(myTimestamp) AS myTimestamp_month, Day(myTimestamp) AS myTimestamp_day, Hour(myTimestamp) AS myTimestamp_h, Minute(myTimestamp) AS myTimestamp_m, Second(myTimestamp) AS myTimestamp_s"
    -## Output (re-formatted): -# "Year(myTimestamp) AS myTimestamp_year, -# Month(myTimestamp) AS myTimestamp_month, -# Day(myTimestamp) AS myTimestamp_day, -# Hour(myTimestamp) AS myTimestamp_h, -# Minute(myTimestamp) AS myTimestamp_m, -# Second(myTimestamp) AS myTimestamp_s" - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsSqlQuery.html b/docs/dev/reference/hsSqlQuery.html deleted file mode 100644 index 5b6a7ed..0000000 --- a/docs/dev/reference/hsSqlQuery.html +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - -Send SQL Query to Database — hsSqlQuery • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get data from database requested via an SQL query. This function performs -opening of the connection, data retieval via SQL and closing of the -connection. If an error occurs the program stops and an error description is -shown.

    - -
    - -
    hsSqlQuery(mdb, sql, use2007Driver = NULL, dbg = TRUE,
    -  stopOnError = TRUE, DBMSencoding = "", ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    sql

    SQL query

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE (default), debug messages are shown.

    stopOnError

    if TRUE (default), the program stops in case of an error, -otherwise a warning is shown and NULL is returned.

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    additional arguments to be passed to sqlQuery

    - -

    Value

    - -

    On success, a data.frame containing the data that is internally - requested by calling the RODBC function sqlQuery and that is provided by - the database is returned. On error R stops execution and does not return - anything.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get Q time series from table "tbl_Hyd" in example database
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tsQ <- hsSqlQuery(
    -    xmdb(), "SELECT Zeitst AS t, Q FROM tbl_Hyd WHERE Q > 1.0"
    -  )
    -
    -  ## Show the first lines of the resulting data.frame
    -  head(tsQ)
    -}
    -
    -## Output
    -# t     Q
    -# 1 2011-08-24 22:27:00 1.061
    -# 2 2011-08-24 22:28:00 1.091
    -# 3 2011-08-24 22:29:00 1.115
    -# 4 2011-08-24 22:30:00 1.092
    -# 5 2011-08-24 22:31:00 1.086
    -# 6 2011-08-24 22:32:00 1.074
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsTables.html b/docs/dev/reference/hsTables.html deleted file mode 100644 index 8356357..0000000 --- a/docs/dev/reference/hsTables.html +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - -Available tables in database — hsTables • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a data.frame as returned by sqlTables, containing information on the -tables contained in the database. Opening of the database connection, -getting the list of tables and closing of the database connection is done -within this function.

    - -
    - -
    hsTables(mdb, excludeSystemTables = grepl("\\.(mdb|accdb)$", mdb),
    -  namesOnly = TRUE, use2007Driver = NULL, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    excludeSystemTables

    if TRUE (default), system tables are excluded from -the table list, else included.

    namesOnly

    if TRUE, only table names are returned. Default: TRUE

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    data.frame with columns TABLE_CAT, TABLE_SCHEM, - TABLE_NAME, TABLE_TYPE, REMARKS, see sqlTables of - RODBC package.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get names of tables in the example database
    -## (only on Windows)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tnames <- hsTables(xmdb(), namesOnly = TRUE)
    -
    -  ## Exclude system tables by filtering for table names
    -  ## not starting with '^MSys'
    -  tNonSys <- grep("^MSys", tnames, invert = TRUE, value = TRUE)
    -
    -  ## Print the names of the non-system tables.
    -  cat(paste(tNonSys, "\n"))
    -}
    -
    -## Ouput:
    -# tbl_Hyd
    -#  tbl_Qua
    -#  ...
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/hsTsField.html b/docs/dev/reference/hsTsField.html deleted file mode 100644 index 0b9cac9..0000000 --- a/docs/dev/reference/hsTsField.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - -Available timestamp-field(s) in database table — hsTsField • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Available timestamp-field(s) in database table

    - -
    - -
    hsTsField(src, tbl, namesOnly = TRUE, all = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    src

    source file (MS Access or Excel)

    tbl

    table name

    namesOnly

    if TRUE, only the name(s) of the timestamp field(s) is (are) -returned, otherwise additional information.

    all

    if TRUE, all timestamp fields are considiered, otherwise only the -first timestamp field.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/index.html b/docs/dev/reference/index.html deleted file mode 100644 index f989dd3..0000000 --- a/docs/dev/reference/index.html +++ /dev/null @@ -1,568 +0,0 @@ - - - - - - - - -Function reference • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -

    All functions

    -

    -
    -

    connectionStringAccess()

    -

    Connection String Access

    -

    createRDatabaseInterface()

    -

    Create R-Function Interface to Database

    -

    currentDb()

    -

    Get Path to or Name of Current Database

    -

    dataFrameToSqlTuples()

    -

    Create SQL Tuples from Data Frame

    -

    dumpDatabase()

    -

    Export Database Tables to CSV Files

    -

    getCurrentSqlDialect()

    -

    Get Current SQL Dialect

    -

    getDatabaseSchema()

    -

    Get Database Schema

    -

    getFilteredRecords()

    -

    Get Filtered Records

    -

    getNamedExcelRanges()

    -

    Get Named Ranges from Excel File

    -

    getSqlDialect()

    -

    Get SQL Dialect from Given Database

    -

    getTypeIdentifier()

    -

    Get Type Identifier

    -

    hsClearTable()

    -

    Clear a Database Table

    -

    hsCloseDb()

    -

    Close Connection to MS Access or Excel

    -

    hsCloseMdb()

    -

    Close Connection

    -

    hsDropTable()

    -

    Drop Database Table(s)

    -

    hsDumpMdb()

    -

    Export Database Tables to CSV Files

    -

    hsFields()

    -

    Available Fields in Database Table

    -

    hsGetTable()

    -

    Get Table from MS Access Database

    -

    hsGetTimeSeries()

    -

    Get Time Series With Timestamp Info

    -

    hsJetDate()

    -

    Date to “mm/dd/yyyy HH:MM:SS”

    -

    hsLookupOrAddRecord()

    -

    Lookup or Add Record

    -

    hsMdbTimeSeries()

    -

    Get Mdb time series in UTC

    -

    hsOpenDb()

    -

    Open Connection to MS Access or Excel

    -

    hsOpenMdb()

    -

    Open Connection to MS Access Database

    -

    hsPutTable()

    -

    Save Data Frame to Database Table

    -

    hsSetForeignKey()

    -

    Set Foreign Key for Table Field

    -

    hsSetPrimaryKey()

    -

    Set Primary Key of Database Table

    -

    hsSqlExAnd()

    -

    SQL Expression “AND”

    -

    hsSqlExOr()

    -

    SQL Expression “OR”

    -

    hsSqlExTimeCond()

    -

    SQL Expression: Time Period

    -

    hsSqlExTimeGroup()

    -

    SQL Expression: Time Grouping

    -

    hsSqlExTsFields()

    -

    SQL Expression: Timestamp Info

    -

    hsSqlQuery()

    -

    Send SQL Query to Database

    -

    hsTables()

    -

    Available tables in database

    -

    hsTsField()

    -

    Available timestamp-field(s) in database table

    -

    isExcel2003File()

    -

    Is this an XLS file?

    -

    isExcel2007File()

    -

    Is this an XLSX file?

    -

    isExcelFile()

    -

    Is this an Excel file?

    -

    isMySQL()

    -

    Is the Given Database of Type MySQL?

    -

    keyValueToSql()

    -

    Generate SQL Filter or Assignment Expression

    -

    keyValuesToSql()

    -

    List of Key = Value Pairs to SQL Expressions

    -

    keyValuesToSqlAssignment()

    -

    List of Key = Value Pairs to SQL Assignment

    -

    keyValuesToSqlAssignment2()

    -

    Key Values to SQL Assignment (2)

    -

    keyValuesToSqlFilter()

    -

    List of Key = Value Pairs to SQL Filter Expression

    -

    listValuesToSql()

    -

    Create SQL Tuples from a List

    -

    lookupRecord()

    -

    Lookup Record

    -

    openAdequateConnectionOrStop()

    -

    Open Adequate Connection or Stop

    -

    printDatabaseSchema()

    -

    Print Database Schema

    -

    rcode_DatabaseInterface()

    -

    R-code for Functions to Access Database Tables

    -

    readSqlCommandsFromFile()

    -

    Read SQL Commands from File

    -

    renamesToFieldList()

    -

    List of Renamings to Field Selection String

    -

    renamesToQueries()

    -

    List of Renamings to SQL Queries

    -

    runSqlCommandsFromFile()

    -

    Run SQL Commands from File

    -

    safeTableName()

    -

    Safe Table Name

    -

    selectFromDb()

    -

    Select from Database

    -

    selectFromTable()

    -

    Select from Table

    -

    setCurrentDb()

    -

    Set Current Database

    -

    setCurrentSqlDialect()

    -

    Set Current SQL Dialect

    -

    sqlForInsert()

    -

    Generate SQL INSERT statement

    -

    sqlForInsertDataFrame()

    -

    Generate SQL INSERT Statement

    -

    sqlForInsertFromSelect()

    -

    SQL for INSERT FROM SELECT

    -

    sqlForInsertIgnoreInMsAccess()

    -

    SQL for "INSERT IGNORE" in MS Access

    -

    sqlForSelect()

    -

    Generate SQL SELECT statement#'

    -

    sqlForSelectByKey()

    -

    Generate SQL SELECT Statement

    -

    sqlForUpdate()

    -

    Generate SQL UPDATE Statement

    -

    sqlFullLeftJoin()

    -

    Merge SQL Queries to One Query That Performs a Full Left Join

    -

    sqlJoinExpression()

    -

    Create an SQL JOIN Expression

    -

    sqlLeftJoin()

    -

    Generate SQL for LEFT JOIN

    -

    sqlLeftJoinBody()

    -

    Generate (Base Part of) SQL for LEFT JOIN

    -

    sqlLeftJoinExpression()

    -

    Create an SQL LEFT JOIN Expression

    -

    xmdb()

    -

    Path to example database

    -
    - - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/isExcel2003File.html b/docs/dev/reference/isExcel2003File.html deleted file mode 100644 index 3b7d114..0000000 --- a/docs/dev/reference/isExcel2003File.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - -Is this an XLS file? — isExcel2003File • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an XLS file?

    - -
    - -
    isExcel2003File(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xls -extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/isExcel2007File.html b/docs/dev/reference/isExcel2007File.html deleted file mode 100644 index aa0a35d..0000000 --- a/docs/dev/reference/isExcel2007File.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - -Is this an XLSX file? — isExcel2007File • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an XLSX file?

    - -
    - -
    isExcel2007File(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xlsx -extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/isExcelFile.html b/docs/dev/reference/isExcelFile.html deleted file mode 100644 index b2c675e..0000000 --- a/docs/dev/reference/isExcelFile.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - -Is this an Excel file? — isExcelFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an Excel file?

    - -
    - -
    isExcelFile(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xls -or .xlsx extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/isMySQL.html b/docs/dev/reference/isMySQL.html deleted file mode 100644 index 9a4db3b..0000000 --- a/docs/dev/reference/isMySQL.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - -Is the Given Database of Type MySQL? — isMySQL • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is the Given Database of Type MySQL?

    - -
    - -
    isMySQL(db, ...)
    - -

    Arguments

    - - - - - - - - - - -
    db

    database file (*.mdb, *.accdb, *.xls, *.xlsx) or name of ODBC -database

    arguments passed to hsOpenDb, e.g. -use2007Driver

    - -

    Value

    - -

    TRUE if db is a MySQL database, else FALSE

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/keyValueToSql.html b/docs/dev/reference/keyValueToSql.html deleted file mode 100644 index 600ea5a..0000000 --- a/docs/dev/reference/keyValueToSql.html +++ /dev/null @@ -1,173 +0,0 @@ - - - - - - - - -Generate SQL Filter or Assignment Expression — keyValueToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL Filter or Assignment Expression

    - -
    - -
    keyValueToSql(cname, cvalue, like = TRUE, filter = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    cname

    field name

    cvalue

    field value

    like

    if TRUE, the SQL comparison operator will be LIKE -instead of =.

    filter

    if TRUE an SQL filter expression is returned, otherwise -an SQL assignment expression

    - -

    Value

    - -

    (vector of) character representing an SQL expression

    - - -

    Examples

    -
    cat(kwb.db:::keyValueToSql("age", 1))
    #> age = 1
    cat(kwb.db:::keyValueToSql("name", "peter"))
    #> name LIKE "peter"
    cat(kwb.db:::keyValueToSql("name", "peter", like = FALSE))
    #> name = "peter"
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/keyValuesToSql.html b/docs/dev/reference/keyValuesToSql.html deleted file mode 100644 index 8caa330..0000000 --- a/docs/dev/reference/keyValuesToSql.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Expressions — keyValuesToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Expressions

    - -
    - -
    keyValuesToSql(keyValues, filter, like = filter)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    keyValues

    list of key = value pairs

    filter

    logical. If TRUE the target is an SQL filter expression, -otherwise an SQL SET expression.

    like

    passed to keyValueToSql

    - - -

    Examples

    -
    keyValues <- list(name = "Peter", birth = as.POSIXct("1999-09-09")) - -setCurrentSqlDialect("msaccess") -cat(keyValuesToSql(keyValues, filter = TRUE))
    #> name LIKE 'Peter' AND birth LIKE #1999-09-09#
    cat(keyValuesToSql(keyValues, filter = TRUE, like = FALSE))
    #> name = 'Peter' AND birth = #1999-09-09#
    cat(keyValuesToSql(keyValues, filter = FALSE))
    #> name = 'Peter',birth = #1999-09-09#
    -setCurrentSqlDialect("mysql") -cat(keyValuesToSql(keyValues, filter = TRUE))
    #> name LIKE "Peter" AND birth LIKE '1999-09-09'
    cat(keyValuesToSql(keyValues, filter = TRUE, like = FALSE))
    #> name = "Peter" AND birth = '1999-09-09'
    cat(keyValuesToSql(keyValues, filter = FALSE))
    #> name = "Peter",birth = '1999-09-09'
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/keyValuesToSqlAssignment.html b/docs/dev/reference/keyValuesToSqlAssignment.html deleted file mode 100644 index f46cfd7..0000000 --- a/docs/dev/reference/keyValuesToSqlAssignment.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Assignment — keyValuesToSqlAssignment • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Assignment

    - -
    - -
    keyValuesToSqlAssignment(keyValues)
    - -

    Arguments

    - - - - - - -
    keyValues

    list of key = value pairs

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/keyValuesToSqlAssignment2.html b/docs/dev/reference/keyValuesToSqlAssignment2.html deleted file mode 100644 index a3200a7..0000000 --- a/docs/dev/reference/keyValuesToSqlAssignment2.html +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - -Key Values to SQL Assignment (2) — keyValuesToSqlAssignment2 • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Key Values to SQL Assignment (2)

    - -
    - -
    keyValuesToSqlAssignment2(keyvalues)
    - -

    Arguments

    - - - - - - -
    keyvalues

    list of key = value pairs

    - -

    Value

    - -

    list with elements fieldList and valueList

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/keyValuesToSqlFilter.html b/docs/dev/reference/keyValuesToSqlFilter.html deleted file mode 100644 index 2d10d8e..0000000 --- a/docs/dev/reference/keyValuesToSqlFilter.html +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Filter Expression — keyValuesToSqlFilter • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Filter Expression

    - -
    - -
    keyValuesToSqlFilter(keyValues, like = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    keyValues

    list of key = value pairs

    like

    if TRUE, the SQL comparison operator will be LIKE -instead of =.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/listValuesToSql.html b/docs/dev/reference/listValuesToSql.html deleted file mode 100644 index 559918e..0000000 --- a/docs/dev/reference/listValuesToSql.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - - -Create SQL Tuples from a List — listValuesToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create SQL Tuples from a List

    - -
    - -
    listValuesToSql(x)
    - -

    Arguments

    - - - - - - -
    x

    a list defining key = value pairs

    - -

    Value

    - -

    vector of character strings each of which represents one assignment - in x

    - - -

    Examples

    -
    x <- list(name = "Peter", birthday = as.POSIXct("1981-12-13")) - -setCurrentSqlDialect("msaccess") -cat(listValuesToSql(x))
    #> 'Peter',#1981-12-13#
    -# Note that the representation of a date and time is different in MySQL -setCurrentSqlDialect("mysql") -cat(listValuesToSql(x))
    #> "Peter",'1981-12-13'
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/lookupRecord.html b/docs/dev/reference/lookupRecord.html deleted file mode 100644 index e3a65f7..0000000 --- a/docs/dev/reference/lookupRecord.html +++ /dev/null @@ -1,173 +0,0 @@ - - - - - - - - -Lookup Record — lookupRecord • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Looks up a record in a database table and returns the ID of the record or - NULL if the record does not exist.

    - -
    - -
    lookupRecord(db, tableName, keyAssignments, idField = hsFields(db,
    -  tableName)[1], dbg = FALSE, use2007Driver = NULL)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    full path to MS Access/Excel database or name of ODBC data source

    tableName

    name of table in which record is to be looked up

    keyAssignments

    key-value-assignments used to identify the record to be looked up. -The assignments are defined in forms of a list, e.g. list(key1 = "value1", -key2 = "value2").

    idField

    name of ID field, default: name of first table field

    dbg

    if TRUE, debug messages are shown

    use2007Driver

    passed to isMySQL

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/openAdequateConnectionOrStop.html b/docs/dev/reference/openAdequateConnectionOrStop.html deleted file mode 100644 index 9234d2d..0000000 --- a/docs/dev/reference/openAdequateConnectionOrStop.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - -Open Adequate Connection or Stop — openAdequateConnectionOrStop • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Open Adequate Connection or Stop

    - -
    - -
    openAdequateConnectionOrStop(db, use2007Driver = NULL, dbg = FALSE,
    -  DBMSencoding = "", ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE, debug messages are shown

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    further arguments passed to odbcConnectionAccess, -odbcConnectionExcel or odbcConnect

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/printDatabaseSchema.html b/docs/dev/reference/printDatabaseSchema.html deleted file mode 100644 index e6b1655..0000000 --- a/docs/dev/reference/printDatabaseSchema.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - -Print Database Schema — printDatabaseSchema • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Print Database Schema

    - -
    - -
    printDatabaseSchema(dbSchema)
    - -

    Arguments

    - - - - - - -
    dbSchema

    database schema as returned by -getDatabaseSchema

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/rcode_DatabaseInterface.html b/docs/dev/reference/rcode_DatabaseInterface.html deleted file mode 100644 index b1030b2..0000000 --- a/docs/dev/reference/rcode_DatabaseInterface.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - -R-code for Functions to Access Database Tables — rcode_DatabaseInterface • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    R-code for Functions to Access Database Tables

    - -
    - -
    rcode_DatabaseInterface(db = NULL, dbSchema = NULL,
    -  tableNamePattern = "", functionPrefix = "db_", pattern = "^",
    -  dbg = TRUE, sql.dbg = TRUE, create.create.functions = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    dbSchema

    database schema as returned by -getDatabaseSchema

    tableNamePattern

    pattern matching the names of tables/views for which -an accessor function is to be generated

    functionPrefix

    prefix to be given to each generated function. Default: -"db_"

    pattern

    pattern matching the part of the table name that will be -replaced with functionPrefix. Default: "^", i.e. the prefix will be -appended to the start of the table name

    dbg

    if TRUE, progress messages are shown during the creation of the -interface functions

    sql.dbg

    if TRUE, SQL strings used to access the database are shown -when calling the interface functions

    create.create.functions

    if TRUE, functions for creating new records in -the database tables are created

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/readSqlCommandsFromFile.html b/docs/dev/reference/readSqlCommandsFromFile.html deleted file mode 100644 index dadd206..0000000 --- a/docs/dev/reference/readSqlCommandsFromFile.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - -Read SQL Commands from File — readSqlCommandsFromFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Lines starting with "--" or "#" are ignored. SQL commands must be separated -by semicolon and end of line character (\n).

    - -
    - -
    readSqlCommandsFromFile(sqlScript)
    - -

    Arguments

    - - - - - - -
    sqlScript

    full path to file containing SQL commands

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/renamesToFieldList.html b/docs/dev/reference/renamesToFieldList.html deleted file mode 100644 index becdf28..0000000 --- a/docs/dev/reference/renamesToFieldList.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - -List of Renamings to Field Selection String — renamesToFieldList • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Convert a list of renamings to a field selection string that can be used as -fields argument in a call to kwb.db::hsGetTable

    - -
    - -
    renamesToFieldList(renames, source.in.brackets = TRUE,
    -  target.in.brackets = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    renames

    list of key = value pairs defining renamings from the keys to -the values

    source.in.brackets

    if TRUE (default) the source expressions -will be enclosed in square brackets: [source] AS <target>

    target.in.brackets

    if TRUE (default) the target names will be -enclosed in square brackets: <source> AS [target]

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/renamesToQueries.html b/docs/dev/reference/renamesToQueries.html deleted file mode 100644 index a05bf07..0000000 --- a/docs/dev/reference/renamesToQueries.html +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - -List of Renamings to SQL Queries — renamesToQueries • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Convert a list of renamings to a list of SQL queries each of which can be -used to select and rename the given fields from a database.

    - -
    - -
    renamesToQueries(renamesList)
    - -

    Arguments

    - - - - - - -
    renamesList

    list of renaming lists. A renaming list is a list of -key = value pairs defining renamings from the keys to the values.

    - -

    Value

    - -

    list of character each of which represents an SQL query

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/runSqlCommandsFromFile.html b/docs/dev/reference/runSqlCommandsFromFile.html deleted file mode 100644 index 61bc789..0000000 --- a/docs/dev/reference/runSqlCommandsFromFile.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - -Run SQL Commands from File — runSqlCommandsFromFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Run SQL Commands from File

    - -
    - -
    runSqlCommandsFromFile(db, sqlFile, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    db

    Full path to MS Access mdb file or ODBC database name

    sqlFile

    full path to file containing Ms Access SQL commands

    further arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/safeTableName.html b/docs/dev/reference/safeTableName.html deleted file mode 100644 index 2c3e9a3..0000000 --- a/docs/dev/reference/safeTableName.html +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - -Safe Table Name — safeTableName • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    MS Access: table name enclosed in brackets "[" and "]", else: table name -enclosed in backquotes "`"

    - -
    - -
    safeTableName(tableName, sqlDialect = getCurrentSqlDialect(warn = FALSE))
    - -

    Arguments

    - - - - - - - - - - -
    tableName

    name of table to be quoted

    sqlDialect

    one of c("mysql", "msaccess")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/selectFromDb.html b/docs/dev/reference/selectFromDb.html deleted file mode 100644 index 6cbaa76..0000000 --- a/docs/dev/reference/selectFromDb.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - -Select from Database — selectFromDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Select from Database

    - -
    - -
    selectFromDb(tableName, fields = "*", whereClause = "TRUE", odbc,
    -  dbg = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tableName

    name of database table from which to load data

    fields

    names of fields to be selected

    whereClause

    SQL WHERE condition string

    odbc

    database name or file

    dbg

    if TRUE, debug messages are shown

    additonal arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/selectFromTable.html b/docs/dev/reference/selectFromTable.html deleted file mode 100644 index d4d6a7f..0000000 --- a/docs/dev/reference/selectFromTable.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - - - -Select from Table — selectFromTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Select from Table

    - -
    - -
    selectFromTable(db, tableName, arguments, run = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    tableName

    name of table from which to read data

    arguments

    list with elements select, where, -orderBy and further elements starting with select_, -where_ and orderBy_, respectively

    run

    if TRUE (default) the SQL SELECT statement is run otherwise -returned as character string

    further arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/setCurrentDb.html b/docs/dev/reference/setCurrentDb.html deleted file mode 100644 index 0a273b7..0000000 --- a/docs/dev/reference/setCurrentDb.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - -Set Current Database — setCurrentDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set Current Database

    - -
    - -
    setCurrentDb(db)
    - -

    Arguments

    - - - - - - -
    db

    full path to MS Access database or ODBC database name

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/setCurrentSqlDialect.html b/docs/dev/reference/setCurrentSqlDialect.html deleted file mode 100644 index dfa7bfc..0000000 --- a/docs/dev/reference/setCurrentSqlDialect.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - -Set Current SQL Dialect — setCurrentSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set Current SQL Dialect

    - -
    - -
    setCurrentSqlDialect(dialectName)
    - -

    Arguments

    - - - - - - -
    dialectName

    one of "msaccess", "mysql"

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForInsert.html b/docs/dev/reference/sqlForInsert.html deleted file mode 100644 index 2e9a9cc..0000000 --- a/docs/dev/reference/sqlForInsert.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - -Generate SQL INSERT statement — sqlForInsert • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement

    - -
    - -
    sqlForInsert(tablename, fields, sqlSource,
    -  sourceAreValues = !grepl(sqlSource, "^SELECT"), ignore = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    field names, separated by comma

    sqlSource

    value tupels of form (value1.1, value1.2, value1.3, ...) -(value2.1, value2.2, value2.3, ...) ... or SQL SELECT statement providing -these tupels

    sourceAreValues

    if TRUE, sqlSource is expected to be an SQL -query providing data to be inserted -> no keyword VALUES in generated SQL -code

    ignore

    if TRUE the keyword IGNORE is inserted between INSERT and INTO -in the SQL statement -> no error will be given if data to insert already -exists

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForInsertDataFrame.html b/docs/dev/reference/sqlForInsertDataFrame.html deleted file mode 100644 index e249079..0000000 --- a/docs/dev/reference/sqlForInsertDataFrame.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - -Generate SQL INSERT Statement — sqlForInsertDataFrame • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement to insert values in a data frame

    - -
    - -
    sqlForInsertDataFrame(tablename, dataFrame, ignore = FALSE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    dataFrame

    data frame with column names representing table field names

    ignore

    if TRUE the keyword IGNORE is inserted between INSERT and INTO -in the SQL statement -> no error will be given if data to insert already -exists

    further arguments passed to sqlForInsert

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForInsertFromSelect.html b/docs/dev/reference/sqlForInsertFromSelect.html deleted file mode 100644 index 98fe814..0000000 --- a/docs/dev/reference/sqlForInsertFromSelect.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - -SQL for INSERT FROM SELECT — sqlForInsertFromSelect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement of the form INSERT INTO target.table (fields) - SELECT fields FROM source.table

    - -
    - -
    sqlForInsertFromSelect(target.table, source.table, fields)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    target.table

    name of target table

    source.table

    name of source table or SQL providing source data

    fields

    vector of character with field names

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForInsertIgnoreInMsAccess.html b/docs/dev/reference/sqlForInsertIgnoreInMsAccess.html deleted file mode 100644 index 06c3555..0000000 --- a/docs/dev/reference/sqlForInsertIgnoreInMsAccess.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - -SQL for "INSERT IGNORE" in MS Access — sqlForInsertIgnoreInMsAccess • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns SQL for inserting all records from table.source that are not yet - contained in table.target into table.target

    - -
    - -
    sqlForInsertIgnoreInMsAccess(db, table.source, table.target,
    -  uniqueFields = NA)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    table.source

    name of source table

    table.target

    name of target table

    uniqueFields

    names of unique fields

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForSelect.html b/docs/dev/reference/sqlForSelect.html deleted file mode 100644 index 3f6037e..0000000 --- a/docs/dev/reference/sqlForSelect.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - -Generate SQL SELECT statement#' — sqlForSelect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL SELECT statement#'

    - -
    - -
    sqlForSelect(tablename, fields = "*", whereClause = "TRUE",
    -  groupBy = "", orderBy = "", sqlDialect = getCurrentSqlDialect())
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    expression to select fields; field names are separated by comma -and alias names may be used, just as SQL accepts, e.g.: "tstamp as -myDateTime, parVal as myValue"; Default: "*"

    whereClause

    where condition; Default: "TRUE"

    groupBy

    GROUP BY-clause, Default: "" (no grouping)

    orderBy

    ORDER BY-clause, Default: "" (no sorting of results)

    sqlDialect

    one of c("mysql", "msaccess")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForSelectByKey.html b/docs/dev/reference/sqlForSelectByKey.html deleted file mode 100644 index 3bc3375..0000000 --- a/docs/dev/reference/sqlForSelectByKey.html +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - -Generate SQL SELECT Statement — sqlForSelectByKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL SELECT statement (key field values instead of where clause)

    - -
    - -
    sqlForSelectByKey(tablename, fields = "*", keyValues = NULL)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    expression to select fields; field names are separated by comma -and alias names may be used, just as SQL accepts, e.g.: "tstamp as -myDateTime, parVal as myValue"; Default: "*"

    keyValues

    list of "key=value" pairs with the keys being valid field -names of table

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlForUpdate.html b/docs/dev/reference/sqlForUpdate.html deleted file mode 100644 index 1fb9359..0000000 --- a/docs/dev/reference/sqlForUpdate.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - -Generate SQL UPDATE Statement — sqlForUpdate • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL UPDATE Statement

    - -
    - -
    sqlForUpdate(tablename, keyValues, whereClause, ignore = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    keyValues

    assignments as list of key=value pairs with the keys -representing valid fields of table tablename

    whereClause

    where condition

    ignore

    if TRUE the keyword IGNORE is inserted between UPDATE and INTO -in the SQL statement -> no error will be given if updating fails, e.g. -because of key constraints

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlFullLeftJoin.html b/docs/dev/reference/sqlFullLeftJoin.html deleted file mode 100644 index 87d5304..0000000 --- a/docs/dev/reference/sqlFullLeftJoin.html +++ /dev/null @@ -1,176 +0,0 @@ - - - - - - - - -Merge SQL Queries to One Query That Performs a Full Left Join — sqlFullLeftJoin • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Merge SQL Queries to One Query That Performs a Full Left Join

    - -
    - -
    sqlFullLeftJoin(sqls, key)
    - -

    Arguments

    - - - - - - - - - - -
    sqls

    list of SQL queries each of which is expected to contain an -attribute alias giving the alias name for the query

    key

    name of the primary key field, being selected in each SQL query -contained in sqls

    - -

    Value

    - -

    vector of character of length one representing the result of "left - join"-ing all sub-queries given in sqls

    - - -

    Examples

    -
    sql <- sqlFullLeftJoin(key = "id", list( - structure("SELECT id, field_1 from table_1", alias = "t1"), - structure("SELECT id, field_2, field_3 from table_2", alias = "t2"), - structure("SELECT id, field_4 from table_3", alias = "t3") -)) - -cat(sql)
    #> ( SELECT id, field_1 from table_1 AS t1 -#> LEFT JOIN SELECT id, field_2, field_3 from table_2 AS t2 -#> ON ( t1.id = t2.id ) ) -#> LEFT JOIN SELECT id, field_4 from table_3 AS t3 -#> ON ( t1.id = t3.id )
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlJoinExpression.html b/docs/dev/reference/sqlJoinExpression.html deleted file mode 100644 index 7105727..0000000 --- a/docs/dev/reference/sqlJoinExpression.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - -Create an SQL JOIN Expression — sqlJoinExpression • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create an SQL JOIN Expression

    - -
    - -
    sqlJoinExpression(left, right, condition, type = "INNER")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    left

    left part of JOIN (e.g. table name)

    right

    right part of JOIN (e.g. table name)

    condition

    condition

    type

    one of c("LEFT", "RIGHT", "INNER")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlLeftJoin.html b/docs/dev/reference/sqlLeftJoin.html deleted file mode 100644 index 6d00669..0000000 --- a/docs/dev/reference/sqlLeftJoin.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - -Generate SQL for LEFT JOIN — sqlLeftJoin • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL for LEFT JOIN

    - -
    - -
    sqlLeftJoin(sqlSource, tablesAndIDs, fields = "*")
    - -

    Arguments

    - - - - - - - - - - - - - - -
    sqlSource

    SQL of subquery that provides the "base" table on the left

    tablesAndIDs

    named character vector with the names representing the -names of the tables to be joined and the values representing the ID fields -of these tables

    fields

    fields to be selected

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlLeftJoinBody.html b/docs/dev/reference/sqlLeftJoinBody.html deleted file mode 100644 index 4b3a719..0000000 --- a/docs/dev/reference/sqlLeftJoinBody.html +++ /dev/null @@ -1,172 +0,0 @@ - - - - - - - - -Generate (Base Part of) SQL for LEFT JOIN — sqlLeftJoinBody • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate (Base Part of) SQL for LEFT JOIN

    - -
    - -
    sqlLeftJoinBody(leftSql, rightTable, id, idLeft = id, useAlias = (id !=
    -  idLeft), aliasName = "tbase")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    leftSql

    SQL of subquery that provides the "base" table on the left

    rightTable

    name of "right" table

    id

    name of ID field of "right" table (must correspond to a field -returned by leftSql)

    idLeft

    name of ID field of "left" table

    useAlias

    if TRUE, the alias given in aliasName is given to the -subquery leftSql. Default: FALSE

    aliasName

    alias name to be used if useAlias is TRUE. Default: -"tbase"

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/sqlLeftJoinExpression.html b/docs/dev/reference/sqlLeftJoinExpression.html deleted file mode 100644 index 3836617..0000000 --- a/docs/dev/reference/sqlLeftJoinExpression.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - -Create an SQL LEFT JOIN Expression — sqlLeftJoinExpression • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create an SQL LEFT JOIN Expression

    - -
    - -
    sqlLeftJoinExpression(left, right, condition)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    left

    left part of JOIN (e.g. table name)

    right

    right part of JOIN (e.g. table name)

    condition

    condition

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/dev/reference/xmdb.html b/docs/dev/reference/xmdb.html deleted file mode 100644 index 17b0699..0000000 --- a/docs/dev/reference/xmdb.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - -Path to example database — xmdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns full path to MS Access example database

    - -
    - -
    xmdb()
    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - diff --git a/docs/docsearch.css b/docs/docsearch.css deleted file mode 100644 index e5f1fe1..0000000 --- a/docs/docsearch.css +++ /dev/null @@ -1,148 +0,0 @@ -/* Docsearch -------------------------------------------------------------- */ -/* - Source: https://github.com/algolia/docsearch/ - License: MIT -*/ - -.algolia-autocomplete { - display: block; - -webkit-box-flex: 1; - -ms-flex: 1; - flex: 1 -} - -.algolia-autocomplete .ds-dropdown-menu { - width: 100%; - min-width: none; - max-width: none; - padding: .75rem 0; - background-color: #fff; - background-clip: padding-box; - border: 1px solid rgba(0, 0, 0, .1); - box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); -} - -@media (min-width:768px) { - .algolia-autocomplete .ds-dropdown-menu { - width: 175% - } -} - -.algolia-autocomplete .ds-dropdown-menu::before { - display: none -} - -.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { - padding: 0; - background-color: rgb(255,255,255); - border: 0; - max-height: 80vh; -} - -.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { - margin-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion { - padding: 0; - overflow: visible -} - -.algolia-autocomplete .algolia-docsearch-suggestion--category-header { - padding: .125rem 1rem; - margin-top: 0; - font-size: 1.3em; - font-weight: 500; - color: #00008B; - border-bottom: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { - float: none; - padding-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { - float: none; - width: auto; - padding: 0; - text-align: left -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content { - float: none; - width: auto; - padding: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content::before { - display: none -} - -.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { - padding-top: .75rem; - margin-top: .75rem; - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { - display: block; - padding: .1rem 1rem; - margin-bottom: 0.1; - font-size: 1.0em; - font-weight: 400 - /* display: none */ -} - -.algolia-autocomplete .algolia-docsearch-suggestion--title { - display: block; - padding: .25rem 1rem; - margin-bottom: 0; - font-size: 0.9em; - font-weight: 400 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--text { - padding: 0 1rem .5rem; - margin-top: -.25rem; - font-size: 0.8em; - font-weight: 400; - line-height: 1.25 -} - -.algolia-autocomplete .algolia-docsearch-footer { - width: 110px; - height: 20px; - z-index: 3; - margin-top: 10.66667px; - float: right; - font-size: 0; - line-height: 0; -} - -.algolia-autocomplete .algolia-docsearch-footer--logo { - background-image: url("data:image/svg+xml;utf8,"); - background-repeat: no-repeat; - background-position: 50%; - background-size: 100%; - overflow: hidden; - text-indent: -9000px; - width: 100%; - height: 100%; - display: block; - transform: translate(-8px); -} - -.algolia-autocomplete .algolia-docsearch-suggestion--highlight { - color: #FF8C00; - background: rgba(232, 189, 54, 0.1) -} - - -.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { - box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) -} - -.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { - background-color: rgba(192, 192, 192, .15) -} diff --git a/docs/docsearch.js b/docs/docsearch.js deleted file mode 100644 index b35504c..0000000 --- a/docs/docsearch.js +++ /dev/null @@ -1,85 +0,0 @@ -$(function() { - - // register a handler to move the focus to the search bar - // upon pressing shift + "/" (i.e. "?") - $(document).on('keydown', function(e) { - if (e.shiftKey && e.keyCode == 191) { - e.preventDefault(); - $("#search-input").focus(); - } - }); - - $(document).ready(function() { - // do keyword highlighting - /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ - var mark = function() { - - var referrer = document.URL ; - var paramKey = "q" ; - - if (referrer.indexOf("?") !== -1) { - var qs = referrer.substr(referrer.indexOf('?') + 1); - var qs_noanchor = qs.split('#')[0]; - var qsa = qs_noanchor.split('&'); - var keyword = ""; - - for (var i = 0; i < qsa.length; i++) { - var currentParam = qsa[i].split('='); - - if (currentParam.length !== 2) { - continue; - } - - if (currentParam[0] == paramKey) { - keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); - } - } - - if (keyword !== "") { - $(".contents").unmark({ - done: function() { - $(".contents").mark(keyword); - } - }); - } - } - }; - - mark(); - }); -}); - -/* Search term highlighting ------------------------------*/ - -function matchedWords(hit) { - var words = []; - - var hierarchy = hit._highlightResult.hierarchy; - // loop to fetch from lvl0, lvl1, etc. - for (var idx in hierarchy) { - words = words.concat(hierarchy[idx].matchedWords); - } - - var content = hit._highlightResult.content; - if (content) { - words = words.concat(content.matchedWords); - } - - // return unique words - var words_uniq = [...new Set(words)]; - return words_uniq; -} - -function updateHitURL(hit) { - - var words = matchedWords(hit); - var url = ""; - - if (hit.anchor) { - url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; - } else { - url = hit.url + '?q=' + escape(words.join(" ")); - } - - return url; -} diff --git a/docs/docsearch.json b/docs/docsearch.json deleted file mode 100644 index 257d5dc..0000000 --- a/docs/docsearch.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "index_name": "kwb_db", - "start_urls": [ - { - "url": "/index.html", - "selectors_key": "homepage", - "tags": [ - "homepage" - ] - }, - { - "url": "/reference", - "selectors_key": "reference", - "tags": [ - "reference" - ] - }, - { - "url": "/articles", - "selectors_key": "articles", - "tags": [ - "articles" - ] - } - ], - "stop_urls": [ - "/reference/$", - "/reference/index.html", - "/articles/$", - "/articles/index.html" - ], - "sitemap_urls": [ - "/sitemap.xml" - ], - "selectors": { - "homepage": { - "lvl0": { - "selector": ".contents h1", - "default_value": "kwb.db Home page" - }, - "lvl1": { - "selector": ".contents h2" - }, - "lvl2": { - "selector": ".contents h3", - "default_value": "Context" - }, - "lvl3": ".ref-arguments td, .ref-description", - "text": ".contents p, .contents li, .contents .pre" - }, - "reference": { - "lvl0": { - "selector": ".contents h1" - }, - "lvl1": { - "selector": ".contents .name", - "default_value": "Argument" - }, - "lvl2": { - "selector": ".ref-arguments th", - "default_value": "Description" - }, - "lvl3": ".ref-arguments td, .ref-description", - "text": ".contents p, .contents li" - }, - "articles": { - "lvl0": { - "selector": ".contents h1" - }, - "lvl1": { - "selector": ".contents .name" - }, - "lvl2": { - "selector": ".contents h2, .contents h3", - "default_value": "Context" - }, - "text": ".contents p, .contents li, .tempate-article .contents .pre" - } - }, - "selectors_exclude": [ - ".dont-index" - ], - "min_indexed_level": 2, - "custom_settings": { - "separatorsToIndex": "_", - "attributesToRetrieve": [ - "hierarchy", - "content", - "anchor", - "url", - "url_without_anchor" - ] - } -} diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 5bcc09e..0000000 --- a/docs/index.html +++ /dev/null @@ -1,204 +0,0 @@ - - - - - - - -Functions supporting data base access • kwb.db - - - - - - - - - - - -
    -
    - - - -
    -
    - - - - - - -
    - -

    This repository contains the R package kwb.db. The package provides functions that aim at simplifying the data transfer between databases and R. It is based on the RODBC package that gives access to databases that provide an ODBC interface. Databases may be Microsoft Access files, Microsoft Excel files or any other database that is registered as an ODBC data source on your local machine. See e.g. here for how to setup ODBC data sources in Windows.

    -
    -

    -Installation

    -

    Once you have the devtools package installed, you can install the package kwb.db like this:

    - -
    -
    -

    -Database Access in RODBC

    -

    With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the dabase connection.

    -
    -
    -

    -Database Access with this package

    -

    With the functions of this package it is not needed to open and close a database connection explicitly; this is done behind the scenes in the functions. Instead of a database connection the path to the database file needs to be passed to the functions as an argument.

    -

    The main functions are hsGetTable() and hsPutTable(). They transfer data from a database to a data frame in R and save data from a data frame in R into a new table in a database, respectively.

    -

    Use hsTables() to get a list of tables that are available in a database and hsFields() to get a list of table fields that are contained in a database table.

    -

    A general workflow could look like this:

    - -

    In each of the kwb.db::-function calls above a database connection is opened, a request to the database is sent and the connection is closed again. Thus, the user does not have to care about open database connections.

    -

    Take care when getting time series data from an MS Access database, see therefore hsMdbTimeSeries().

    -
    -
    -
    - - - -
    - - -
    - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - diff --git a/docs/link.svg b/docs/link.svg deleted file mode 100644 index 88ad827..0000000 --- a/docs/link.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/docs/pkgdown.css b/docs/pkgdown.css deleted file mode 100644 index 6ca2f37..0000000 --- a/docs/pkgdown.css +++ /dev/null @@ -1,232 +0,0 @@ -/* Sticky footer */ - -/** - * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ - * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css - * - * .Site -> body > .container - * .Site-content -> body > .container .row - * .footer -> footer - * - * Key idea seems to be to ensure that .container and __all its parents__ - * have height set to 100% - * - */ - -html, body { - height: 100%; -} - -body > .container { - display: flex; - height: 100%; - flex-direction: column; - - padding-top: 60px; -} - -body > .container .row { - flex: 1 0 auto; -} - -footer { - margin-top: 45px; - padding: 35px 0 36px; - border-top: 1px solid #e5e5e5; - color: #666; - display: flex; - flex-shrink: 0; -} -footer p { - margin-bottom: 0; -} -footer div { - flex: 1; -} -footer .pkgdown { - text-align: right; -} -footer p { - margin-bottom: 0; -} - -img.icon { - float: right; -} - -img { - max-width: 100%; -} - -/* Typographic tweaking ---------------------------------*/ - -.contents h1.page-header { - margin-top: calc(-60px + 1em); -} - -/* Section anchors ---------------------------------*/ - -a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; - - background-image: url(./link.svg); - background-repeat: no-repeat; - background-size: 20px 20px; - background-position: center center; -} - -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } -} - - -/* Fixes for fixed navbar --------------------------*/ - -.contents h1, .contents h2, .contents h3, .contents h4 { - padding-top: 60px; - margin-top: -40px; -} - -/* Static header placement on mobile devices */ -@media (max-width: 767px) { - .navbar-fixed-top { - position: absolute; - } - .navbar { - padding: 0; - } -} - - -/* Sidebar --------------------------*/ - -#sidebar { - margin-top: 30px; -} -#sidebar h2 { - font-size: 1.5em; - margin-top: 1em; -} - -#sidebar h2:first-child { - margin-top: 0; -} - -#sidebar .list-unstyled li { - margin-bottom: 0.5em; -} - -.orcid { - height: 16px; - vertical-align: middle; -} - -/* Reference index & topics ----------------------------------------------- */ - -.ref-index th {font-weight: normal;} - -.ref-index td {vertical-align: top;} -.ref-index .alias {width: 40%;} -.ref-index .title {width: 60%;} - -.ref-index .alias {width: 40%;} -.ref-index .title {width: 60%;} - -.ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top;} -.ref-arguments .name {width: 20%;} -.ref-arguments .desc {width: 80%;} - -/* Nice scrolling for wide elements --------------------------------------- */ - -table { - display: block; - overflow: auto; -} - -/* Syntax highlighting ---------------------------------------------------- */ - -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { - background-color: #f8f8f8; - color: #333; -} - -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; -} - -pre .img { - margin: 5px 0; -} - -pre .img img { - background-color: #fff; - display: block; - height: auto; -} - -code a, pre a { - color: #375f84; -} - -a.sourceLine:hover { - text-decoration: none; -} - -.fl {color: #1514b5;} -.fu {color: #000000;} /* function */ -.ch,.st {color: #036a07;} /* string */ -.kw {color: #264D66;} /* keyword */ -.co {color: #888888;} /* comment */ - -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} - -/* Clipboard --------------------------*/ - -.hasCopyButton { - position: relative; -} - -.btn-copy-ex { - position: absolute; - right: 0; - top: 0; - visibility: hidden; -} - -.hasCopyButton:hover button.btn-copy-ex { - visibility: visible; -} - -/* mark.js ----------------------------*/ - -mark { - background-color: rgba(255, 255, 51, 0.5); - border-bottom: 2px solid rgba(255, 153, 51, 0.3); - padding: 1px; -} - -/* vertical spacing after htmlwidgets */ -.html-widget { - margin-bottom: 10px; -} diff --git a/docs/pkgdown.js b/docs/pkgdown.js deleted file mode 100644 index de9bd72..0000000 --- a/docs/pkgdown.js +++ /dev/null @@ -1,110 +0,0 @@ -/* http://gregfranko.com/blog/jquery-best-practices/ */ -(function($) { - $(function() { - - $("#sidebar") - .stick_in_parent({offset_top: 40}) - .on('sticky_kit:bottom', function(e) { - $(this).parent().css('position', 'static'); - }) - .on('sticky_kit:unbottom', function(e) { - $(this).parent().css('position', 'relative'); - }); - - $('body').scrollspy({ - target: '#sidebar', - offset: 60 - }); - - $('[data-toggle="tooltip"]').tooltip(); - - var cur_path = paths(location.pathname); - var links = $("#navbar ul li a"); - var max_length = -1; - var pos = -1; - for (var i = 0; i < links.length; i++) { - if (links[i].getAttribute("href") === "#") - continue; - var path = paths(links[i].pathname); - - var length = prefix_length(cur_path, path); - if (length > max_length) { - max_length = length; - pos = i; - } - } - - // Add class to parent
  • , and enclosing
  • if in dropdown - if (pos >= 0) { - var menu_anchor = $(links[pos]); - menu_anchor.parent().addClass("active"); - menu_anchor.closest("li.dropdown").addClass("active"); - } - }); - - function paths(pathname) { - var pieces = pathname.split("/"); - pieces.shift(); // always starts with / - - var end = pieces[pieces.length - 1]; - if (end === "index.html" || end === "") - pieces.pop(); - return(pieces); - } - - function prefix_length(needle, haystack) { - if (needle.length > haystack.length) - return(0); - - // Special case for length-0 haystack, since for loop won't run - if (haystack.length === 0) { - return(needle.length === 0 ? 1 : 0); - } - - for (var i = 0; i < haystack.length; i++) { - if (needle[i] != haystack[i]) - return(i); - } - - return(haystack.length); - } - - /* Clipboard --------------------------*/ - - function changeTooltipMessage(element, msg) { - var tooltipOriginalTitle=element.getAttribute('data-original-title'); - element.setAttribute('data-original-title', msg); - $(element).tooltip('show'); - element.setAttribute('data-original-title', tooltipOriginalTitle); - } - - if(Clipboard.isSupported()) { - $(document).ready(function() { - var copyButton = ""; - - $(".examples, div.sourceCode").addClass("hasCopyButton"); - - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); - - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); - - // Initialize clipboard: - var clipboardBtnCopies = new Clipboard('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent; - } - }); - - clipboardBtnCopies.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); - - clipboardBtnCopies.on('error', function() { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); - }); - } -})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml deleted file mode 100644 index 7908647..0000000 --- a/docs/pkgdown.yml +++ /dev/null @@ -1,5 +0,0 @@ -pandoc: 2.2.1 -pkgdown: 1.1.0 -pkgdown_sha: ~ -articles: [] - diff --git a/docs/reference/connectionStringAccess.html b/docs/reference/connectionStringAccess.html deleted file mode 100644 index b93f97c..0000000 --- a/docs/reference/connectionStringAccess.html +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - -Connection String Access — connectionStringAccess • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Connection String Access

    - -
    - -
    connectionStringAccess(mdb, uid = "", pwd = "",
    -  globalPartialBulkOps = 0)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access file

    uid

    user id, if any

    pwd

    password, if any

    globalPartialBulkOps

    A Long value (read/write) that determines the -behavior of the Jet database engine when SQL DML bulk operations fail. When -set to allow partial completion of bulk operations, inconsistent changes -can occur, because operations on some records could succeed and others -could fail. When set to allow no partial completion of bulk operations, all -changes are rolled back if a single error occurs. The Jet OLEDB:Global -Partial Bulk Ops property setting can be overridden for the current -Recordset object by setting the Jet OLEDB:Partial Bulk Ops property.The Jet -OLEDB:Global Partial Bulk Ops and Jet OLEDB:Partial Bulk Ops properties can -be set to any of the following values: Default = 0, Partial = 1, No Partial -= 2

    - -

    References

    - -

    http://msdn.microsoft.com/en-us/library/office/aa140022%28v=office.10%29.aspx

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/createRDatabaseInterface.html b/docs/reference/createRDatabaseInterface.html deleted file mode 100644 index 7e0a608..0000000 --- a/docs/reference/createRDatabaseInterface.html +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - -Create R-Function Interface to Database — createRDatabaseInterface • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create R-Function Interface to Database

    - -
    - -
    createRDatabaseInterface(db = NULL, dbSchema = NULL,
    -  tableNamePattern = "", functionPrefix = "db_", pattern = "^",
    -  rfile = file.path(tempdir(), "dbInterface.R"),
    -  rfile.create = file.path(tempdir(), "dbInterfaceCreate.R"),
    -  create.create.functions = FALSE, dbg = TRUE, sql.dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    name of ODBC data source or full path to MS Access or Excel file

    dbSchema

    list structure describing the database schema, as returned by -kwb.odm::dbSchema_ODM()

    tableNamePattern

    pattern matching the names of tables/views for which -an accessor function is to be generated

    functionPrefix

    prefix to be given to each generated function. Default: -"db_"

    pattern

    pattern matching the part of the table name that will be -replaced with functionPrefix. Default: "^", i.e. the prefix will be -appended to the start of the table name

    rfile

    full path to the file in which to store the data access -functions

    rfile.create

    full path to the file in which to store the data creation -functions (only relevant if crete.create.functions is TRUE)

    create.create.functions

    logical. If TRUE (the default if FALSE) not -only data access but also data creation functions are generated

    dbg

    if TRUE, progress messages are shown during the creation of the -interface functions

    sql.dbg

    if TRUE, SQL strings used to access the database are shown -when calling the interface functions

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/currentDb.html b/docs/reference/currentDb.html deleted file mode 100644 index 5ab337a..0000000 --- a/docs/reference/currentDb.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - -Get Path to or Name of Current Database — currentDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Path to or name of current database (as set with -setCurrentDb)

    - -
    - -
    currentDb(dbg = TRUE)
    - -

    Arguments

    - - - - - - -
    dbg

    if TRUE, a message obout setting the current database is printed

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/dataFrameToSqlTuples.html b/docs/reference/dataFrameToSqlTuples.html deleted file mode 100644 index 1fac5da..0000000 --- a/docs/reference/dataFrameToSqlTuples.html +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - -Create SQL Tuples from Data Frame — dataFrameToSqlTuples • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create SQL Tuples from Data Frame

    - -
    - -
    dataFrameToSqlTuples(newData)
    - -

    Arguments

    - - - - - - -
    newData

    a data frame

    - -

    Value

    - -

    vector of character strings each of which represents one row in - newData

    - - -

    Examples

    -
    x <- data.frame( - name = c("Peter", "Paul"), - birthday = as.POSIXct(c("1981-12-13", "2003-01-16")) -) - -setCurrentSqlDialect("msaccess") -dataFrameToSqlTuples(x)
    #> [1] "(Peter,#1981-12-13#)" "(Paul,#2003-01-16#)"
    -# Note that the representation of a date and time is different in MySQL -setCurrentSqlDialect("mysql") -dataFrameToSqlTuples(x)
    #> [1] "(Peter,'1981-12-13')" "(Paul,'2003-01-16')"
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/getCurrentSqlDialect.html b/docs/reference/getCurrentSqlDialect.html deleted file mode 100644 index f998fb8..0000000 --- a/docs/reference/getCurrentSqlDialect.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - -Get Current SQL Dialect — getCurrentSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Current SQL Dialect

    - -
    - -
    getCurrentSqlDialect(warn = TRUE, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    warn

    if TRUE and if no current SQL dialog is stored in the options, -the program stops with an error message

    dbg

    if TRUE, a message about the current SQL dialect is printed

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/getDatabaseSchema.html b/docs/reference/getDatabaseSchema.html deleted file mode 100644 index 4de736a..0000000 --- a/docs/reference/getDatabaseSchema.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - -Get Database Schema — getDatabaseSchema • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Database Schema

    - -
    - -
    getDatabaseSchema(db)
    - -

    Arguments

    - - - - - - -
    db

    full path to database (*.mdb, *.xls) or name of ODBC database

    - -

    Value

    - -

    list with elements tables and relationships. Element - tables is a list o named elements with the name representing the - table names and the elements being lists describing the table...

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/getFilteredRecords.html b/docs/reference/getFilteredRecords.html deleted file mode 100644 index 8820653..0000000 --- a/docs/reference/getFilteredRecords.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - -Get Filtered Records — getFilteredRecords • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Filtered Records

    - -
    - -
    getFilteredRecords(db, tableName, keyValues, fields, like, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or database file

    tableName

    name of the table from which to read records

    keyValues

    list of key = value pairs with the keys representing -field names of the table tableName, defining filter criteria

    fields

    table fields to be selected

    like

    if TRUE the SQL LIKE operator is used instead of -the equal operator = when matching the values in keyValues -with the table fields

    additonal arguments passed to selectFromDb

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/getSqlDialect.html b/docs/reference/getSqlDialect.html deleted file mode 100644 index 5ff7a92..0000000 --- a/docs/reference/getSqlDialect.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - -Get SQL Dialect from Given Database — getSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    get SQL dialect ("mysql" or "msaccess") from given database

    - -
    - -
    getSqlDialect(db, use2007Driver = NULL)
    - -

    Arguments

    - - - - - - - - - - -
    db

    ODBC database name or full path to database (mdb or xls)

    use2007Driver

    passed to isMySQL

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/getTypeIdentifier.html b/docs/reference/getTypeIdentifier.html deleted file mode 100644 index 270626d..0000000 --- a/docs/reference/getTypeIdentifier.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - -Get Type Identifier — getTypeIdentifier • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get Type Identifier

    - -
    - -
    getTypeIdentifier(x)
    - -

    Arguments

    - - - - - - -
    x

    R object for which to find an adequate database object type

    - -

    Value

    - -

    Returns "int", "double", "text", "date_time" or "boolean" depending - on the data type of x

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsClearTable.html b/docs/reference/hsClearTable.html deleted file mode 100644 index 1084022..0000000 --- a/docs/reference/hsClearTable.html +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - - -Clear a Database Table — hsClearTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deletes all the rows of the table \(tbl\). This function performs opening -of the connection, clearing of the table and closing of the connection. If -an error occurs the program stops and an error description is shown.

    - -
    - -
    hsClearTable(mdb, tbl, cond = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database (*.mdb).

    tbl

    table name.

    cond

    optional: condition.

    additional arguments passed to hsSqlQuery, e.g. "errors=TRUE"

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsCloseDb.html b/docs/reference/hsCloseDb.html deleted file mode 100644 index 0d3c0f6..0000000 --- a/docs/reference/hsCloseDb.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - -Close Connection to MS Access or Excel — hsCloseDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Closes the database connection.

    - -
    - -
    hsCloseDb(con)
    - -

    Arguments

    - - - - - - -
    con

    Open database connection as returned by -hsOpenDb/odbcConnect

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsCloseMdb.html b/docs/reference/hsCloseMdb.html deleted file mode 100644 index 4fffdf4..0000000 --- a/docs/reference/hsCloseMdb.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - -Close Connection — hsCloseMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deprecated. Use codehsCloseDb instead.

    - -
    - -
    hsCloseMdb(con)
    - -

    Arguments

    - - - - - - -
    con

    Open database connection as returned by -hsOpenMdb/odbcConnect

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsDropTable.html b/docs/reference/hsDropTable.html deleted file mode 100644 index 5c957ad..0000000 --- a/docs/reference/hsDropTable.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - -Drop Database Table(s) — hsDropTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Removes the table \(tbl\) (if permitted). This function performs opening of -the connection, dropping of the table and closing of the connection. If an -error occurs the program stops and an error description is shown.

    - -
    - -
    hsDropTable(mdb, tbl, isPtrn = FALSE, dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database (*.mdb).

    tbl

    table name.

    isPtrn

    if TRUE, tbl is interpreted as a regular expression -matching the names of the tables to be deleted.

    dbg

    if TRUE, debug messages are shown

    - -

    See also

    - - - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsDumpMdb.html b/docs/reference/hsDumpMdb.html deleted file mode 100644 index a5d902c..0000000 --- a/docs/reference/hsDumpMdb.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - -Export Database Tables to CSV Files — hsDumpMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Exports all tables of a database of which the names match a given pattern to -csv files.

    - -
    - -
    hsDumpMdb(mdb, ptrn = "^tbl", tdir = file.path(dirname(mdb),
    -  gsub("\\.", "_", basename(mdb))))
    - -

    Arguments

    - - - - - - - - - - - - - - -
    mdb

    full path to database

    ptrn

    pattern matching names of tables to be exported. Default: "^tbl", -i.e. tables starting with "tbl"

    tdir

    target directory. By default a new directory is created in the -same directory as mdb resides in. The new directory has the same name as -the database file with dots substituted with underscores

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsFields.html b/docs/reference/hsFields.html deleted file mode 100644 index 4301b6f..0000000 --- a/docs/reference/hsFields.html +++ /dev/null @@ -1,242 +0,0 @@ - - - - - - - - -Available Fields in Database Table — hsFields • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a vector containing the field names of a database table.

    - -
    - -
    hsFields(mdb, tbl, namesOnly = TRUE, chopDollar = TRUE,
    -  ignore.case = (!isMySQL(mdb, use2007Driver = use2007Driver)),
    -  use2007Driver = NULL, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    tbl

    table name.

    namesOnly

    if TRUE, only field names are returned, otherwise all -available information on the fields. Default: TRUE

    chopDollar

    if TRUE (default), a dollar sign at the end of the table -name is removed before sending it to sqlColumns,

    ignore.case

    if TRUE, case is ignored when comparing the given table -with the names of the existing tables. Default: FALSE

    use2007Driver

    passed to isMySQL

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    Vector containing the field names of the database table (if namesOnly - = TRUE) or data.frame with columns COLUMN_NAME, DATA_TYPE, - TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, - DECIMAL_DIGITS, NUM_PREC_RADIX, NULLABLE describing - the database fields in detail, otherwise.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## List the fields of table "tbl_Hyd" in the example database
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -  setCurrentSqlDialect("msaccess")
    -  fields <- hsFields(xmdb(), "tbl_Hyd")
    -  fields
    -}
    -
    -## Ouput:
    -# [1] "Zeitst"  "Q"       "v"       "H"       "T_Kanal"
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsGetTable.html b/docs/reference/hsGetTable.html deleted file mode 100644 index 524080b..0000000 --- a/docs/reference/hsGetTable.html +++ /dev/null @@ -1,303 +0,0 @@ - - - - - - - - -Get Table from MS Access Database — hsGetTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Provides data from an MS Access database table in forms of a data frame.

    - -
    - -
    hsGetTable(mdb, tbl, cond = "TRUE", fields = "*", dbg = TRUE,
    -  check = TRUE, use2007Driver = NULL, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    tbl

    Table name. Put it into brackets [] if it contains spaces and if -it mdb does not point to a MySQL database

    cond

    Condition string.

    fields

    Comma separated list of names of fields to be selected.

    dbg

    if TRUE, debug messages are shown, else not

    check

    if TRUE (default), tbl is checked for existence in -mdb before trying to get the data and a list of available tables is -shown in the case that the table does not exist.

    use2007Driver

    passed to hsTables and -hsSqlQuery

    Additional arguments to be passed to hsSqlQuery

    - -

    Value

    - -

    data.frame containing data from table in database

    - -

    Details

    - -

    ATTENTION: This function may not return what you want if the table contains a -timestamp field. Use hsMdbTimeSeries instead.

    - -

    See also

    - -

    hsSqlQuery, hsPutTable, hsGetTimeSeries, - hsMdbTimeSeries

    - - -

    Examples

    -
    # NOT RUN {
    -## Get all datasets from tbl_Hyd in example database where
    -## Q > 1.0 m3/s and temperature > 20 degree Celsius
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -  ts <- hsGetTable(xmdb(), "tbl_Hyd", "Q > 1.0 AND T_Kanal > 20")
    -  head(ts)
    -}
    -
    -## Output:
    -# Zeitst     Q     v     H T_Kanal
    -# 1 2011-08-24 22:33:00 1.075 0.459 1.366    20.1
    -# 2 2011-08-24 22:34:00 1.062 0.453 1.370    20.2
    -# 3 2011-08-24 22:35:00 1.050 0.449 1.364    20.2
    -# 4 2011-08-24 22:36:00 1.042 0.446 1.361    20.3
    -# 5 2011-08-24 22:37:00 1.032 0.443 1.354    20.3
    -# 6 2011-08-24 22:38:00 1.010 0.436 1.348    20.4
    -
    -## TAKE CARE when getting time-series data:
    -if (.Platform$OS.type == "windows") {
    -  hsGetTable(xmdb(), "tblTimestampTest_DST")
    -}
    -
    -## Output:
    -#                tstamp
    -# 1 2011-03-27 01:00:00
    -# 2 2011-03-27 01:30:00
    -# 3                <NA>
    -# 4                <NA>
    -# 5 2011-03-27 03:00:00
    -# 6 2011-03-27 03:30:00
    -
    -## As the output shows the timestamps between 02:00:00 and
    -## 02:59:59 have been set to <NA>. Reason: When retrieving
    -## date/time data from MS Access, R converts the timestamps
    -## from a text representation into POSIXct objects. As POSIXct's
    -## standard time zone seems to be taken from the Windows system
    -## R tries to convert to Central European Time (CET) which
    -## does not exist for the hour in which time is switched to
    -## daylight-saving time (as in the example).
    -
    -## This standard behaviour can be changed by setting the
    -## standard time zone:
    -tz <- Sys.getenv("tz") # save current standard time zone
    -Sys.setenv(tz = "UTC") # set standard time zone to UTC
    -
    -## The same command as above now delivers all timestamps
    -## (in Coordinated Universal Time, UTC):
    -
    -if (.Platform$OS.type == "windows") {
    -  hsGetTable(xmdb(), "tblTimestampTest_DST")
    -}
    -
    -## Output:
    -#                tstamp
    -# 1 2011-03-27 01:00:00
    -# 2 2011-03-27 01:30:00
    -# 3 2011-03-27 02:00:00
    -# 4 2011-03-27 02:30:00
    -# 5 2011-03-27 03:00:00
    -# 6 2011-03-27 03:30:00
    -
    -## Reset standard time zone
    -Sys.setenv(tz = tz)
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsGetTimeSeries.html b/docs/reference/hsGetTimeSeries.html deleted file mode 100644 index e658754..0000000 --- a/docs/reference/hsGetTimeSeries.html +++ /dev/null @@ -1,314 +0,0 @@ - - - - - - - - -Get Time Series With Timestamp Info — hsGetTimeSeries • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Reads time-series data from an MS Access database table and returns a data -frame containing the data. In the data frame the timestamp column contains -the timestamps as they are converted to by R from (text versions of) the -original timestamps read from MS ACCESS. As this conversion may fail (e.g. -the time information gets lost when transferring timestamps from large data -sets between R and MS Access) this function may return different pieces of -information on the timestamp in forms of additional columns, preceding the -timestamp column, in the result data frame. Per default, eleven additional -columns are returned: 1. <ts>_txt (timestamp as text), 2. <ts>_Date (date -only), 3. <ts>_dSince18991230 (number of days since 1899-12-30), 4. -<ts>_secInDay (number of seconds within the day), 5. <ts>_minInDay (number of -minutes within the day), 6. <ts>_year (year), 7. <ts>_month (number of -month), 8. <ts>_day (number of day within the month), 9. <ts>_h (hours within -day), 10. <ts>_min (minutes within hour), 11. <ts>_s (seconds within minute) -where in each case <ts> is the name of the timestamp field.

    - -
    - -
    hsGetTimeSeries(mdb, tbl, tsField = hsTsField(mdb, tbl), fields = "*",
    -  minDate = NULL, maxDate = NULL, xTsFields = c(1:11),
    -  inclLast = TRUE, sqlFilter = "TRUE", dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb)

    tbl

    Name of table containing the time-series data.

    tsField

    Name of table field containing the timestamps.

    fields

    Vector containing names of value fields to be selected from the -table. This vector may or may not contain the name of the timetamp field.

    minDate

    Minimum date (and time) of time interval to be selected in -ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets in optional.

    maxDate

    Day following the maximum date of the time interval to be -selected, in ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets -in optional.

    xTsFields

    Extra timestamp fields to be selected. Vector containing -numbers between 1 and 11, where each number represents a type of date/time -information as described for function hsSqlExTsFields.

    inclLast

    If TRUE, maxDate will be included in result data set, -else excluded.

    sqlFilter

    additional SQL filter criterion

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    data frame containing the requested data (timestamp and value - columns) and additional columns preceding the timestamp column containing - different pieces of information on the timestamp.

    - -

    Details

    - -

    This function is called internally by the higher-level function -hsMdbTimeSeries that reconstructs the correct timestamps from -the different pieces of timestamp information and provides them in forms of -POSIXct objects in UTC timezone.

    -

    Use hsMdbTimeSeries instead if you do not want to care about -any timestamp conversion problems!

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get flow time series of 24 of July 2011 from tbl_Hyd in example database
    -## Additionally to the timestamp that is created by R, return the date only
    -## (timestamp info id = 2) and the number of minutes within the day
    -## (timestamp info id = 5).
    -
    -setCurrentSqlDialect("msaccess")
    -
    -if (.Platform$OS.type == "windows") {
    -  ts <- hsGetTimeSeries(
    -    mdb = xmdb(),
    -    tbl = "tbl_Hyd",
    -    tsField = "Zeitst",
    -    fields = c("Q", "v"),
    -    minDate = "2011-08-24",
    -    maxDate = "2011-08-25",
    -    xTsFields = c(2, 5),
    -    dbg = TRUE
    -  )
    -
    -  ## Show the last records of the returned dataset.
    -  tail(ts)
    -}
    -
    -## Output:
    -#      Zeitst_Date Zeitst_minInDay              Zeitst     Q     v
    -# 1435  2011-08-24            1435 2011-08-24 23:55:00 0.638 0.281
    -# 1436  2011-08-24            1436 2011-08-24 23:56:00 0.601 0.265
    -# 1437  2011-08-24            1437 2011-08-24 23:57:00 0.564 0.249
    -# 1438  2011-08-24            1438 2011-08-24 23:58:00 0.536 0.237
    -# 1439  2011-08-24            1439 2011-08-24 23:59:00 0.504 0.223
    -# 1440  2011-08-25               0 2011-08-25 00:00:00 0.483 0.214
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsJetDate.html b/docs/reference/hsJetDate.html deleted file mode 100644 index 38fc388..0000000 --- a/docs/reference/hsJetDate.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - -Date to “mm/dd/yyyy HH:MM:SS” — hsJetDate • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a date in MS Jet SQL syntax: mm/dd/yyyy HH:MM:SS

    - -
    - -
    hsJetDate(datetime, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    datetime

    Date (and time) information in forms of Date object or POSIX -object or string.

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsLookupOrAddRecord.html b/docs/reference/hsLookupOrAddRecord.html deleted file mode 100644 index 3015c46..0000000 --- a/docs/reference/hsLookupOrAddRecord.html +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - -Lookup or Add Record — hsLookupOrAddRecord • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Looks up a record in a database table and returns the ID of the record. If -the record is not found it is inserted to the table and the ID of the new -record is returned.

    - -
    - -
    hsLookupOrAddRecord(mdb, tbl, keyAssigns, fieldAssigns = NULL,
    -  idField = hsFields(mdb, tbl)[1], dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database

    tbl

    name of table in which record is to be looked up

    keyAssigns

    key-value-assignements used to identify the record to be -looked up. The assignments are defined in forms of a list, e.g. list(key1 = -"value1", key2 = "value2").

    fieldAssigns

    further field-value-assignements used when a new record -needs to be inserted. The assignments are defined in forms of a list, e.g. -list(field1 = "value1", field2 = "value2").

    idField

    name of ID field, default: name of first table field

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsMdbTimeSeries.html b/docs/reference/hsMdbTimeSeries.html deleted file mode 100644 index 6d07bac..0000000 --- a/docs/reference/hsMdbTimeSeries.html +++ /dev/null @@ -1,286 +0,0 @@ - - - - - - - - -Get Mdb time series in UTC — hsMdbTimeSeries • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Reads time-series data from an MS Access database table and returns a data -frame containing the data. The name of the timestamp field must be given in -tsField and the names of the value fields to be selected from the -table must be given in vector fields. Instead of an ODBC channel the -name of the database must be given. This function takes care that the -timestamps are transferred correctly between MS Access and R by requesting -date and time information separately from MS Access and putting both together -to a POSIXct object in UTC timezone. This is necessary because with very long -data sets the RODBC function sqlQuery (or the function -hsSqlQuery that calls this function) may deliver timestamps in -which time information is lacking!

    - -
    - -
    hsMdbTimeSeries(mdb, tbl, tsField = hsTsField(mdb, tbl), fields = "*",
    -  minDate = NULL, maxDate = NULL, resolution = "min",
    -  inclLast = TRUE, sqlFilter = "TRUE", dbg = FALSE, calcType = 1)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb)

    tbl

    Name of table containing the time-series data.

    tsField

    Name of table field containing the timestamps.

    fields

    Vector containing names of value fields to be selected from the -table. This vector may or may not contain the name of the timetamp field.

    minDate

    Minimum date (and time) of time interval to be selected in -ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets in optional.

    maxDate

    Day following the maximum date of the time interval to be -selected, in ISO-Syntax: yyyy-mm-dd [HH:MM:SS], where the part in brackets -in optional.

    resolution

    time resolution: “min” = minutes, “s” = -seconds. If time resolution is “min” timestamps are rounded to the -next full minute.

    inclLast

    If TRUE, maxDate will be included in result data set, -else excluded.

    sqlFilter

    additional SQL filter criterion

    dbg

    if TRUE, debug messages are shown

    calcType

    for internal use only, do not change!

    - -

    Value

    - -

    data.frame with POSIXct timestamp column <strTimestamp> (UTC time - zone) and value columns as selected in <strFieldList>

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get flow time series of 24 of August 2011 from tbl_Hyd in example database
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  ts <- hsMdbTimeSeries(
    -    xmdb(), "tbl_Hyd", "Zeitst", c("Q", "v"), "2011-08-24", "2011-08-25"
    -  )
    -
    -  ## Show the last records of the returned dataset.
    -  tail(ts)
    -}
    -
    -## Output:
    -#                   Zeitst     Q     v
    -# 1435 2011-08-24 23:55:00 0.638 0.281
    -# 1436 2011-08-24 23:56:00 0.601 0.265
    -# 1437 2011-08-24 23:57:00 0.564 0.249
    -# 1438 2011-08-24 23:58:00 0.536 0.237
    -# 1439 2011-08-24 23:59:00 0.504 0.223
    -# 1440 2011-08-25 00:00:00 0.483 0.214
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsOpenDb.html b/docs/reference/hsOpenDb.html deleted file mode 100644 index 6f842fb..0000000 --- a/docs/reference/hsOpenDb.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - - - -Open Connection to MS Access or Excel — hsOpenDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Opens database connection to MS Access or MS Excel, checks the connection and -stops on error.

    - -
    - -
    hsOpenDb(src, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "",
    -  ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    src

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”) or name of ODBC data source.

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE and if the connection could be established details of the -connection are shown.

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    additional arguments passed to the odbcConnect...()-function

    - -

    Value

    - -

    On success an object of class RODBC describing the connection is - returned. On failure nothing is returned and program execution stops.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Open a connection to the example database
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  con <- hsOpenDb(xmdb())
    -  con
    -}
    -
    -## Details on the established connection are shown:
    -# RODBC Connection 9
    -# Details:
    -#   case=nochange
    -#   DBQ=C:\Users\hsonne\Documents\R\win-library\2.14\kwb.base\...
    -#   Driver={Microsoft Access Driver (*.mdb)}
    -#   DriverId=25
    -#   FIL=MS Access
    -#   MaxBufferSize=2048
    -#   PageTimeout=5
    -#   UID=admin
    -
    -## Close the connection again
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  hsCloseDb(con)
    -}
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsOpenMdb.html b/docs/reference/hsOpenMdb.html deleted file mode 100644 index 7c24534..0000000 --- a/docs/reference/hsOpenMdb.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - -Open Connection to MS Access Database — hsOpenMdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Deprecated. Use hsOpenDb instead.

    - -
    - -
    hsOpenMdb(mdb, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    mdb

    full path to MS Access database file.

    dbg

    if TRUE and if the connection could be established details of the -connection are shown.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsPutTable.html b/docs/reference/hsPutTable.html deleted file mode 100644 index 4580170..0000000 --- a/docs/reference/hsPutTable.html +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - -Save Data Frame to Database Table — hsPutTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Writes data to a database table. This function performs opening of the -connection, saving of the data to a table and closing of the connection. If -an error occurs the program stops and an error description is shown. If a -table named tbl already exists in the database mdb the existing -table is only overwritten if overwrite is TRUE. Otherwise a -hsSafeName will be found for the table.

    - -
    - -
    hsPutTable(mdb, myData, tbl = "tblTmp", types = NULL,
    -  overwrite = FALSE, DBMSencoding = "", dbg = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (*.mdb)

    myData

    data.frame containing data to be written to database table

    tbl

    Name of table to be created in the database

    types

    field types to be passed to sqlSave as argument varTypes, -see ?sqlSave for details.

    overwrite

    shall existing table be overwritten?

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    In case of success the name of the created table is returned.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Create a data.frame
    -df1 <- data.frame(id = 1:4, rnd = sample(1:100)[1:4])
    -
    -## Write data.frame into a table in the example database; as no
    -## table name is specified, a table name is generated. The name
    -## of the table is returned.
    -## (only on Windows!)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tbl <- hsPutTable(xmdb(), df1)
    -  tbl # table name here: [1] "tblTmp"
    -
    -
    -  ## Get the data from the created table back again and print the
    -  ## data. As we see, a table containing four different random
    -  ## numbers between one and 100 has been created.
    -  df2 <- hsGetTable(xmdb(), tbl)
    -  df2
    -}
    -
    -## Output:
    -#   id rnd
    -# 1  1  82
    -# 2  2  14
    -# 3  3  99
    -# 4  4   6
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSetForeignKey.html b/docs/reference/hsSetForeignKey.html deleted file mode 100644 index 8bc2de1..0000000 --- a/docs/reference/hsSetForeignKey.html +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - -Set Foreign Key for Table Field — hsSetForeignKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set foreign key constraint for a table field

    - -
    - -
    hsSetForeignKey(mdb, tbl, field, ref.tbl, ref.field,
    -  key.name = .getForeignKeyName(tbl, field, ref.tbl, ref.field),
    -  dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (*.mdb)

    tbl

    name of table containing the field for which the foreign key -constraint is to be defined

    field

    name of table field for which the foreign key constraint is to -be defined

    ref.tbl

    name of table containing the referenced foreign key field

    ref.field

    name of foreign key field in ref.tbl

    key.name

    optional. Name to be given to the foreign key

    dbg

    passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSetPrimaryKey.html b/docs/reference/hsSetPrimaryKey.html deleted file mode 100644 index 328f872..0000000 --- a/docs/reference/hsSetPrimaryKey.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - -Set Primary Key of Database Table — hsSetPrimaryKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Sets fields with names given in vector keyFields as key fields of -table tbl in MS ACCESS database mdb.

    - -
    - -
    hsSetPrimaryKey(mdb, tbl, keyFields, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    mdb

    Full path to MS Access database file (*.mdb).

    tbl

    Name of table in which key fields are to be defined.

    keyFields

    (Vector of) key field name(s)

    dbg

    if TRUE, debug messages are shown

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlExAnd.html b/docs/reference/hsSqlExAnd.html deleted file mode 100644 index 704a608..0000000 --- a/docs/reference/hsSqlExAnd.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - -SQL Expression “AND” — hsSqlExAnd • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Creates a boolean expression of the form
    bFunc(x1) AND bFunc(x2) -AND ... AND bFunc(xn). This function can be used to create SQL queries where -many table fields have to be checked in the same way for some criterion (see -example).

    - -
    - -
    hsSqlExAnd(x, bFunc)
    - -

    Arguments

    - - - - - - - - - - -
    x

    vector of strings, e.g. representing table field names.

    bFunc

    name of a boolean function to be “applied” to each -element of x.

    - -

    See also

    - - - - -

    Examples

    -
    ## Build SQL query finding records in table t in which all -## of the table fields f1 to f100 are NULL. -sql <- sprintf("SELECT * FROM t WHERE %s", - hsSqlExAnd(paste("f", 1:100, sep = ""), "isNull")) - -## Show the SQL string -sql
    #> [1] "SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND isNull(f2) AND isNull(f3) AND isNull(f4) AND isNull(f5) AND isNull(f6) AND isNull(f7) AND isNull(f8) AND isNull(f9) AND isNull(f10) AND isNull(f11) AND isNull(f12) AND isNull(f13) AND isNull(f14) AND isNull(f15) AND isNull(f16) AND isNull(f17) AND isNull(f18) AND isNull(f19) AND isNull(f20) AND isNull(f21) AND isNull(f22) AND isNull(f23) AND isNull(f24) AND isNull(f25) AND isNull(f26) AND isNull(f27) AND isNull(f28) AND isNull(f29) AND isNull(f30) AND isNull(f31) AND isNull(f32) AND isNull(f33) AND isNull(f34) AND isNull(f35) AND isNull(f36) AND isNull(f37) AND isNull(f38) AND isNull(f39) AND isNull(f40) AND isNull(f41) AND isNull(f42) AND isNull(f43) AND isNull(f44) AND isNull(f45) AND isNull(f46) AND isNull(f47) AND isNull(f48) AND isNull(f49) AND isNull(f50) AND isNull(f51) AND isNull(f52) AND isNull(f53) AND isNull(f54) AND isNull(f55) AND isNull(f56) AND isNull(f57) AND isNull(f58) AND isNull(f59) AND isNull(f60) AND isNull(f61) AND isNull(f62) AND isNull(f63) AND isNull(f64) AND isNull(f65) AND isNull(f66) AND isNull(f67) AND isNull(f68) AND isNull(f69) AND isNull(f70) AND isNull(f71) AND isNull(f72) AND isNull(f73) AND isNull(f74) AND isNull(f75) AND isNull(f76) AND isNull(f77) AND isNull(f78) AND isNull(f79) AND isNull(f80) AND isNull(f81) AND isNull(f82) AND isNull(f83) AND isNull(f84) AND isNull(f85) AND isNull(f86) AND isNull(f87) AND isNull(f88) AND isNull(f89) AND isNull(f90) AND isNull(f91) AND isNull(f92) AND isNull(f93) AND isNull(f94) AND isNull(f95) AND isNull(f96) AND isNull(f97) AND isNull(f98) AND isNull(f99) AND isNull(f100)"
    -## Output (middle part omitted): -# SELECT * FROM t WHERE (TRUE) AND isNull(f1) AND -# isNull(f2) AND isNull(f3) AND ... AND isNull(f100) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlExOr.html b/docs/reference/hsSqlExOr.html deleted file mode 100644 index 39035d0..0000000 --- a/docs/reference/hsSqlExOr.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - -SQL Expression “OR” — hsSqlExOr • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Creates a boolean expression of the form
    bFunc(x1) OR bFunc(x2) OR -... OR bFunc(xn). This function can be used to create SQL queries where many -table fields have to be checked in the same way for some criterion (see -example).

    - -
    - -
    hsSqlExOr(x, bFunc = "")
    - -

    Arguments

    - - - - - - - - - - -
    x

    vector of strings, e.g. representing table field names.

    bFunc

    name of a boolean function to be “applied” to each -element of x.

    - -

    See also

    - - - - -

    Examples

    -
    ## Build SQL query finding records in table t in which at least -## one of the table fields f1 to f100 is NULL. -sql <- sprintf("SELECT * FROM t WHERE %s", - hsSqlExOr(paste("f", 1:100, sep = ""), "isNull")) - -## Show the SQL string -sql
    #> [1] "SELECT * FROM t WHERE (FALSE) OR isNull(f1) OR isNull(f2) OR isNull(f3) OR isNull(f4) OR isNull(f5) OR isNull(f6) OR isNull(f7) OR isNull(f8) OR isNull(f9) OR isNull(f10) OR isNull(f11) OR isNull(f12) OR isNull(f13) OR isNull(f14) OR isNull(f15) OR isNull(f16) OR isNull(f17) OR isNull(f18) OR isNull(f19) OR isNull(f20) OR isNull(f21) OR isNull(f22) OR isNull(f23) OR isNull(f24) OR isNull(f25) OR isNull(f26) OR isNull(f27) OR isNull(f28) OR isNull(f29) OR isNull(f30) OR isNull(f31) OR isNull(f32) OR isNull(f33) OR isNull(f34) OR isNull(f35) OR isNull(f36) OR isNull(f37) OR isNull(f38) OR isNull(f39) OR isNull(f40) OR isNull(f41) OR isNull(f42) OR isNull(f43) OR isNull(f44) OR isNull(f45) OR isNull(f46) OR isNull(f47) OR isNull(f48) OR isNull(f49) OR isNull(f50) OR isNull(f51) OR isNull(f52) OR isNull(f53) OR isNull(f54) OR isNull(f55) OR isNull(f56) OR isNull(f57) OR isNull(f58) OR isNull(f59) OR isNull(f60) OR isNull(f61) OR isNull(f62) OR isNull(f63) OR isNull(f64) OR isNull(f65) OR isNull(f66) OR isNull(f67) OR isNull(f68) OR isNull(f69) OR isNull(f70) OR isNull(f71) OR isNull(f72) OR isNull(f73) OR isNull(f74) OR isNull(f75) OR isNull(f76) OR isNull(f77) OR isNull(f78) OR isNull(f79) OR isNull(f80) OR isNull(f81) OR isNull(f82) OR isNull(f83) OR isNull(f84) OR isNull(f85) OR isNull(f86) OR isNull(f87) OR isNull(f88) OR isNull(f89) OR isNull(f90) OR isNull(f91) OR isNull(f92) OR isNull(f93) OR isNull(f94) OR isNull(f95) OR isNull(f96) OR isNull(f97) OR isNull(f98) OR isNull(f99) OR isNull(f100)"
    -## Output (middle part omitted): -# SELECT * FROM t WHERE (FALSE) OR isNull(f1) OR -# isNull(f2) OR isNull(f3) OR ... OR isNull(f100) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlExTimeCond.html b/docs/reference/hsSqlExTimeCond.html deleted file mode 100644 index baca03f..0000000 --- a/docs/reference/hsSqlExTimeCond.html +++ /dev/null @@ -1,251 +0,0 @@ - - - - - - - - -SQL Expression: Time Period — hsSqlExTimeCond • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    WHERE-condition string in MS Jet SQL syntax filtering for a specific - time interval

    - -
    - -
    hsSqlExTimeCond(tsField, dateFirst = NULL, dateLast = NULL,
    -  inclLast = TRUE, sqlDialect = getCurrentSqlDialect(), dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tsField

    name of timestamp field

    dateFirst

    Date object representing the first date of the time interval -to be selected.

    dateLast

    Date object representing the last date of the time interval -to be selected.

    inclLast

    if TRUE, dateLast will be included in result data set, -else excluded.

    sqlDialect

    one of c("mysql", "msaccess")

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    Condition string in MS Jet SQL syntax to be used in WHERE clause

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Condition string to filter field "datetime" for timestamps 
    -## between 21 and 22 of July 2010
    -from <- as.Date("2011-08-23")
    -to   <- as.Date("2011-08-24")
    -cond <- hsSqlExTimeCond("Zeitst", from, to)
    -cond
    -
    -## Output:
    -# TRUE  AND Zeitst >= #08/23/2011 00:00:00#  
    -#       AND Zeitst <= #08/24/2011 00:00:00#
    -
    -## The condition string may now be used in an SQL query 
    -## to select data from within the time interval. 
    -sql <- sprintf("SELECT * FROM tbl_Hyd WHERE %s", cond)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  res <- hsSqlQuery(xmdb(), sql)
    -  head(res)
    -}
    -
    -## Output:
    -# Zeitst Q v     H T_Kanal
    -# 1 2011-08-23 00:00:00 0 0 1.260    19.5
    -# 2 2011-08-23 00:01:00 0 0 1.259    19.5
    -# 3 2011-08-23 00:02:00 0 0 1.259    19.5
    -# 4 2011-08-23 00:03:00 0 0 1.259    19.5
    -# 5 2011-08-23 00:04:00 0 0 1.260    19.5
    -# 6 2011-08-23 00:05:00 0 0 1.260    19.5
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlExTimeGroup.html b/docs/reference/hsSqlExTimeGroup.html deleted file mode 100644 index 4ef8b8c..0000000 --- a/docs/reference/hsSqlExTimeGroup.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - -SQL Expression: Time Grouping — hsSqlExTimeGroup • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generates SQL code for grouping timestamps by years, months or days

    - -
    - -
    hsSqlExTimeGroup(tbl, tsField, interval, cond = "TRUE")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tbl

    name of the table

    tsField

    name of the table field containing the timestamp

    interval

    specifies the time period to group by ("y": years, "m": -months, "d": days)

    cond

    additional condition in SQL syntax

    - -

    Value

    - -

    Returns SQL code for grouping timestamps by years, months or days

    - -

    See also

    - - - - -

    Examples

    -
    ## Show SQL query that gets the number of datasets per -## day ("d") considering the condition "Q > 0" -hsSqlExTimeGroup("myTable", "myTimestamp", "d", "Q > 0")
    #> [1] "SELECT DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) AS myInterval, Count(*) AS myCount FROM (SELECT myTimestamp AS hsTS FROM [myTable] WHERE Q > 0) GROUP BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) ORDER BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS))"
    -## Output (reformatted): -## SELECT DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) -## AS myInterval, Count(*) AS myCount -## FROM ( -## SELECT myTimestamp AS hsTS FROM myTable WHERE Q > 0 -## ) -## GROUP BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) -## ORDER BY DateSerial(Year(hsTS), Month(hsTS), Day(hsTS)) - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlExTsFields.html b/docs/reference/hsSqlExTsFields.html deleted file mode 100644 index 883c37f..0000000 --- a/docs/reference/hsSqlExTsFields.html +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - - - -SQL Expression: Timestamp Info — hsSqlExTsFields • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generates SQL code for selecting different parts of the timestamp

    - -
    - -
    hsSqlExTsFields(tsField, extraTsFields = 0:11)
    - -

    Arguments

    - - - - - - - - - - -
    tsField

    name of the table field containing the timestamp

    extraTsFields

    vector of integers representing different types of -time-stamp information:
    0 = the timestamp in POSIXct as it is converted -to by R from the text representation delivered by MS Access,
    1 = -Timestamp as character string,
    2 = Date,
    3 = number of days since -1899-12-30,
    4 = number of seconds since midnight of Date
    5 = number -of minutes since midnight of Date
    6:8 = year, month, day
    9:11 = -hours, minutes, seconds

    - -

    Value

    - -

    Returns SQL code for selecting different types of information on - the time stamp.

    - -

    See also

    - - - - -

    Examples

    -
    hsSqlExTsFields("myTimestamp", c(6:11))
    #> [1] "Year(myTimestamp) AS myTimestamp_year, Month(myTimestamp) AS myTimestamp_month, Day(myTimestamp) AS myTimestamp_day, Hour(myTimestamp) AS myTimestamp_h, Minute(myTimestamp) AS myTimestamp_m, Second(myTimestamp) AS myTimestamp_s"
    -## Output (re-formatted): -# "Year(myTimestamp) AS myTimestamp_year, -# Month(myTimestamp) AS myTimestamp_month, -# Day(myTimestamp) AS myTimestamp_day, -# Hour(myTimestamp) AS myTimestamp_h, -# Minute(myTimestamp) AS myTimestamp_m, -# Second(myTimestamp) AS myTimestamp_s" - -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsSqlQuery.html b/docs/reference/hsSqlQuery.html deleted file mode 100644 index 53b1c71..0000000 --- a/docs/reference/hsSqlQuery.html +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - -Send SQL Query to Database — hsSqlQuery • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Get data from database requested via an SQL query. This function performs -opening of the connection, data retieval via SQL and closing of the -connection. If an error occurs the program stops and an error description is -shown.

    - -
    - -
    hsSqlQuery(mdb, sql, use2007Driver = NULL, dbg = TRUE,
    -  stopOnError = TRUE, DBMSencoding = "", ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    sql

    SQL query

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE (default), debug messages are shown.

    stopOnError

    if TRUE (default), the program stops in case of an error, -otherwise a warning is shown and NULL is returned.

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    additional arguments to be passed to sqlQuery

    - -

    Value

    - -

    On success, a data.frame containing the data that is internally - requested by calling the RODBC function sqlQuery and that is provided by - the database is returned. On error R stops execution and does not return - anything.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get Q time series from table "tbl_Hyd" in example database
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tsQ <- hsSqlQuery(
    -    xmdb(), "SELECT Zeitst AS t, Q FROM tbl_Hyd WHERE Q > 1.0"
    -  )
    -
    -  ## Show the first lines of the resulting data.frame
    -  head(tsQ)
    -}
    -
    -## Output
    -# t     Q
    -# 1 2011-08-24 22:27:00 1.061
    -# 2 2011-08-24 22:28:00 1.091
    -# 3 2011-08-24 22:29:00 1.115
    -# 4 2011-08-24 22:30:00 1.092
    -# 5 2011-08-24 22:31:00 1.086
    -# 6 2011-08-24 22:32:00 1.074
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsTables.html b/docs/reference/hsTables.html deleted file mode 100644 index bf7ca0b..0000000 --- a/docs/reference/hsTables.html +++ /dev/null @@ -1,245 +0,0 @@ - - - - - - - - -Available tables in database — hsTables • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns a data.frame as returned by sqlTables, containing information on the -tables contained in the database. Opening of the database connection, -getting the list of tables and closing of the database connection is done -within this function.

    - -
    - -
    hsTables(mdb, excludeSystemTables = grepl("\\.(mdb|accdb)$", mdb),
    -  namesOnly = TRUE, use2007Driver = NULL, dbg = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    mdb

    full path to MS Access database file (extension “.mdb” or -“.accdb”) or MS Excel file (extension “.xls” or -“.xlsx”).

    excludeSystemTables

    if TRUE (default), system tables are excluded from -the table list, else included.

    namesOnly

    if TRUE, only table names are returned. Default: TRUE

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE, debug messages are shown

    - -

    Value

    - -

    data.frame with columns TABLE_CAT, TABLE_SCHEM, - TABLE_NAME, TABLE_TYPE, REMARKS, see sqlTables of - RODBC package.

    - -

    See also

    - - - - -

    Examples

    -
    # NOT RUN {
    -## Get names of tables in the example database
    -## (only on Windows)
    -
    -if (.Platform$OS.type == "windows") {
    -
    -  tnames <- hsTables(xmdb(), namesOnly = TRUE)
    -
    -  ## Exclude system tables by filtering for table names
    -  ## not starting with '^MSys'
    -  tNonSys <- grep("^MSys", tnames, invert = TRUE, value = TRUE)
    -
    -  ## Print the names of the non-system tables.
    -  cat(paste(tNonSys, "\n"))
    -}
    -
    -## Ouput:
    -# tbl_Hyd
    -#  tbl_Qua
    -#  ...
    -# }
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/hsTsField.html b/docs/reference/hsTsField.html deleted file mode 100644 index 77d2472..0000000 --- a/docs/reference/hsTsField.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - -Available timestamp-field(s) in database table — hsTsField • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Available timestamp-field(s) in database table

    - -
    - -
    hsTsField(src, tbl, namesOnly = TRUE, all = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    src

    source file (MS Access or Excel)

    tbl

    table name

    namesOnly

    if TRUE, only the name(s) of the timestamp field(s) is (are) -returned, otherwise additional information.

    all

    if TRUE, all timestamp fields are considiered, otherwise only the -first timestamp field.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/index.html b/docs/reference/index.html deleted file mode 100644 index 8b7149d..0000000 --- a/docs/reference/index.html +++ /dev/null @@ -1,575 +0,0 @@ - - - - - - - - -Function reference • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -

    All functions

    -

    -
    -

    connectionStringAccess()

    -

    Connection String Access

    -

    createRDatabaseInterface()

    -

    Create R-Function Interface to Database

    -

    currentDb()

    -

    Get Path to or Name of Current Database

    -

    dataFrameToSqlTuples()

    -

    Create SQL Tuples from Data Frame

    -

    getCurrentSqlDialect()

    -

    Get Current SQL Dialect

    -

    getDatabaseSchema()

    -

    Get Database Schema

    -

    getFilteredRecords()

    -

    Get Filtered Records

    -

    getSqlDialect()

    -

    Get SQL Dialect from Given Database

    -

    getTypeIdentifier()

    -

    Get Type Identifier

    -

    hsClearTable()

    -

    Clear a Database Table

    -

    hsCloseDb()

    -

    Close Connection to MS Access or Excel

    -

    hsCloseMdb()

    -

    Close Connection

    -

    hsDropTable()

    -

    Drop Database Table(s)

    -

    hsDumpMdb()

    -

    Export Database Tables to CSV Files

    -

    hsFields()

    -

    Available Fields in Database Table

    -

    hsGetTable()

    -

    Get Table from MS Access Database

    -

    hsGetTimeSeries()

    -

    Get Time Series With Timestamp Info

    -

    hsJetDate()

    -

    Date to “mm/dd/yyyy HH:MM:SS”

    -

    hsLookupOrAddRecord()

    -

    Lookup or Add Record

    -

    hsMdbTimeSeries()

    -

    Get Mdb time series in UTC

    -

    hsOpenDb()

    -

    Open Connection to MS Access or Excel

    -

    hsOpenMdb()

    -

    Open Connection to MS Access Database

    -

    hsPutTable()

    -

    Save Data Frame to Database Table

    -

    hsSetForeignKey()

    -

    Set Foreign Key for Table Field

    -

    hsSetPrimaryKey()

    -

    Set Primary Key of Database Table

    -

    hsSqlExAnd()

    -

    SQL Expression “AND”

    -

    hsSqlExOr()

    -

    SQL Expression “OR”

    -

    hsSqlExTimeCond()

    -

    SQL Expression: Time Period

    -

    hsSqlExTimeGroup()

    -

    SQL Expression: Time Grouping

    -

    hsSqlExTsFields()

    -

    SQL Expression: Timestamp Info

    -

    hsSqlQuery()

    -

    Send SQL Query to Database

    -

    hsTables()

    -

    Available tables in database

    -

    hsTsField()

    -

    Available timestamp-field(s) in database table

    -

    isExcel2003File()

    -

    Is this an XLS file?

    -

    isExcel2007File()

    -

    Is this an XLSX file?

    -

    isExcelFile()

    -

    Is this an Excel file?

    -

    isMySQL()

    -

    Is the Given Database of Type MySQL?

    -

    keyValuesToSql()

    -

    List of Key = Value Pairs to SQL Expressions

    -

    keyValuesToSqlAssignment()

    -

    List of Key = Value Pairs to SQL Assignment

    -

    keyValuesToSqlAssignment2()

    -

    Key Values to SQL Assignment (2)

    -

    keyValuesToSqlFilter()

    -

    List of Key = Value Pairs to SQL Filter Expression

    -

    keyValueToSql()

    -

    Generate SQL Filter or Assignment Expression

    -

    listValuesToSql()

    -

    Create SQL Tuples from a List

    -

    lookupRecord()

    -

    Lookup Record

    -

    openAdequateConnectionOrStop()

    -

    Open Adequate Connection or Stop

    -

    printDatabaseSchema()

    -

    Print Database Schema

    -

    rcode_DatabaseInterface()

    -

    R-code for Functions to Access Database Tables

    -

    readSqlCommandsFromFile()

    -

    Read SQL Commands from File

    -

    renamesToFieldList()

    -

    List of Renamings to Field Selection String

    -

    runSqlCommandsFromFile()

    -

    Run SQL Commands from File

    -

    safeTableName()

    -

    Safe Table Name

    -

    selectFromDb()

    -

    Select from Database

    -

    selectFromTable()

    -

    Select from Table

    -

    setCurrentDb()

    -

    Set Current Database

    -

    setCurrentSqlDialect()

    -

    Set Current SQL Dialect

    -

    sqlForInsert()

    -

    Generate SQL INSERT statement

    -

    sqlForInsertDataFrame()

    -

    Generate SQL INSERT Statement

    -

    sqlForInsertFromSelect()

    -

    SQL for INSERT FROM SELECT

    -

    sqlForInsertIgnoreInMsAccess()

    -

    SQL for "INSERT IGNORE" in MS Access

    -

    sqlForSelect()

    -

    Generate SQL SELECT statement#'

    -

    sqlForSelectByKey()

    -

    Generate SQL SELECT Statement

    -

    sqlForUpdate()

    -

    Generate SQL UPDATE Statement

    -

    sqlJoinExpression()

    -

    Create an SQL JOIN Expression

    -

    sqlLeftJoin()

    -

    Generate SQL for LEFT JOIN

    -

    sqlLeftJoinBody()

    -

    Generate (Base Part of) SQL for LEFT JOIN

    -

    sqlLeftJoinExpression()

    -

    Create an SQL LEFT JOIN Expression

    -

    xmdb()

    -

    Path to example database

    -
    - - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/isExcel2003File.html b/docs/reference/isExcel2003File.html deleted file mode 100644 index 9217fb8..0000000 --- a/docs/reference/isExcel2003File.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - -Is this an XLS file? — isExcel2003File • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an XLS file?

    - -
    - -
    isExcel2003File(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xls -extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/isExcel2007File.html b/docs/reference/isExcel2007File.html deleted file mode 100644 index e95a84a..0000000 --- a/docs/reference/isExcel2007File.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - -Is this an XLSX file? — isExcel2007File • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an XLSX file?

    - -
    - -
    isExcel2007File(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xlsx -extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/isExcelFile.html b/docs/reference/isExcelFile.html deleted file mode 100644 index 2322974..0000000 --- a/docs/reference/isExcelFile.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - -Is this an Excel file? — isExcelFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is this an Excel file?

    - -
    - -
    isExcelFile(filepath)
    - -

    Arguments

    - - - - - - -
    filepath

    (vector of) path(s) to the file(s) to be checked for .xls -or .xlsx extension

    - -

    Value

    - -

    (vector of) logical.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/isMySQL.html b/docs/reference/isMySQL.html deleted file mode 100644 index 29f18e0..0000000 --- a/docs/reference/isMySQL.html +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - -Is the Given Database of Type MySQL? — isMySQL • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Is the Given Database of Type MySQL?

    - -
    - -
    isMySQL(db, ...)
    - -

    Arguments

    - - - - - - - - - - -
    db

    database file (*.mdb, *.accdb, *.xls, *.xlsx) or name of ODBC -database

    arguments passed to hsOpenDb, e.g. -use2007Driver

    - -

    Value

    - -

    TRUE if db is a MySQL database, else FALSE

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/keyValueToSql.html b/docs/reference/keyValueToSql.html deleted file mode 100644 index 1240f39..0000000 --- a/docs/reference/keyValueToSql.html +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - -Generate SQL Filter or Assignment Expression — keyValueToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL Filter or Assignment Expression

    - -
    - -
    keyValueToSql(cname, cvalue, like = TRUE, filter = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    cname

    field name

    cvalue

    field value

    like

    if TRUE, the SQL comparison operator will be LIKE -instead of =.

    filter

    if TRUE an SQL filter expression is returned, otherwise -an SQL assignment expression

    - -

    Value

    - -

    (vector of) character representing an SQL expression

    - - -

    Examples

    -
    cat(kwb.db:::keyValueToSql("age", 1))
    #> age = 1
    cat(kwb.db:::keyValueToSql("name", "peter"))
    #> name LIKE "peter"
    cat(kwb.db:::keyValueToSql("name", "peter", like = FALSE))
    #> name = "peter"
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/keyValuesToSql.html b/docs/reference/keyValuesToSql.html deleted file mode 100644 index fdc4949..0000000 --- a/docs/reference/keyValuesToSql.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Expressions — keyValuesToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Expressions

    - -
    - -
    keyValuesToSql(keyValues, filter, like = filter)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    keyValues

    list of key = value pairs

    filter

    logical. If TRUE the target is an SQL filter expression, -otherwise an SQL SET expression.

    like

    passed to keyValueToSql

    - - -

    Examples

    -
    keyValues <- list(name = "Peter", birth = as.POSIXct("1999-09-09")) - -setCurrentSqlDialect("msaccess") -cat(keyValuesToSql(keyValues, filter = TRUE))
    #> name LIKE 'Peter' AND birth LIKE #1999-09-09#
    cat(keyValuesToSql(keyValues, filter = TRUE, like = FALSE))
    #> name = 'Peter' AND birth = #1999-09-09#
    cat(keyValuesToSql(keyValues, filter = FALSE))
    #> name = 'Peter',birth = #1999-09-09#
    -setCurrentSqlDialect("mysql") -cat(keyValuesToSql(keyValues, filter = TRUE))
    #> name LIKE "Peter" AND birth LIKE '1999-09-09'
    cat(keyValuesToSql(keyValues, filter = TRUE, like = FALSE))
    #> name = "Peter" AND birth = '1999-09-09'
    cat(keyValuesToSql(keyValues, filter = FALSE))
    #> name = "Peter",birth = '1999-09-09'
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/keyValuesToSqlAssignment.html b/docs/reference/keyValuesToSqlAssignment.html deleted file mode 100644 index 15d18c9..0000000 --- a/docs/reference/keyValuesToSqlAssignment.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Assignment — keyValuesToSqlAssignment • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Assignment

    - -
    - -
    keyValuesToSqlAssignment(keyValues)
    - -

    Arguments

    - - - - - - -
    keyValues

    list of key = value pairs

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/keyValuesToSqlAssignment2.html b/docs/reference/keyValuesToSqlAssignment2.html deleted file mode 100644 index 2ad022f..0000000 --- a/docs/reference/keyValuesToSqlAssignment2.html +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - -Key Values to SQL Assignment (2) — keyValuesToSqlAssignment2 • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Key Values to SQL Assignment (2)

    - -
    - -
    keyValuesToSqlAssignment2(keyvalues)
    - -

    Arguments

    - - - - - - -
    keyvalues

    list of key = value pairs

    - -

    Value

    - -

    list with elements fieldList and valueList

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/keyValuesToSqlFilter.html b/docs/reference/keyValuesToSqlFilter.html deleted file mode 100644 index 0bb8c1d..0000000 --- a/docs/reference/keyValuesToSqlFilter.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - -List of Key = Value Pairs to SQL Filter Expression — keyValuesToSqlFilter • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    List of Key = Value Pairs to SQL Filter Expression

    - -
    - -
    keyValuesToSqlFilter(keyValues, like = FALSE)
    - -

    Arguments

    - - - - - - - - - - -
    keyValues

    list of key = value pairs

    like

    if TRUE, the SQL comparison operator will be LIKE -instead of =.

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/listValuesToSql.html b/docs/reference/listValuesToSql.html deleted file mode 100644 index 9d48e8c..0000000 --- a/docs/reference/listValuesToSql.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - -Create SQL Tuples from a List — listValuesToSql • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create SQL Tuples from a List

    - -
    - -
    listValuesToSql(x)
    - -

    Arguments

    - - - - - - -
    x

    a list defining key = value pairs

    - -

    Value

    - -

    vector of character strings each of which represents one assignment - in x

    - - -

    Examples

    -
    x <- list(name = "Peter", birthday = as.POSIXct("1981-12-13")) - -setCurrentSqlDialect("msaccess") -cat(listValuesToSql(x))
    #> 'Peter',#1981-12-13#
    -# Note that the representation of a date and time is different in MySQL -setCurrentSqlDialect("mysql") -cat(listValuesToSql(x))
    #> "Peter",'1981-12-13'
    -
    -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/lookupRecord.html b/docs/reference/lookupRecord.html deleted file mode 100644 index 0a788a6..0000000 --- a/docs/reference/lookupRecord.html +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - -Lookup Record — lookupRecord • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Looks up a record in a database table and returns the ID of the record or - NULL if the record does not exist.

    - -
    - -
    lookupRecord(db, tableName, keyAssignments, idField = hsFields(db,
    -  tableName)[1], dbg = FALSE, use2007Driver = NULL)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    full path to MS Access/Excel database or name of ODBC data source

    tableName

    name of table in which record is to be looked up

    keyAssignments

    key-value-assignments used to identify the record to be looked up. -The assignments are defined in forms of a list, e.g. list(key1 = "value1", -key2 = "value2").

    idField

    name of ID field, default: name of first table field

    dbg

    if TRUE, debug messages are shown

    use2007Driver

    passed to isMySQL

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/openAdequateConnectionOrStop.html b/docs/reference/openAdequateConnectionOrStop.html deleted file mode 100644 index 77cc553..0000000 --- a/docs/reference/openAdequateConnectionOrStop.html +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - -Open Adequate Connection or Stop — openAdequateConnectionOrStop • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Open Adequate Connection or Stop

    - -
    - -
    openAdequateConnectionOrStop(db, use2007Driver = NULL, dbg = FALSE,
    -  DBMSencoding = "", ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    use2007Driver

    if TRUE the functions odbcConnectAccess2007 and -odbcConnectExcel2007 are used instead of odbcConnectAccess and -odbcConnectExcel, respectively

    dbg

    if TRUE, debug messages are shown

    DBMSencoding

    finally passed to odbcDriverConnect. Default: "", -You may want to use: "UTF-8"

    further arguments passed to odbcConnectionAccess, -odbcConnectionExcel or odbcConnect

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/printDatabaseSchema.html b/docs/reference/printDatabaseSchema.html deleted file mode 100644 index eb0fefd..0000000 --- a/docs/reference/printDatabaseSchema.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - -Print Database Schema — printDatabaseSchema • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Print Database Schema

    - -
    - -
    printDatabaseSchema(dbSchema)
    - -

    Arguments

    - - - - - - -
    dbSchema

    database schema as returned by -getDatabaseSchema

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/rcode_DatabaseInterface.html b/docs/reference/rcode_DatabaseInterface.html deleted file mode 100644 index f13f1fe..0000000 --- a/docs/reference/rcode_DatabaseInterface.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - -R-code for Functions to Access Database Tables — rcode_DatabaseInterface • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    R-code for Functions to Access Database Tables

    - -
    - -
    rcode_DatabaseInterface(db = NULL, dbSchema = NULL,
    -  tableNamePattern = "", functionPrefix = "db_", pattern = "^",
    -  dbg = TRUE, sql.dbg = TRUE, create.create.functions = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    dbSchema

    database schema as returned by -getDatabaseSchema

    tableNamePattern

    pattern matching the names of tables/views for which -an accessor function is to be generated

    functionPrefix

    prefix to be given to each generated function. Default: -"db_"

    pattern

    pattern matching the part of the table name that will be -replaced with functionPrefix. Default: "^", i.e. the prefix will be -appended to the start of the table name

    dbg

    if TRUE, progress messages are shown during the creation of the -interface functions

    sql.dbg

    if TRUE, SQL strings used to access the database are shown -when calling the interface functions

    create.create.functions

    if TRUE, functions for creating new records in -the database tables are created

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/readSqlCommandsFromFile.html b/docs/reference/readSqlCommandsFromFile.html deleted file mode 100644 index 056675f..0000000 --- a/docs/reference/readSqlCommandsFromFile.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - -Read SQL Commands from File — readSqlCommandsFromFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Lines starting with "--" or "#" are ignored. SQL commands must be separated -by semicolon and end of line character (\n).

    - -
    - -
    readSqlCommandsFromFile(sqlScript)
    - -

    Arguments

    - - - - - - -
    sqlScript

    full path to file containing SQL commands

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/renamesToFieldList.html b/docs/reference/renamesToFieldList.html deleted file mode 100644 index da60e10..0000000 --- a/docs/reference/renamesToFieldList.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - -List of Renamings to Field Selection String — renamesToFieldList • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Convert a list of renamings to a field selection string that can be used as -fields argument in a call to kwb.db::hsGetTable

    - -
    - -
    renamesToFieldList(renames, source.in.brackets = TRUE,
    -  target.in.brackets = TRUE)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    renames

    list of key = value pairs defining renamings from the keys to -the values

    source.in.brackets

    if TRUE (default) the source expressions -will be enclosed in square brackets: [source] AS <target>

    target.in.brackets

    if TRUE (default) the target names will be -enclosed in square brackets: <source> AS [target]

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/runSqlCommandsFromFile.html b/docs/reference/runSqlCommandsFromFile.html deleted file mode 100644 index 8bf56a8..0000000 --- a/docs/reference/runSqlCommandsFromFile.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - -Run SQL Commands from File — runSqlCommandsFromFile • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Run SQL Commands from File

    - -
    - -
    runSqlCommandsFromFile(db, sqlFile, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    db

    Full path to MS Access mdb file or ODBC database name

    sqlFile

    full path to file containing Ms Access SQL commands

    further arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/safeTableName.html b/docs/reference/safeTableName.html deleted file mode 100644 index 1e00aa6..0000000 --- a/docs/reference/safeTableName.html +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - -Safe Table Name — safeTableName • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    MS Access: table name enclosed in brackets "[" and "]", else: table name -enclosed in backquotes "`"

    - -
    - -
    safeTableName(tableName, sqlDialect = getCurrentSqlDialect(warn = FALSE))
    - -

    Arguments

    - - - - - - - - - - -
    tableName

    name of table to be quoted

    sqlDialect

    one of c("mysql", "msaccess")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/selectFromDb.html b/docs/reference/selectFromDb.html deleted file mode 100644 index 0d1a40e..0000000 --- a/docs/reference/selectFromDb.html +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - -Select from Database — selectFromDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Select from Database

    - -
    - -
    selectFromDb(tableName, fields = "*", whereClause = "TRUE", odbc,
    -  dbg = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tableName

    name of database table from which to load data

    fields

    names of fields to be selected

    whereClause

    SQL WHERE condition string

    odbc

    database name or file

    dbg

    if TRUE, debug messages are shown

    additonal arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/selectFromTable.html b/docs/reference/selectFromTable.html deleted file mode 100644 index 9839450..0000000 --- a/docs/reference/selectFromTable.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - -Select from Table — selectFromTable • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Select from Table

    - -
    - -
    selectFromTable(db, tableName, arguments, run = TRUE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    tableName

    name of table from which to read data

    arguments

    list with elements select, where, -orderBy and further elements starting with select_, -where_ and orderBy_, respectively

    run

    if TRUE (default) the SQL SELECT statement is run otherwise -returned as character string

    further arguments passed to hsSqlQuery

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/setCurrentDb.html b/docs/reference/setCurrentDb.html deleted file mode 100644 index 26aef02..0000000 --- a/docs/reference/setCurrentDb.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - -Set Current Database — setCurrentDb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set Current Database

    - -
    - -
    setCurrentDb(db)
    - -

    Arguments

    - - - - - - -
    db

    full path to MS Access database or ODBC database name

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/setCurrentSqlDialect.html b/docs/reference/setCurrentSqlDialect.html deleted file mode 100644 index 301e6ed..0000000 --- a/docs/reference/setCurrentSqlDialect.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - -Set Current SQL Dialect — setCurrentSqlDialect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Set Current SQL Dialect

    - -
    - -
    setCurrentSqlDialect(dialectName)
    - -

    Arguments

    - - - - - - -
    dialectName

    one of "msaccess", "mysql"

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForInsert.html b/docs/reference/sqlForInsert.html deleted file mode 100644 index 9e76436..0000000 --- a/docs/reference/sqlForInsert.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - -Generate SQL INSERT statement — sqlForInsert • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement

    - -
    - -
    sqlForInsert(tablename, fields, sqlSource,
    -  sourceAreValues = !grepl(sqlSource, "^SELECT"), ignore = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    field names, separated by comma

    sqlSource

    value tupels of form (value1.1, value1.2, value1.3, ...) -(value2.1, value2.2, value2.3, ...) ... or SQL SELECT statement providing -these tupels

    sourceAreValues

    if TRUE, sqlSource is expected to be an SQL -query providing data to be inserted -> no keyword VALUES in generated SQL -code

    ignore

    if TRUE the keyword IGNORE is inserted between INSERT and INTO -in the SQL statement -> no error will be given if data to insert already -exists

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForInsertDataFrame.html b/docs/reference/sqlForInsertDataFrame.html deleted file mode 100644 index 3c6c284..0000000 --- a/docs/reference/sqlForInsertDataFrame.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - -Generate SQL INSERT Statement — sqlForInsertDataFrame • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement to insert values in a data frame

    - -
    - -
    sqlForInsertDataFrame(tablename, dataFrame, ignore = FALSE, ...)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    dataFrame

    data frame with column names representing table field names

    ignore

    if TRUE the keyword IGNORE is inserted between INSERT and INTO -in the SQL statement -> no error will be given if data to insert already -exists

    further arguments passed to sqlForInsert

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForInsertFromSelect.html b/docs/reference/sqlForInsertFromSelect.html deleted file mode 100644 index def7560..0000000 --- a/docs/reference/sqlForInsertFromSelect.html +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - -SQL for INSERT FROM SELECT — sqlForInsertFromSelect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL INSERT statement of the form INSERT INTO target.table (fields) - SELECT fields FROM source.table

    - -
    - -
    sqlForInsertFromSelect(target.table, source.table, fields)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    target.table

    name of target table

    source.table

    name of source table or SQL providing source data

    fields

    vector of character with field names

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForInsertIgnoreInMsAccess.html b/docs/reference/sqlForInsertIgnoreInMsAccess.html deleted file mode 100644 index 17b787d..0000000 --- a/docs/reference/sqlForInsertIgnoreInMsAccess.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - - -SQL for "INSERT IGNORE" in MS Access — sqlForInsertIgnoreInMsAccess • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns SQL for inserting all records from table.source that are not yet - contained in table.target into table.target

    - -
    - -
    sqlForInsertIgnoreInMsAccess(db, table.source, table.target,
    -  uniqueFields = NA)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    db

    database name or file

    table.source

    name of source table

    table.target

    name of target table

    uniqueFields

    names of unique fields

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForSelect.html b/docs/reference/sqlForSelect.html deleted file mode 100644 index 870b058..0000000 --- a/docs/reference/sqlForSelect.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - -Generate SQL SELECT statement#' — sqlForSelect • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL SELECT statement#'

    - -
    - -
    sqlForSelect(tablename, fields = "*", whereClause = "TRUE",
    -  groupBy = "", orderBy = "", sqlDialect = getCurrentSqlDialect())
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    expression to select fields; field names are separated by comma -and alias names may be used, just as SQL accepts, e.g.: "tstamp as -myDateTime, parVal as myValue"; Default: "*"

    whereClause

    where condition; Default: "TRUE"

    groupBy

    GROUP BY-clause, Default: "" (no grouping)

    orderBy

    ORDER BY-clause, Default: "" (no sorting of results)

    sqlDialect

    one of c("mysql", "msaccess")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForSelectByKey.html b/docs/reference/sqlForSelectByKey.html deleted file mode 100644 index 444bdc7..0000000 --- a/docs/reference/sqlForSelectByKey.html +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - -Generate SQL SELECT Statement — sqlForSelectByKey • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL SELECT statement (key field values instead of where clause)

    - -
    - -
    sqlForSelectByKey(tablename, fields = "*", keyValues = NULL)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    tablename

    table name

    fields

    expression to select fields; field names are separated by comma -and alias names may be used, just as SQL accepts, e.g.: "tstamp as -myDateTime, parVal as myValue"; Default: "*"

    keyValues

    list of "key=value" pairs with the keys being valid field -names of table

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlForUpdate.html b/docs/reference/sqlForUpdate.html deleted file mode 100644 index 87d4058..0000000 --- a/docs/reference/sqlForUpdate.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - - -Generate SQL UPDATE Statement — sqlForUpdate • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL UPDATE Statement

    - -
    - -
    sqlForUpdate(tablename, keyValues, whereClause, ignore = FALSE)
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    tablename

    table name

    keyValues

    assignments as list of key=value pairs with the keys -representing valid fields of table tablename

    whereClause

    where condition

    ignore

    if TRUE the keyword IGNORE is inserted between UPDATE and INTO -in the SQL statement -> no error will be given if updating fails, e.g. -because of key constraints

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlJoinExpression.html b/docs/reference/sqlJoinExpression.html deleted file mode 100644 index 4d56f21..0000000 --- a/docs/reference/sqlJoinExpression.html +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - -Create an SQL JOIN Expression — sqlJoinExpression • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create an SQL JOIN Expression

    - -
    - -
    sqlJoinExpression(left, right, condition, type = "INNER")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - -
    left

    left part of JOIN (e.g. table name)

    right

    right part of JOIN (e.g. table name)

    condition

    condition

    type

    one of c("LEFT", "RIGHT", "INNER")

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlLeftJoin.html b/docs/reference/sqlLeftJoin.html deleted file mode 100644 index 3495718..0000000 --- a/docs/reference/sqlLeftJoin.html +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - -Generate SQL for LEFT JOIN — sqlLeftJoin • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate SQL for LEFT JOIN

    - -
    - -
    sqlLeftJoin(sqlSource, tablesAndIDs, fields = "*")
    - -

    Arguments

    - - - - - - - - - - - - - - -
    sqlSource

    SQL of subquery that provides the "base" table on the left

    tablesAndIDs

    named character vector with the names representing the -names of the tables to be joined and the values representing the ID fields -of these tables

    fields

    fields to be selected

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlLeftJoinBody.html b/docs/reference/sqlLeftJoinBody.html deleted file mode 100644 index 8bfde51..0000000 --- a/docs/reference/sqlLeftJoinBody.html +++ /dev/null @@ -1,202 +0,0 @@ - - - - - - - - -Generate (Base Part of) SQL for LEFT JOIN — sqlLeftJoinBody • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Generate (Base Part of) SQL for LEFT JOIN

    - -
    - -
    sqlLeftJoinBody(leftSql, rightTable, id, idLeft = id, useAlias = (id !=
    -  idLeft), aliasName = "tbase")
    - -

    Arguments

    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    leftSql

    SQL of subquery that provides the "base" table on the left

    rightTable

    name of "right" table

    id

    name of ID field of "right" table (must correspond to a field -returned by leftSql)

    idLeft

    name of ID field of "left" table

    useAlias

    if TRUE, the alias given in aliasName is given to the -subquery leftSql. Default: FALSE

    aliasName

    alias name to be used if useAlias is TRUE. Default: -"tbase"

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/sqlLeftJoinExpression.html b/docs/reference/sqlLeftJoinExpression.html deleted file mode 100644 index 1f598bf..0000000 --- a/docs/reference/sqlLeftJoinExpression.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - -Create an SQL LEFT JOIN Expression — sqlLeftJoinExpression • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Create an SQL LEFT JOIN Expression

    - -
    - -
    sqlLeftJoinExpression(left, right, condition)
    - -

    Arguments

    - - - - - - - - - - - - - - -
    left

    left part of JOIN (e.g. table name)

    right

    right part of JOIN (e.g. table name)

    condition

    condition

    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - diff --git a/docs/reference/xmdb.html b/docs/reference/xmdb.html deleted file mode 100644 index f1d6a23..0000000 --- a/docs/reference/xmdb.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - -Path to example database — xmdb • kwb.db - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - -
    -
    - - -
    - -

    Returns full path to MS Access example database

    - -
    - -
    xmdb()
    - - -
    - -
    - -
    - - -
    -

    Site built with pkgdown.

    -
    - -
    -
    - - - - - - - - - From 5995f3a5c10cccc80c73488ff3d6facf65ab47a5 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 17 Sep 2019 16:48:02 +0200 Subject: [PATCH 23/28] Correct path to GitHub repo odbc32 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1259fad..04abc60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,7 +36,7 @@ Suggests: Remotes: github::kwb-r/kwb.datetime, github::kwb-r/kwb.utils, - github::vh/odbc32 + github::vh-d/odbc32 Encoding: UTF-8 License: MIT + file LICENSE RoxygenNote: 6.1.1 From 986ad22cb2638a02885fdd41753e40ccbb0bcf29 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 1 Nov 2019 19:58:07 +0100 Subject: [PATCH 24/28] Export additional functions, add test scripts --- NAMESPACE | 2 + R/connect.R | 1 + R/sql_expressions.R | 2 +- inst/extdata/NAMESPACE_old | 68 ++++++++++++++++++++++ inst/extdata/snippets_64_bit.R | 40 +++++++++++++ inst/extdata/snippets_64_bit_support_mdb.R | 46 +++++++++++++++ 6 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 inst/extdata/NAMESPACE_old create mode 100644 inst/extdata/snippets_64_bit.R create mode 100644 inst/extdata/snippets_64_bit_support_mdb.R diff --git a/NAMESPACE b/NAMESPACE index 7f65325..3d35147 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,11 +13,13 @@ export(hsGetTable) export(hsGetTimeSeries) export(hsLookupOrAddRecord) export(hsMdbTimeSeries) +export(hsOpenDb) export(hsPutTable) export(hsSetForeignKey) export(hsSetPrimaryKey) export(hsSqlExAnd) export(hsSqlExOr) +export(hsSqlExTimeCond) export(hsSqlExTimeGroup) export(hsSqlExTsFields) export(hsSqlQuery) diff --git a/R/connect.R b/R/connect.R index a18c23a..1cd1d81 100644 --- a/R/connect.R +++ b/R/connect.R @@ -40,6 +40,7 @@ hsOpenMdb <- function(mdb, dbg = FALSE) #' #' @seealso \code{\link{hsCloseDb}} #' @importFrom kwb.utils catIf printIf +#' @export #' @examples #' \dontrun{ #' ## Open a connection to the example database diff --git a/R/sql_expressions.R b/R/sql_expressions.R index ba9866d..0e71fea 100644 --- a/R/sql_expressions.R +++ b/R/sql_expressions.R @@ -81,7 +81,7 @@ hsSqlExAnd <- function(x, bFunc) #' @param sqlDialect one of \code{c("mysql", "msaccess")} #' @param dbg if \code{TRUE}, debug messages are shown #' @return Condition string in MS Jet SQL syntax to be used in WHERE clause -#' +#' @export #' @seealso \code{\link{hsJetDate}} #' #' @examples diff --git a/inst/extdata/NAMESPACE_old b/inst/extdata/NAMESPACE_old new file mode 100644 index 0000000..9f490bb --- /dev/null +++ b/inst/extdata/NAMESPACE_old @@ -0,0 +1,68 @@ +export(connectionStringAccess) +export(createRDatabaseInterface) +export(currentDb) +export(dataFrameToSqlTuples) +export(dumpDatabase) +export(getCurrentSqlDialect) +export(getDatabaseSchema) +export(getFilteredRecords) +export(getSqlDialect) +export(getTypeIdentifier) +export(hsClearTable) +export(hsCloseDb) +export(hsCloseMdb) +export(hsDropTable) +export(hsDumpMdb) +export(hsFields) +export(hsGetTable) +export(hsGetTimeSeries) +export(hsJetDate) +export(hsLookupOrAddRecord) +export(hsMdbTimeSeries) +export(hsOpenDb) +export(hsOpenMdb) +export(hsPutTable) +export(hsSetForeignKey) +export(hsSetPrimaryKey) +export(hsSqlExAnd) +export(hsSqlExOr) +export(hsSqlExTimeCond) +export(hsSqlExTimeGroup) +export(hsSqlExTsFields) +export(hsSqlQuery) +export(hsTables) +export(hsTsField) +export(isExcel2007File) +export(isExcelFile) +export(isMySQL) +export(keyValuesToSql) +export(keyValuesToSqlAssignment) +export(keyValuesToSqlAssignment2) +export(keyValuesToSqlFilter) +export(listValuesToSql) +export(lookupRecord) +export(openAdequateConnectionOrStop) +export(printDatabaseSchema) +export(rcode_DatabaseInterface) +export(readSqlCommandsFromFile) +export(renamesToFieldList) +export(renamesToQueries) +export(runSqlCommandsFromFile) +export(safeTableName) +export(selectFromDb) +export(selectFromTable) +export(setCurrentDb) +export(setCurrentSqlDialect) +export(sqlForInsert) +export(sqlForInsertDataFrame) +export(sqlForInsertFromSelect) +export(sqlForInsertIgnoreInMsAccess) +export(sqlForSelect) +export(sqlForSelectByKey) +export(sqlForUpdate) +export(sqlFullLeftJoin) +export(sqlJoinExpression) +export(sqlLeftJoin) +export(sqlLeftJoinBody) +export(sqlLeftJoinExpression) +export(xmdb) diff --git a/inst/extdata/snippets_64_bit.R b/inst/extdata/snippets_64_bit.R new file mode 100644 index 0000000..40c0981 --- /dev/null +++ b/inst/extdata/snippets_64_bit.R @@ -0,0 +1,40 @@ + + +# kwb.db::hsTables +# function (mdb, excludeSystemTables = grepl("\\.(mdb|accdb)$", +# mdb), namesOnly = TRUE, use2007Driver = NULL, dbg = FALSE) +# { + + dbg <- TRUE + use2007Driver <- NULL + mdb <- db_path + + kwb.utils::catIf(dbg, "in hsTables: use2007Driver =", use2007Driver, + "\n") + sqlDialect = kwb.db::getCurrentSqlDialect(warn = FALSE) + + + #con <- kwb.db::hsOpenDb(mdb, use2007Driver = use2007Driver) + con <- odbc32::odbcConnectAccess2007(db_path) + + on.exit({ + #kwb.db::hsCloseDb(con) + odbc32::odbcClose(con) + setCurrentSqlDialect(sqlDialect) + }) + + is_64_bit <- (.Machine$sizeof.pointer == 8) + + tblList <- RODBC::sqlTables(con) + tblList <- odbc32::sqlTables(con) + + if (excludeSystemTables) + tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", + ] + if (namesOnly) { + return(tblList$TABLE_NAME) + } + else { + return(tblList) + } +#} \ No newline at end of file diff --git a/inst/extdata/snippets_64_bit_support_mdb.R b/inst/extdata/snippets_64_bit_support_mdb.R new file mode 100644 index 0000000..307ff97 --- /dev/null +++ b/inst/extdata/snippets_64_bit_support_mdb.R @@ -0,0 +1,46 @@ +file_accdb <- paste0( + "C:/Users/hsonne/Documents/Projekte2/sema-berlin/DatenCOd_G_ds20180620.accdb" +) + +file_mdb <- paste0( + "C:/Users/hsonne/Documents/Projekte2/SEMA/1a_Environment_mdb/", + "StatAna_be_SEMA_versions/StatAna_be_SEMA_v09.mdb" +) + +stopifnot(file.exists(file_accdb)) +stopifnot(file.exists(file_mdb)) + +kwb.db::hsTables(file_accdb) +kwb.db::hsOpenDb(file_accdb) + +con <- kwb.db:::openAdequateConnectionOrStop(file_accdb) +con <- kwb.db:::odbcConnectionAccess(file_accdb) +con <- kwb.db:::odbcConnectionAccess64(file_accdb, TRUE) +con <- kwb.db:::odbcConnectionAccess64(file_mdb, FALSE) + +con_accdb <- odbc32::odbcConnectAccess2007( + file_accdb, + socket = kwb.utils::defaultIfNULL( + x = .GlobalEnv$.r2r_socket, + default = odbc32::start_server(invisible = TRUE) + ) +) + +con_mdb <- odbc32:::odbcConnectAccess( + file_mdb, + socket = kwb.utils::defaultIfNULL( + x = .GlobalEnv$.r2r_socket, + default = odbc32::start_server(invisible = TRUE) + ) +) + +odbc32::sqlTables(con_accdb) +odbc32::sqlTables(con_mdb) + +kwb.db:::hsCloseDb(con_accdb) +kwb.db:::hsCloseDb(con_mdb) + +key <- "SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers" + +utils::readRegistry(key, view = "64-bit") +utils::readRegistry(key, view = "32-bit") From beb6e83521a49ab1ef1271164de532363a203a46 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 3 Nov 2019 17:18:43 +0100 Subject: [PATCH 25/28] Do not use kwb.db::: --- R/base.R | 930 +++++++++++++++++++++++++++---------------------------- 1 file changed, 465 insertions(+), 465 deletions(-) diff --git a/R/base.R b/R/base.R index 0f97546..f13d2e4 100644 --- a/R/base.R +++ b/R/base.R @@ -1,466 +1,466 @@ -# hsPutTable ------------------------------------------------------------------- - -#' Save Data Frame to Database Table -#' -#' Writes data to a database table. This function performs opening of the -#' connection, saving of the data to a table and closing of the connection. If -#' an error occurs the program stops and an error description is shown. If a -#' table named \emph{tbl} already exists in the database \emph{mdb} the existing -#' table is only overwritten if \emph{overwrite} is TRUE. Otherwise a -#' \code{\link[kwb.utils]{hsSafeName}} will be found for the table. -#' -#' @param mdb full path to MS Access database file (*.mdb) -#' @param myData data.frame containing data to be written to database table -#' @param tbl Name of table to be created in the database -#' @param types field types to be passed to sqlSave as argument \emph{varTypes}, -#' see ?sqlSave for details. -#' @param overwrite shall existing table be overwritten? -#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", -#' You may want to use: "UTF-8" -#' @param dbg if TRUE, debug messages are shown -#' -#' @return In case of success the name of the created table is returned. -#' -#' @seealso \code{\link{hsSqlQuery}, \link{hsGetTable}} -#' @importFrom kwb.utils hsSafeName -#' @importFrom RODBC sqlSave -#' @export -#' @examples -#' \dontrun{ -#' ## Create a data.frame -#' df1 <- data.frame(id = 1:4, rnd = sample(1:100)[1:4]) -#' -#' ## Write data.frame into a table in the example database; as no -#' ## table name is specified, a table name is generated. The name -#' ## of the table is returned. -#' ## (only on Windows!) -#' -#' if (.Platform$OS.type == "windows") { -#' -#' tbl <- hsPutTable(xmdb(), df1) -#' tbl # table name here: [1] "tblTmp" -#' -#' -#' ## Get the data from the created table back again and print the -#' ## data. As we see, a table containing four different random -#' ## numbers between one and 100 has been created. -#' df2 <- hsGetTable(xmdb(), tbl) -#' df2 -#' } -#' -#' ## Output: -#' # id rnd -#' # 1 1 82 -#' # 2 2 14 -#' # 3 3 99 -#' # 4 4 6 -#' } -#' -hsPutTable <- function( - mdb, myData, tbl = "tblTmp", types = NULL, overwrite = FALSE, - DBMSencoding = "", dbg = TRUE -) -{ - ## Find a safe (non-existing) table name - tblSafe <- kwb.utils::hsSafeName(tbl, hsTables(mdb, namesOnly=TRUE)) - - ## if tblSafe differs from tbl the table exists. Delete the - ## existing table and use nevertheless tbl as table name if - ## overwrite is TRUE - if (tblSafe != tbl && isTRUE(overwrite)) { - hsDropTable(mdb, tbl, dbg = dbg) - tblSafe <- tbl - } - - sqlDialect <- getCurrentSqlDialect(warn = FALSE) - - ## Open database connection, on exit close it and reset the sql dialect - con <- hsOpenDb(mdb, DBMSencoding = DBMSencoding) - - on.exit({ - hsCloseDb(con) - setCurrentSqlDialect(sqlDialect) - }) - - if (is.null(types)) { - - kwb.utils::catIf(dbg, "No field types given.\n") - - if (! isMySQL(mdb, con = con)) { - - for (colname in colnames(myData)) { - - className <- class(myData[[colname]])[1] - dbClassName <- .hsJetType(className) - types <- c(types, dbClassName) - } - - names(types) <- colnames(myData) - } - } - - kwb.utils::printIf( - dbg && ! is.null(types), types, "Given/generated field types" - ) - - # Provide arguments to sqlSave() - arguments <- list(con, myData, tblSafe, rownames = FALSE, verbose = dbg) - - if (! is.null(types)) { - arguments <- c(arguments, list(varTypes = types)) - } - - # Select the appropriate function - FUN <- if (is64BitR()) { - odbc32::sqlSave - } else { - RODBC::sqlSave - } - - # Call the function that saves the data to the database table - result <- kwb.utils::catAndRun( - dbg = dbg, - messageText = sprintf("Writing data to table '%s' in '%s'\n", tblSafe, mdb), - expr = do.call(FUN, arguments) - ) - - # Did an error occur? - if (result != 1) { - stop("sqlSave returned with error.\n") - } - - tblSafe -} - -# hsGetTable ------------------------------------------------------------------- - -#' Get Table from MS Access Database -#' -#' Provides data from an MS Access database table in forms of a data frame. -#' -#' ATTENTION: This function may not return what you want if the table contains a -#' timestamp field. Use \code{hsMdbTimeSeries} instead. -#' -#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or -#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or -#' \dQuote{.xlsx}). -#' @param tbl Table name. Put it into brackets [] if it contains spaces and if -#' it mdb does not point to a MySQL database -#' @param cond Condition string. -#' @param fields Comma separated list of names of fields to be selected. -#' @param dbg if TRUE, debug messages are shown, else not -#' @param check if TRUE (default), \emph{tbl} is checked for existence in -#' \emph{mdb} before trying to get the data and a list of available tables is -#' shown in the case that the table does not exist. -#' @param use2007Driver passed to \code{\link{hsTables}} and -#' \code{\link{hsSqlQuery}} -#' @param \dots Additional arguments to be passed to hsSqlQuery -#' -#' @return data.frame containing data from table in database -#' -#' @seealso \code{\link{hsSqlQuery}, \link{hsPutTable}, hsGetTimeSeries, -#' hsMdbTimeSeries} -#' @importFrom kwb.utils hsQuoteChr -#' @export -#' @examples -#' \dontrun{ -#' ## Get all datasets from tbl_Hyd in example database where -#' ## Q > 1.0 m3/s and temperature > 20 degree Celsius -#' ## (only on Windows!) -#' -#' if (.Platform$OS.type == "windows") { -#' ts <- hsGetTable(xmdb(), "tbl_Hyd", "Q > 1.0 AND T_Kanal > 20") -#' head(ts) -#' } -#' -#' ## Output: -#' # Zeitst Q v H T_Kanal -#' # 1 2011-08-24 22:33:00 1.075 0.459 1.366 20.1 -#' # 2 2011-08-24 22:34:00 1.062 0.453 1.370 20.2 -#' # 3 2011-08-24 22:35:00 1.050 0.449 1.364 20.2 -#' # 4 2011-08-24 22:36:00 1.042 0.446 1.361 20.3 -#' # 5 2011-08-24 22:37:00 1.032 0.443 1.354 20.3 -#' # 6 2011-08-24 22:38:00 1.010 0.436 1.348 20.4 -#' -#' ## TAKE CARE when getting time-series data: -#' if (.Platform$OS.type == "windows") { -#' hsGetTable(xmdb(), "tblTimestampTest_DST") -#' } -#' -#' ## Output: -#' # tstamp -#' # 1 2011-03-27 01:00:00 -#' # 2 2011-03-27 01:30:00 -#' # 3 -#' # 4 -#' # 5 2011-03-27 03:00:00 -#' # 6 2011-03-27 03:30:00 -#' -#' ## As the output shows the timestamps between 02:00:00 and -#' ## 02:59:59 have been set to . Reason: When retrieving -#' ## date/time data from MS Access, R converts the timestamps -#' ## from a text representation into POSIXct objects. As POSIXct's -#' ## standard time zone seems to be taken from the Windows system -#' ## R tries to convert to Central European Time (CET) which -#' ## does not exist for the hour in which time is switched to -#' ## daylight-saving time (as in the example). -#' -#' ## This standard behaviour can be changed by setting the -#' ## standard time zone: -#' tz <- Sys.getenv("tz") # save current standard time zone -#' Sys.setenv(tz = "UTC") # set standard time zone to UTC -#' -#' ## The same command as above now delivers all timestamps -#' ## (in Coordinated Universal Time, UTC): -#' -#' if (.Platform$OS.type == "windows") { -#' hsGetTable(xmdb(), "tblTimestampTest_DST") -#' } -#' -#' ## Output: -#' # tstamp -#' # 1 2011-03-27 01:00:00 -#' # 2 2011-03-27 01:30:00 -#' # 3 2011-03-27 02:00:00 -#' # 4 2011-03-27 02:30:00 -#' # 5 2011-03-27 03:00:00 -#' # 6 2011-03-27 03:30:00 -#' -#' ## Reset standard time zone -#' Sys.setenv(tz = tz) -#' } -#' -hsGetTable <- function( - mdb, tbl, cond = "TRUE", fields = "*", dbg = TRUE, check = TRUE, - use2007Driver = NULL, ... -) -{ - if (missing(tbl) || check) { - - availableTableNames <- hsTables( - mdb, namesOnly = TRUE, use2007Driver = use2007Driver - ) - } - - # Help the user by showing a list of available table names - if (missing(tbl)) { - - stop("No table name given. ",.message_availableTables(availableTableNames)) - } - - if (check) { - - # remove possible quotes embracing the table name - availableTableNames <- gsub("^'(.*)'$", "\\1", availableTableNames) - - if (! (tbl %in% availableTableNames)) { - - stop( - "Table ", kwb.utils::hsQuoteChr(tbl), " does not exist in ", - kwb.utils::hsQuoteChr(mdb), ".\n", - .message_availableTables(availableTableNames) - ) - } - } - - # Return result of SQL query - is.MySql <- isMySQL(mdb, use2007Driver = use2007Driver) - - sql <- sqlForSelect( - tablename = tbl, fields = fields, whereClause = cond, - sqlDialect = ifelse(is.MySql, "mysql", "msaccess") - ) - - hsSqlQuery(mdb, sql = sql, dbg = dbg, use2007Driver = use2007Driver, ...) -} - -# .message_availableTables ----------------------------------------------------- - -.message_availableTables <- function(tableNames) -{ - paste("Available tables:\n ", paste(tableNames, collapse = "\n ")) -} - -# hsTables --------------------------------------------------------------------- - -#' Available tables in database -#' -#' Returns a data.frame as returned by sqlTables, containing information on the -#' tables contained in the database. Opening of the database connection, -#' getting the list of tables and closing of the database connection is done -#' within this function. -#' -#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or -#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or -#' \dQuote{.xlsx}). -#' @param excludeSystemTables if TRUE (default), system tables are excluded from -#' the table list, else included. -#' @param namesOnly if TRUE, only table names are returned. Default: TRUE -#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and -#' odbcConnectExcel2007 are used instead of odbcConnectAccess and -#' odbcConnectExcel, respectively -#' @param dbg if TRUE, debug messages are shown -#' -#' @return data.frame with columns \emph{TABLE_CAT}, \emph{TABLE_SCHEM}, -#' \emph{TABLE_NAME}, \emph{TABLE_TYPE}, \emph{REMARKS}, see sqlTables of -#' RODBC package. -#' -#' @seealso \code{\link{hsFields}} -#' @importFrom kwb.utils catIf -#' @importFrom RODBC sqlTables -#' @export -#' @examples -#' \dontrun{ -#' ## Get names of tables in the example database -#' ## (only on Windows) -#' -#' if (.Platform$OS.type == "windows") { -#' -#' tnames <- hsTables(xmdb(), namesOnly = TRUE) -#' -#' ## Exclude system tables by filtering for table names -#' ## not starting with '^MSys' -#' tNonSys <- grep("^MSys", tnames, invert = TRUE, value = TRUE) -#' -#' ## Print the names of the non-system tables. -#' cat(paste(tNonSys, "\n")) -#' } -#' -#' ## Ouput: -#' # tbl_Hyd -#' # tbl_Qua -#' # ... -#' } -#' -hsTables <- function( - mdb, excludeSystemTables = grepl("\\.(mdb|accdb)$", mdb), namesOnly = TRUE, - use2007Driver = NULL, dbg = FALSE -) -{ - kwb.utils::catIf(dbg, "in hsTables: use2007Driver =", use2007Driver, "\n") - - sqlDialect = getCurrentSqlDialect(warn = FALSE) - - ## Open database connection and close it on exit - con <- hsOpenDb(mdb, use2007Driver = use2007Driver) - - on.exit({ - hsCloseDb(con) - setCurrentSqlDialect(sqlDialect) - }) - - tblList <- if (is64BitR()) { - odbc32::sqlTables(con) - } else { - RODBC::sqlTables(con) - } - - if (excludeSystemTables) { - tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] - } - - if (namesOnly) { - tblList$TABLE_NAME - } else { - tblList - } -} - -# hsFields --------------------------------------------------------------------- - -#' Available Fields in Database Table -#' -#' Returns a vector containing the field names of a database table. -#' -#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or -#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or -#' \dQuote{.xlsx}). -#' @param tbl table name. -#' @param namesOnly if TRUE, only field names are returned, otherwise all -#' available information on the fields. Default: TRUE -#' @param chopDollar if TRUE (default), a dollar sign at the end of the table -#' name is removed before sending it to \code{sqlColumns}, -#' @param ignore.case if TRUE, case is ignored when comparing the given table -#' with the names of the existing tables. Default: FALSE -#' @param use2007Driver passed to \code{\link{isMySQL}} -#' @param dbg if TRUE, debug messages are shown -#' -#' @return Vector containing the field names of the database table (if namesOnly -#' = TRUE) or data.frame with columns \emph{COLUMN_NAME}, \emph{DATA_TYPE}, -#' \emph{TYPE_NAME}, \emph{COLUMN_SIZE}, \emph{BUFFER_LENGTH}, -#' \emph{DECIMAL_DIGITS}, \emph{NUM_PREC_RADIX}, \emph{NULLABLE} describing -#' the database fields in detail, otherwise. -#' -#' @seealso \code{\link{hsTables}} -#' @importFrom RODBC sqlColumns -#' @export -#' @examples -#' \dontrun{ -#' ## List the fields of table "tbl_Hyd" in the example database -#' ## (only on Windows!) -#' -#' if (.Platform$OS.type == "windows") { -#' setCurrentSqlDialect("msaccess") -#' fields <- hsFields(xmdb(), "tbl_Hyd") -#' fields -#' } -#' -#' ## Ouput: -#' # [1] "Zeitst" "Q" "v" "H" "T_Kanal" -#' } -#' -hsFields <- function( - mdb, tbl, namesOnly = TRUE, chopDollar = TRUE, - ignore.case = (! isMySQL(mdb, use2007Driver = use2007Driver)), - use2007Driver = NULL, dbg = FALSE -) -{ - ## if no table name is given stop with showing a list of available tables - tbls <- hsTables(mdb, namesOnly = TRUE) - - msg <- sprintf("Available tables:\n %s", paste( - '"', tbls, '"', sep = "", collapse = '\n ' - )) - - if (missing(tbl)) { - - clean_stop("No table name given. ", msg) - } - - pattern <- paste("^", tbl, "$", sep = "") - - if (length(grep(pattern, tbls, ignore.case = ignore.case)) != 1) { - - clean_stop(sprintf('Table "%s" not found in %s. ', tbl, mdb), msg) - } - - sqlDialect <- getCurrentSqlDialect(warn = FALSE) - - con <- hsOpenDb(mdb) - - on.exit({ - hsCloseDb(con) - setCurrentSqlDialect(sqlDialect) - }) - - if (chopDollar) { - - tbl <- sub("\\$$", "", tbl) - } - - fieldInfo <- if (kwb.db:::is64BitR()) { - clean_stop("Sorry. There is no equivalent to sqlColumns() in odbc32!") - } else { - RODBC::sqlColumns(con, tbl) - } - - if (namesOnly) { - - return(fieldInfo$COLUMN_NAME) - - } else { - - ## omit first three (table related) columns of data frame - return(fieldInfo[, -c(1:3)]) - } +# hsPutTable ------------------------------------------------------------------- + +#' Save Data Frame to Database Table +#' +#' Writes data to a database table. This function performs opening of the +#' connection, saving of the data to a table and closing of the connection. If +#' an error occurs the program stops and an error description is shown. If a +#' table named \emph{tbl} already exists in the database \emph{mdb} the existing +#' table is only overwritten if \emph{overwrite} is TRUE. Otherwise a +#' \code{\link[kwb.utils]{hsSafeName}} will be found for the table. +#' +#' @param mdb full path to MS Access database file (*.mdb) +#' @param myData data.frame containing data to be written to database table +#' @param tbl Name of table to be created in the database +#' @param types field types to be passed to sqlSave as argument \emph{varTypes}, +#' see ?sqlSave for details. +#' @param overwrite shall existing table be overwritten? +#' @param DBMSencoding finally passed to \code{odbcDriverConnect}. Default: "", +#' You may want to use: "UTF-8" +#' @param dbg if TRUE, debug messages are shown +#' +#' @return In case of success the name of the created table is returned. +#' +#' @seealso \code{\link{hsSqlQuery}, \link{hsGetTable}} +#' @importFrom kwb.utils hsSafeName +#' @importFrom RODBC sqlSave +#' @export +#' @examples +#' \dontrun{ +#' ## Create a data.frame +#' df1 <- data.frame(id = 1:4, rnd = sample(1:100)[1:4]) +#' +#' ## Write data.frame into a table in the example database; as no +#' ## table name is specified, a table name is generated. The name +#' ## of the table is returned. +#' ## (only on Windows!) +#' +#' if (.Platform$OS.type == "windows") { +#' +#' tbl <- hsPutTable(xmdb(), df1) +#' tbl # table name here: [1] "tblTmp" +#' +#' +#' ## Get the data from the created table back again and print the +#' ## data. As we see, a table containing four different random +#' ## numbers between one and 100 has been created. +#' df2 <- hsGetTable(xmdb(), tbl) +#' df2 +#' } +#' +#' ## Output: +#' # id rnd +#' # 1 1 82 +#' # 2 2 14 +#' # 3 3 99 +#' # 4 4 6 +#' } +#' +hsPutTable <- function( + mdb, myData, tbl = "tblTmp", types = NULL, overwrite = FALSE, + DBMSencoding = "", dbg = TRUE +) +{ + ## Find a safe (non-existing) table name + tblSafe <- kwb.utils::hsSafeName(tbl, hsTables(mdb, namesOnly=TRUE)) + + ## if tblSafe differs from tbl the table exists. Delete the + ## existing table and use nevertheless tbl as table name if + ## overwrite is TRUE + if (tblSafe != tbl && isTRUE(overwrite)) { + hsDropTable(mdb, tbl, dbg = dbg) + tblSafe <- tbl + } + + sqlDialect <- getCurrentSqlDialect(warn = FALSE) + + ## Open database connection, on exit close it and reset the sql dialect + con <- hsOpenDb(mdb, DBMSencoding = DBMSencoding) + + on.exit({ + hsCloseDb(con) + setCurrentSqlDialect(sqlDialect) + }) + + if (is.null(types)) { + + kwb.utils::catIf(dbg, "No field types given.\n") + + if (! isMySQL(mdb, con = con)) { + + for (colname in colnames(myData)) { + + className <- class(myData[[colname]])[1] + dbClassName <- .hsJetType(className) + types <- c(types, dbClassName) + } + + names(types) <- colnames(myData) + } + } + + kwb.utils::printIf( + dbg && ! is.null(types), types, "Given/generated field types" + ) + + # Provide arguments to sqlSave() + arguments <- list(con, myData, tblSafe, rownames = FALSE, verbose = dbg) + + if (! is.null(types)) { + arguments <- c(arguments, list(varTypes = types)) + } + + # Select the appropriate function + FUN <- if (is64BitR()) { + odbc32::sqlSave + } else { + RODBC::sqlSave + } + + # Call the function that saves the data to the database table + result <- kwb.utils::catAndRun( + dbg = dbg, + messageText = sprintf("Writing data to table '%s' in '%s'\n", tblSafe, mdb), + expr = do.call(FUN, arguments) + ) + + # Did an error occur? + if (result != 1) { + stop("sqlSave returned with error.\n") + } + + tblSafe +} + +# hsGetTable ------------------------------------------------------------------- + +#' Get Table from MS Access Database +#' +#' Provides data from an MS Access database table in forms of a data frame. +#' +#' ATTENTION: This function may not return what you want if the table contains a +#' timestamp field. Use \code{hsMdbTimeSeries} instead. +#' +#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or +#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or +#' \dQuote{.xlsx}). +#' @param tbl Table name. Put it into brackets [] if it contains spaces and if +#' it mdb does not point to a MySQL database +#' @param cond Condition string. +#' @param fields Comma separated list of names of fields to be selected. +#' @param dbg if TRUE, debug messages are shown, else not +#' @param check if TRUE (default), \emph{tbl} is checked for existence in +#' \emph{mdb} before trying to get the data and a list of available tables is +#' shown in the case that the table does not exist. +#' @param use2007Driver passed to \code{\link{hsTables}} and +#' \code{\link{hsSqlQuery}} +#' @param \dots Additional arguments to be passed to hsSqlQuery +#' +#' @return data.frame containing data from table in database +#' +#' @seealso \code{\link{hsSqlQuery}, \link{hsPutTable}, hsGetTimeSeries, +#' hsMdbTimeSeries} +#' @importFrom kwb.utils hsQuoteChr +#' @export +#' @examples +#' \dontrun{ +#' ## Get all datasets from tbl_Hyd in example database where +#' ## Q > 1.0 m3/s and temperature > 20 degree Celsius +#' ## (only on Windows!) +#' +#' if (.Platform$OS.type == "windows") { +#' ts <- hsGetTable(xmdb(), "tbl_Hyd", "Q > 1.0 AND T_Kanal > 20") +#' head(ts) +#' } +#' +#' ## Output: +#' # Zeitst Q v H T_Kanal +#' # 1 2011-08-24 22:33:00 1.075 0.459 1.366 20.1 +#' # 2 2011-08-24 22:34:00 1.062 0.453 1.370 20.2 +#' # 3 2011-08-24 22:35:00 1.050 0.449 1.364 20.2 +#' # 4 2011-08-24 22:36:00 1.042 0.446 1.361 20.3 +#' # 5 2011-08-24 22:37:00 1.032 0.443 1.354 20.3 +#' # 6 2011-08-24 22:38:00 1.010 0.436 1.348 20.4 +#' +#' ## TAKE CARE when getting time-series data: +#' if (.Platform$OS.type == "windows") { +#' hsGetTable(xmdb(), "tblTimestampTest_DST") +#' } +#' +#' ## Output: +#' # tstamp +#' # 1 2011-03-27 01:00:00 +#' # 2 2011-03-27 01:30:00 +#' # 3 +#' # 4 +#' # 5 2011-03-27 03:00:00 +#' # 6 2011-03-27 03:30:00 +#' +#' ## As the output shows the timestamps between 02:00:00 and +#' ## 02:59:59 have been set to . Reason: When retrieving +#' ## date/time data from MS Access, R converts the timestamps +#' ## from a text representation into POSIXct objects. As POSIXct's +#' ## standard time zone seems to be taken from the Windows system +#' ## R tries to convert to Central European Time (CET) which +#' ## does not exist for the hour in which time is switched to +#' ## daylight-saving time (as in the example). +#' +#' ## This standard behaviour can be changed by setting the +#' ## standard time zone: +#' tz <- Sys.getenv("tz") # save current standard time zone +#' Sys.setenv(tz = "UTC") # set standard time zone to UTC +#' +#' ## The same command as above now delivers all timestamps +#' ## (in Coordinated Universal Time, UTC): +#' +#' if (.Platform$OS.type == "windows") { +#' hsGetTable(xmdb(), "tblTimestampTest_DST") +#' } +#' +#' ## Output: +#' # tstamp +#' # 1 2011-03-27 01:00:00 +#' # 2 2011-03-27 01:30:00 +#' # 3 2011-03-27 02:00:00 +#' # 4 2011-03-27 02:30:00 +#' # 5 2011-03-27 03:00:00 +#' # 6 2011-03-27 03:30:00 +#' +#' ## Reset standard time zone +#' Sys.setenv(tz = tz) +#' } +#' +hsGetTable <- function( + mdb, tbl, cond = "TRUE", fields = "*", dbg = TRUE, check = TRUE, + use2007Driver = NULL, ... +) +{ + if (missing(tbl) || check) { + + availableTableNames <- hsTables( + mdb, namesOnly = TRUE, use2007Driver = use2007Driver + ) + } + + # Help the user by showing a list of available table names + if (missing(tbl)) { + + stop("No table name given. ",.message_availableTables(availableTableNames)) + } + + if (check) { + + # remove possible quotes embracing the table name + availableTableNames <- gsub("^'(.*)'$", "\\1", availableTableNames) + + if (! (tbl %in% availableTableNames)) { + + stop( + "Table ", kwb.utils::hsQuoteChr(tbl), " does not exist in ", + kwb.utils::hsQuoteChr(mdb), ".\n", + .message_availableTables(availableTableNames) + ) + } + } + + # Return result of SQL query + is.MySql <- isMySQL(mdb, use2007Driver = use2007Driver) + + sql <- sqlForSelect( + tablename = tbl, fields = fields, whereClause = cond, + sqlDialect = ifelse(is.MySql, "mysql", "msaccess") + ) + + hsSqlQuery(mdb, sql = sql, dbg = dbg, use2007Driver = use2007Driver, ...) +} + +# .message_availableTables ----------------------------------------------------- + +.message_availableTables <- function(tableNames) +{ + paste("Available tables:\n ", paste(tableNames, collapse = "\n ")) +} + +# hsTables --------------------------------------------------------------------- + +#' Available tables in database +#' +#' Returns a data.frame as returned by sqlTables, containing information on the +#' tables contained in the database. Opening of the database connection, +#' getting the list of tables and closing of the database connection is done +#' within this function. +#' +#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or +#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or +#' \dQuote{.xlsx}). +#' @param excludeSystemTables if TRUE (default), system tables are excluded from +#' the table list, else included. +#' @param namesOnly if TRUE, only table names are returned. Default: TRUE +#' @param use2007Driver if TRUE the functions odbcConnectAccess2007 and +#' odbcConnectExcel2007 are used instead of odbcConnectAccess and +#' odbcConnectExcel, respectively +#' @param dbg if TRUE, debug messages are shown +#' +#' @return data.frame with columns \emph{TABLE_CAT}, \emph{TABLE_SCHEM}, +#' \emph{TABLE_NAME}, \emph{TABLE_TYPE}, \emph{REMARKS}, see sqlTables of +#' RODBC package. +#' +#' @seealso \code{\link{hsFields}} +#' @importFrom kwb.utils catIf +#' @importFrom RODBC sqlTables +#' @export +#' @examples +#' \dontrun{ +#' ## Get names of tables in the example database +#' ## (only on Windows) +#' +#' if (.Platform$OS.type == "windows") { +#' +#' tnames <- hsTables(xmdb(), namesOnly = TRUE) +#' +#' ## Exclude system tables by filtering for table names +#' ## not starting with '^MSys' +#' tNonSys <- grep("^MSys", tnames, invert = TRUE, value = TRUE) +#' +#' ## Print the names of the non-system tables. +#' cat(paste(tNonSys, "\n")) +#' } +#' +#' ## Ouput: +#' # tbl_Hyd +#' # tbl_Qua +#' # ... +#' } +#' +hsTables <- function( + mdb, excludeSystemTables = grepl("\\.(mdb|accdb)$", mdb), namesOnly = TRUE, + use2007Driver = NULL, dbg = FALSE +) +{ + kwb.utils::catIf(dbg, "in hsTables: use2007Driver =", use2007Driver, "\n") + + sqlDialect = getCurrentSqlDialect(warn = FALSE) + + ## Open database connection and close it on exit + con <- hsOpenDb(mdb, use2007Driver = use2007Driver) + + on.exit({ + hsCloseDb(con) + setCurrentSqlDialect(sqlDialect) + }) + + tblList <- if (is64BitR()) { + odbc32::sqlTables(con) + } else { + RODBC::sqlTables(con) + } + + if (excludeSystemTables) { + tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] + } + + if (namesOnly) { + tblList$TABLE_NAME + } else { + tblList + } +} + +# hsFields --------------------------------------------------------------------- + +#' Available Fields in Database Table +#' +#' Returns a vector containing the field names of a database table. +#' +#' @param mdb full path to MS Access database file (extension \dQuote{.mdb} or +#' \dQuote{.accdb}) or MS Excel file (extension \dQuote{.xls} or +#' \dQuote{.xlsx}). +#' @param tbl table name. +#' @param namesOnly if TRUE, only field names are returned, otherwise all +#' available information on the fields. Default: TRUE +#' @param chopDollar if TRUE (default), a dollar sign at the end of the table +#' name is removed before sending it to \code{sqlColumns}, +#' @param ignore.case if TRUE, case is ignored when comparing the given table +#' with the names of the existing tables. Default: FALSE +#' @param use2007Driver passed to \code{\link{isMySQL}} +#' @param dbg if TRUE, debug messages are shown +#' +#' @return Vector containing the field names of the database table (if namesOnly +#' = TRUE) or data.frame with columns \emph{COLUMN_NAME}, \emph{DATA_TYPE}, +#' \emph{TYPE_NAME}, \emph{COLUMN_SIZE}, \emph{BUFFER_LENGTH}, +#' \emph{DECIMAL_DIGITS}, \emph{NUM_PREC_RADIX}, \emph{NULLABLE} describing +#' the database fields in detail, otherwise. +#' +#' @seealso \code{\link{hsTables}} +#' @importFrom RODBC sqlColumns +#' @export +#' @examples +#' \dontrun{ +#' ## List the fields of table "tbl_Hyd" in the example database +#' ## (only on Windows!) +#' +#' if (.Platform$OS.type == "windows") { +#' setCurrentSqlDialect("msaccess") +#' fields <- hsFields(xmdb(), "tbl_Hyd") +#' fields +#' } +#' +#' ## Ouput: +#' # [1] "Zeitst" "Q" "v" "H" "T_Kanal" +#' } +#' +hsFields <- function( + mdb, tbl, namesOnly = TRUE, chopDollar = TRUE, + ignore.case = (! isMySQL(mdb, use2007Driver = use2007Driver)), + use2007Driver = NULL, dbg = FALSE +) +{ + ## if no table name is given stop with showing a list of available tables + tbls <- hsTables(mdb, namesOnly = TRUE) + + msg <- sprintf("Available tables:\n %s", paste( + '"', tbls, '"', sep = "", collapse = '\n ' + )) + + if (missing(tbl)) { + + clean_stop("No table name given. ", msg) + } + + pattern <- paste("^", tbl, "$", sep = "") + + if (length(grep(pattern, tbls, ignore.case = ignore.case)) != 1) { + + clean_stop(sprintf('Table "%s" not found in %s. ', tbl, mdb), msg) + } + + sqlDialect <- getCurrentSqlDialect(warn = FALSE) + + con <- hsOpenDb(mdb) + + on.exit({ + hsCloseDb(con) + setCurrentSqlDialect(sqlDialect) + }) + + if (chopDollar) { + + tbl <- sub("\\$$", "", tbl) + } + + fieldInfo <- if (is64BitR()) { + clean_stop("Sorry. There is no equivalent to sqlColumns() in odbc32!") + } else { + RODBC::sqlColumns(con, tbl) + } + + if (namesOnly) { + + return(fieldInfo$COLUMN_NAME) + + } else { + + ## omit first three (table related) columns of data frame + return(fieldInfo[, -c(1:3)]) + } } \ No newline at end of file From 8871e341fe5f4617e1ee1c884994b7fd2d77ffa7 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 3 Nov 2019 17:20:38 +0100 Subject: [PATCH 26/28] Import Windows-specific functions only on Windows Therefore, do not let Roxygen generate the NAMESPACE and introduce an if () directive within NAMESPACE. --- NAMESPACE | 12 ++++++++---- kwb.db.Rproj | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7f65325..4ac6e4a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -45,10 +45,14 @@ export(sqlJoinExpression) export(sqlLeftJoinExpression) export(xmdb) importFrom(RODBC,odbcConnect) -importFrom(RODBC,odbcConnectAccess) -importFrom(RODBC,odbcConnectAccess2007) -importFrom(RODBC,odbcConnectExcel) -importFrom(RODBC,odbcConnectExcel2007) + +if(tools:::.OStype() == "windows") { + importFrom(RODBC,odbcConnectAccess) + importFrom(RODBC,odbcConnectAccess2007) + importFrom(RODBC,odbcConnectExcel) + importFrom(RODBC,odbcConnectExcel2007) +} + importFrom(RODBC,odbcDataSources) importFrom(RODBC,sqlColumns) importFrom(RODBC,sqlDrop) diff --git a/kwb.db.Rproj b/kwb.db.Rproj index 1788e68..574014a 100644 --- a/kwb.db.Rproj +++ b/kwb.db.Rproj @@ -15,4 +15,4 @@ LaTeX: pdfLaTeX BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace,vignette +PackageRoxygenize: rd,collate,vignette From de3b4cacabf7f939c296a18d2a88497a2fcd84bd Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 3 Nov 2019 21:08:42 +0100 Subject: [PATCH 27/28] Switch between functions from RODBC and odbc32 --- DESCRIPTION | 10 ++++---- NAMESPACE | 3 ++- R/base.R | 20 ++++------------ R/connect.R | 42 +++++++++++++++++----------------- R/logical.R | 5 +++- R/main.R | 11 ++++----- R/utils.R | 8 +++++++ inst/extdata/snippets_64_bit.R | 8 +++---- 8 files changed, 53 insertions(+), 54 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 04abc60..9cf5e8d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,12 +27,12 @@ Authors@R: person(given = "Kompetenzzentrum Wasser Berlin gGmbH", role = "cph")) Imports: - kwb.datetime, - kwb.utils, - odbc32, - RODBC + kwb.datetime (>= 0.4.0), + kwb.utils (>= 0.4.4), + odbc32 (>= 0.2.7), + RODBC (>= 1.3.16) Suggests: - testthat + testthat (>= 2.2.1) Remotes: github::kwb-r/kwb.datetime, github::kwb-r/kwb.utils, diff --git a/NAMESPACE b/NAMESPACE index cc2fa13..16e84c1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ -# Generated by roxygen2: do not edit by hand +# Originally generated by roxygen2 but then modified so that the functions +# odbcConnect...() are only imported on a Windows machine (see below) export(createRDatabaseInterface) export(currentDb) diff --git a/R/base.R b/R/base.R index f13d2e4..026d9a9 100644 --- a/R/base.R +++ b/R/base.R @@ -110,18 +110,12 @@ hsPutTable <- function( arguments <- c(arguments, list(varTypes = types)) } - # Select the appropriate function - FUN <- if (is64BitR()) { - odbc32::sqlSave - } else { - RODBC::sqlSave - } - - # Call the function that saves the data to the database table + # Call the function that saves the data to the database table. + # Select the appropriate function by means of get_odbc_function() result <- kwb.utils::catAndRun( dbg = dbg, messageText = sprintf("Writing data to table '%s' in '%s'\n", tblSafe, mdb), - expr = do.call(FUN, arguments) + expr = do.call(get_odbc_function("sqlSave"), arguments) ) # Did an error occur? @@ -349,12 +343,8 @@ hsTables <- function( setCurrentSqlDialect(sqlDialect) }) - tblList <- if (is64BitR()) { - odbc32::sqlTables(con) - } else { - RODBC::sqlTables(con) - } - + tblList <- (get_odbc_function("sqlTables"))(con) + if (excludeSystemTables) { tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] } diff --git a/R/connect.R b/R/connect.R index 1cd1d81..cc4bf30 100644 --- a/R/connect.R +++ b/R/connect.R @@ -122,6 +122,7 @@ hsOpenDb <- function( #' \code{odbcConnectionExcel} or \code{\link[RODBC]{odbcConnect}} #' @importFrom kwb.utils catIf #' @importFrom RODBC odbcConnect odbcDataSources +#' @importFrom odbc32 odbcConnect odbcDataSources #' openAdequateConnectionOrStop <- function( db, use2007Driver = NULL, dbg = FALSE, DBMSencoding = "", ... @@ -134,7 +135,7 @@ openAdequateConnectionOrStop <- function( is_mdb <- isAccessFile(db) is_xls <- isExcelFile(db) - if ((is_mdb || is_xls) &&! file.exists(db)) clean_stop( + if ((is_mdb || is_xls) && ! file.exists(db)) clean_stop( "No such file: '", db, "'! Please check the path!" ) @@ -222,14 +223,19 @@ odbcConnectionExcel32 <- function(db, use2007Driver, ...) odbcConnectionAccess64 <- function(db, use2007Driver) { - if (! use2007Driver) clean_stop( - "Cannot connect to ", db, " with 64 Bit-Version of R!" - ) - - odbc32::odbcConnectAccess2007(db, socket = kwb.utils::defaultIfNULL( + socket <- kwb.utils::defaultIfNULL( x = .GlobalEnv$.r2r_socket, default = odbc32::start_server(invisible = TRUE) - )) + ) + + if (use2007Driver) { + + odbc32::odbcConnectAccess2007(db, socket = socket) + + } else { + + odbc32::odbcConnectAccess(db, socket = socket) + } } # hsCloseMdb ------------------------------------------------------------------- @@ -261,22 +267,16 @@ hsCloseMdb <- function(con) #' hsCloseDb <- function(con) { - ## Close database connection - if (is64BitR()) { - - odbc32::odbcClose(con) - - socket <- .GlobalEnv$.r2r_socket - - if (! is.null(socket)) { - odbc32::stop_server(socket = socket) - rm(".r2r_socket", envir = .GlobalEnv) - } + # Close database connection + (get_odbc_function("odbcClose"))(con) + + # Stop the 32 Bit R server if it is running + if (is64BitR() && ! is.null(socket <- .GlobalEnv$.r2r_socket)) { - } else { + odbc32::stop_server(socket = socket) - RODBC::odbcClose(con) + rm(".r2r_socket", envir = .GlobalEnv) } - + #options("kwb.db.current.sql.dialect" = NULL) } diff --git a/R/logical.R b/R/logical.R index 23abea3..dd2e708 100644 --- a/R/logical.R +++ b/R/logical.R @@ -114,8 +114,11 @@ isMySQL <- function(db, ..., con = NULL) # isOdbcDataSource ------------------------------------------------------------- #' @importFrom RODBC odbcDataSources +#' @importFrom odbc32 odbcDataSources #' isOdbcDataSource <- function(db) { - db %in% names(RODBC::odbcDataSources()) + data_sources <- (get_odbc_function("odbcDataSources"))() + + db %in% names(data_sources) } diff --git a/R/main.R b/R/main.R index 02fcd71..b3d6820 100644 --- a/R/main.R +++ b/R/main.R @@ -681,6 +681,8 @@ hsMdbTimeSeries <- function( #' @seealso \code{\link{hsClearTable}} #' @importFrom kwb.utils catIf #' @importFrom RODBC sqlDrop +#' @importFrom odbc32 sqlDrop + #' @export #' hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) @@ -702,7 +704,8 @@ hsDropTable <- function(mdb, tbl, isPtrn = FALSE, dbg = TRUE) if (tbl %in% existingTables) { kwb.utils::catAndRun(dbg = dbg, sprintf("Dropping table '%s'", tbl), { - RODBC::sqlDrop(con, tbl) + + (get_odbc_function("sqlDrop"))(con, tbl) }) } else { @@ -868,11 +871,7 @@ hsSqlQuery <- function( ## Send SQL query kwb.utils::catIf(dbg, sprintf("\nRunning SQL: %s\n\n", sql)) - res <- if (is64BitR()) { - odbc32::sqlQuery(con, sql, ...) - } else { - RODBC::sqlQuery(con, sql, ...) - } + res <- (get_odbc_function("sqlQuery"))(con, sql, ...) # Did an error occur? if ((class(res) == "character") && (length(res) > 0)) { diff --git a/R/utils.R b/R/utils.R index 44b721f..02562a3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -3,3 +3,11 @@ clean_stop <- function(...) { stop(call. = FALSE, ...) } + +# get_odbc_function ------------------------------------------------------------ +get_odbc_function <- function(function_name) +{ + package <- if (is64BitR()) "odbc32" else "RODBC" + + getExportedValue(package, function_name) +} diff --git a/inst/extdata/snippets_64_bit.R b/inst/extdata/snippets_64_bit.R index 40c0981..3ef5a1b 100644 --- a/inst/extdata/snippets_64_bit.R +++ b/inst/extdata/snippets_64_bit.R @@ -25,16 +25,14 @@ is_64_bit <- (.Machine$sizeof.pointer == 8) - tblList <- RODBC::sqlTables(con) - tblList <- odbc32::sqlTables(con) - + tblList <- (kwb.db:::get_odbc_function("sqlTables"))(con) + if (excludeSystemTables) tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] if (namesOnly) { return(tblList$TABLE_NAME) - } - else { + } else { return(tblList) } #} \ No newline at end of file From 9fbcaa7b120f777f265604b748cfc09f147f2800 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 3 Nov 2019 22:46:36 +0100 Subject: [PATCH 28/28] Prepare new Release v0.4.0 --- DESCRIPTION | 2 +- NEWS | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9cf5e8d..3a9275f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: kwb.db -Version: 0.3.0.9000 +Version: 0.4.0 Title: Functions supporting data base access Description: This package contains some useful functions, especially for simplifying data transfer between MS Access databases and R. With the diff --git a/NEWS b/NEWS index 3645f4a..d5a448c 100644 --- a/NEWS +++ b/NEWS @@ -1,13 +1,21 @@ -2019-06-07 -- give a warning when using deprecated functions hsOpenMdb(), hsCloseMdb() - -2019-06-06 -- support 64 Bit in odbcConnectionAccess() - -Changes in kwb.db 0.1.1 -========================= -* xmdb now points to example database in this package not in kwb.base - -Changes in kwb.db 0.1.0 -========================= -* package created with functions that were originally in kwb.base +Changes in kwb.db 0.4.0 (2019-11-03) +==================================== +* Use the package odbc32 by Vaclav Hausenblas in order to use Window's 32 bit + ODBC driver from within a 64 bit R session. +* Decrease the number of exported functions. + TODO: Check if some functions need to be exported again as they may be used + in some scripts that were/are used at KWB. + +2019-06-07 +* give a warning when using deprecated functions hsOpenMdb(), hsCloseMdb() + +2019-06-06 +* support 64 Bit in odbcConnectionAccess() + +Changes in kwb.db 0.1.1 +======================= +* xmdb now points to example database in this package not in kwb.base + +Changes in kwb.db 0.1.0 +======================= +* package created with functions that were originally in kwb.base