# Correcciones de RODBC sqlFetch <- function (channel, sqtable, ..., colnames = FALSE, rownames = TRUE) { if (!odbcValidChannel(channel)) stop("first argument is not an open RODBC channel") if (missing(sqtable)) stop("Missing argument 'sqtable'") dbname <- odbcTableExists(channel, sqtable) DBMS <- odbcGetInfo(channel)[1] if (DBMS == "ACCESS" && length(grep(" ", dbname))) dbname <- paste("[", dbname, "]", sep = "") ans <- sqlQuery(channel, paste("SELECT * FROM", dbname), ...) if (is.data.frame(ans)) { if (is.logical(colnames) && colnames) { colnames(ans) <- as.character(as.matrix(ans[1, ])) ans <- ans[-1, ] } if (is.logical(rownames) && rownames) rownames <- "rownames" if (is.character(rownames)) { cn <- names(ans) if (!is.na(rn <- match(rownames, cn))) { row.names(ans) <- as.character(ans[, rn]) ans <- ans[, -rn, drop = FALSE] } } } ans } odbcValidChannel <- function (channel) { inherits(channel, "RODBC") && is.integer(channel) && .Call("RODBCcheckchannel", channel, attr(channel, "id"), PACKAGE = "RODBC") > 0 } odbcTableExists <- function (channel, tablename, abort = TRUE) { if (!odbcValidChannel(channel)) stop("first argument is not an open RODBC channel") if (length(tablename) != 1) stop(paste(tablename, "should be a name")) tablename <- as.character(tablename) switch(attr(channel, "case"), nochange = { }, toupper = tablename <- toupper(tablename), tolower = tablename <- tolower(tablename)) res <- sqlTables(channel) tables <- if (is.data.frame(res)) res[, 3] else "" stables <- sub("\\$$", "", tables) ans <- tablename %in% stables if (abort && !ans) stop(paste(tablename, ": table not found on channel")) if (ans) { dbname <- tables[match(tablename, stables)] if (tablename != dbname) paste("[", tablename, "$]", sep = "") else tablename } else character(0) } # Final de correcciones de RODBC