1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
% $Id: dbReadTable-methods.Rd,v 1.2 2003/12/02 15:58:29 dj Exp dj $
\name{dbReadTable-methods}
\docType{methods}
\alias{dbReadTable-methods}
\alias{dbWriteTable-methods}
\alias{dbExistsTable-methods}
\alias{dbRemoveTable-methods}
\alias{dbReadTable,MySQLConnection,character-method}
\alias{dbWriteTable,MySQLConnection,character,data.frame-method}
\alias{dbExistsTable,MySQLConnection,character-method}
\alias{dbRemoveTable,MySQLConnection,character-method}
\title{
Convenience functions for Importing/Exporting DBMS tables
}
\description{
These functions mimic their R/S-Plus counterpart
\code{get},
\code{assign},
\code{exists},
\code{remove}, and
\code{objects},
except that they generate code that gets remotely executed
in a database engine.
}
\section{Methods}{\describe{
\item{conn}{
an \code{MySQLConnection} database connection object.
}
\item{name}{
a character string specifying a table name.
}
\item{value}{
a data.frame (or coercible to data.frame).
}
\item{row.names}{
in the case of \code{dbReadTable}, this argument can be a string or
an index specifying the column in the DBMS table to be used as
\code{row.names} in the output data.frame (a \code{NULL}, \code{""}, or 0
specifies that no column should be used as \code{row.names} in the output).
In the case of \code{dbWriteTable}, this argument should be a logical
specifying whether the \code{row.names} should be output to the
output DBMS table; if \code{TRUE}, an extra field whose name will be
whatever the R/S-Plus identifier \code{"row.names"} maps to the DBMS
(see \code{\link[DBI]{make.db.names}}).
}
\item{overwrite}{
a logical specifying whether to overwrite an existing table
or not. Its default is \code{FALSE}.
}
\item{append}{
a logical specifying whether to append to an existing table
in the DBMS. Its default is \code{FALSE}.
}
\item{allow.keywords}{
\code{dbWriteTable} accepts a logical \code{allow.keywords}
to allow or prevent MySQL reserved identifiers to be used as
column names. By default it is \code{FALSE}.
}
}
}
\value{
A \code{data.frame} in the case of \code{dbReadTable}; otherwise a logical
indicating whether the operation was successful.
}
\note{
Note that data.frames are only approximately analogous to tables
(relations) in relational DBMS, and thus you should not expect
complete agreement in their semantics. Tables in RDBMS are
best thought of as \emph{relations} with a number of constraints
imposed by the relational database model, and data.frames, with
their roots in statistical modeling, as self-contained "sequence
of observations on some chosen variables" (Chambers and Hastie
(1992), p.46).
In particular the \code{data.frame} returned by \code{dbReadTable}
only has primitive data, e.g., it does not coerce character data
to factors.
Also, column names in a data.frame are \emph{not} guaranteed to be
equal to the column names in a MySQL exported/imported table
(e.g., by default MySQL reserved identifiers may not be used
as column names --- and with 218 keywords like \code{"BEFORE"},
\code{"DESC"}, and \code{"FROM"} the likelihood of name conflicts
is not small.) Use \code{isSQLKeyword(con, names(value))} to check
whether the data.frame names in \code{value} coincide with
MySQL reserver words.
MySQL table names are \emph{not} case sensitive, e.g., table
names \code{ABC} and \code{abc} are considered equal.
}
\references{
See the Database Interface definition document
\code{DBI.pdf} in the base directory of this package
or \url{http://stat.bell-labs.com/RS-DBI}.
}
\seealso{
\code{\link{MySQL}},
\code{\link[DBI]{isSQLKeyword}},
\code{\link[DBI]{dbDriver}},
\code{\link[DBI]{dbConnect}},
\code{\link[DBI]{dbSendQuery}},
\code{\link[DBI]{dbGetQuery}},
\code{\link[DBI]{fetch}},
\code{\link[DBI]{dbCommit}},
\code{\link[DBI]{dbGetInfo}},
\code{\link[DBI]{dbListTables}},
\code{\link[DBI]{dbReadTable}}.
}
\examples{\dontrun{
conn <- dbConnect("MySQL", group = "wireless")
if(dbExistsTable(con, "fuel_frame")){
dbRemoveTable(conn, "fuel_frame")
dbWriteTable(conn, "fuel_frame", fuel.frame)
}
if(dbExistsTable(conn, "RESULTS")){
dbWriteTable(conn, "RESULTS", results2000, append = T)
else
dbWriteTable(conn, "RESULTS", results2000)
}
}
}
\keywords{methods}
\keyword{interface}
\keyword{database}
% vim: syntax=tex
|