sqlFetch {RODBC}R Documentation

Reading Tables from ODBC Databases

Description

Read a table of an ODBC database into a data frame.

Usage

sqlFetch(channel, sqtable, ..., colnames = FALSE, rownames = TRUE)

Arguments

channel connection handle returned by odbcConnect.
sqtable a database table name accessible from the connected dsn. This should be either a character string or a character vector of length 1.
... additional arguments to be passed to sqlGetResults.
colnames logical: retrieve column names from first row of table?
rownames either logical or character. If logical, retrieve row names from the first column (rownames) in the table? If character, the column name to retrieve them.

Details

sqlFetch retrieves the the entire contents of the table sqtable. Rownames and column names are restored as indicated.

It tries to cope with the peculiar way the Excel ODBC driver handles table names.

Useful additional parameters to pass to sqlGetResults include

max:
limit on the number of rows to fetch, with 0 (the default) indicating no limit.
item{nullstring}:{character string to be used when reading SQL_NULL_DATA character items from the database.}
na.strings:
character string(s) to be mapped to NA when reading character data.
as.is:
as in sqlGetResults.
dec:
The character for the decimal place to be assumed when converting character columns.

Value

A data frame on success, or a character or numeric error code (see sqlQuery).

Author(s)

Michael Lapsley and Brian Ripley

See Also

sqlSave, sqlQuery, odbcConnect, odbcGetInfo

Examples

## Not run: 
library(RODBC)
data(USArrests)
channel <- odbcConnect("test", "", "") # userId and password
sqlSave(channel, USArrests, verbose = TRUE)
sqlFetch(channel, "USArrests") # get the lot
sqlDrop(channel, "USArrests") 
odbcClose(channel)
## End(Not run)

[Package Contents]