R/maptypes.R

Defines functions dbSetTypeMaps .remap.types

## default type maps
.type.map <- as.environment(list(
    DATE = function(x) as.Date(x, "%Y-%m-%d"),
    DATETIME = function(x) as.POSIXct(x, format="%Y-%m-%d %H:%M:%OS"),
    TIMESTAMP = function(x) as.POSIXct(x, format="%Y-%m-%d %H:%M:%OS")
))

.remap.types <- function(d, ct) {
    mn <- names(JDBC.types)[match(ct, JDBC.types)]
    for(i in seq_along(mn))
        if (!is.na(mn[i]) && !is.null(f <- .type.map[[mn[i]]]))
            d[[i]] <- f(d[[i]])
    d
}

dbSetTypeMaps <- function(...) {
    l <- list(...)
    if (length(l) && is.null(names(l)))
        stop("Type maps must be named")
    for (i in names(l))
        .type.map[[i]] <- l[[i]]
    as.list(.type.map)
}

Try the RJDBC package in your browser

Any scripts or data that you put into this service are public.

RJDBC documentation built on March 24, 2022, 5:07 p.m.