sqlFetch {RODBC} | R Documentation |
Read a table of an ODBC database into a data frame.
sqlFetch(channel, sqtable, ..., colnames = FALSE, rownames = TRUE) sqlFetchMore(channel, ..., colnames = FALSE, rownames = TRUE)
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. |
sqlFetch
retrieves the the entire contents of the table
sqtable
. Rownames and column names are restored as indicated.
sqlFetchMore
will retrieve further results from the query
(provided there has been no other ODBC query on that channel in the
meantime).
It tries to cope with the peculiar way the Excel ODBC driver handles table names, and to quote Access table names which contain spaces.
Useful additional parameters to pass to sqlGetResults
include
max
:nullstring
:SQL_NULL_DATA
character items from the database.na.strings
:NA
when reading character data.as.is
:sqlGetResults
.dec
:
A data frame on success, or a character or numeric error code (see
sqlQuery
).
If the table name desired is not a valid SQL name (alphanumeric plus
_
), use sqlQuery
with whatever quoting mechanism
your DBMS vendor provides (e.g. [ ]
on Microsoft products and
backticks on recent versions of MySQL).
Michael Lapsley and Brian Ripley
sqlSave
, sqlQuery
,
odbcConnect
, odbcGetInfo
## Not run: data(USArrests) # R < 2.0.0 only channel <- odbcConnect("test") sqlSave(channel, USArrests, verbose = TRUE) sqlFetch(channel, "USArrests") # get the lot sqlFetch(channel, "USArrests", max=20) sqlFetchMore(channel, max=20) sqlFetchMore(channel) # get the rest sqlDrop(channel, "USArrests") close(channel) ## End(Not run)