@@ -12,6 +12,11 @@ setClass(
12
12
slots = list (odbc = " RODBC" )
13
13
)
14
14
15
+ # ' Execute a statement on a given database connection.
16
+ # '
17
+ # ' @param conn An existing \code{\linkS4class{ODBCConnection}}
18
+ # ' @param statement a character vector of length 1 containing SQL
19
+ # ' @param ... Other parameters passed on to methods
15
20
# ' @export
16
21
# ' @rdname odbc-query
17
22
setMethod ("dbSendQuery ", "ODBCConnection", function(conn, statement, ...) {
@@ -21,22 +26,27 @@ setMethod("dbSendQuery", "ODBCConnection", function(conn, statement, ...) {
21
26
new(" ODBCResult" , connection = conn , sql = statement , state = env )
22
27
})
23
28
29
+ # ' Get DBMS metadata.
30
+ # '
31
+ # ' @param dbObj An object inheriting from \code{\linkS4class{ODBCConnection}}, \code{\linkS4class{ODBCDriver}}, or a \code{\linkS4class{ODBCResult}}
24
32
# ' @export
25
33
# ' @rdname ODBCConnection-class
26
- setMethod ("dbGetInfo ", "ODBCConnection", function(dbObj, ...) {odbcGetInfo (dbObj@odbc)})
34
+ setMethod ("dbGetInfo ", "ODBCConnection", function(dbObj, ...) {dbObj (dbObj@odbc)})
27
35
28
36
29
37
# ' List fields in specified table.
30
38
# '
31
- # ' @param conn An existing \code{\linkS4class{RODBCConnection }}
39
+ # ' @param conn An existing \code{\linkS4class{ODBCConnection }}
32
40
# ' @param name a length 1 character vector giving the name of a table.
33
41
# ' @export
34
42
# ' @examples
43
+ # ' \dontrun{
35
44
# ' library(DBI)
36
45
# ' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
37
46
# ' dbWriteTable(con, "iris", iris, overwrite=TRUE)
38
47
# ' dbListFields(con, "iris")
39
48
# ' dbDisconnect(con)
49
+ # ' }
40
50
setMethod ("dbListFields ", c("ODBCConnection", "character"), function(conn, name) {
41
51
sqlColumns(conn @ odbc , name )$ COLUMN_NAME
42
52
})
@@ -53,27 +63,32 @@ setMethod("dbListTables", "ODBCConnection", function(conn){
53
63
# '
54
64
# ' @export
55
65
# ' @rdname dbWriteTable
56
- # ' @param con, conn a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}
66
+ # ' @param conn a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}
57
67
# ' @param name a character string specifying a table name. ODBCConnection table names
58
68
# ' are \emph{not} case sensitive, e.g., table names \code{ABC} and \code{abc}
59
69
# ' are considered equal.
60
70
# ' @param value a data.frame (or coercible to data.frame) object or a
61
71
# ' file name (character). when \code{value} is a character, it is interpreted as a file name and its contents imported to ODBC.
72
+ # ' @param overwrite logical. Should data be overwritten?
73
+ # ' @param append logical. Should data be appended to an existing table?
74
+ # ' @param ... additional arguments passed to the generic.
62
75
# ' @export
63
76
# ' @examples
77
+ # ' \dontrun{
64
78
# ' library(DBI)
65
79
# ' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
66
80
# ' dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
67
81
# ' dbReadTable(con, "mtcars")
68
82
# ' dbDisconnect(con)
83
+ # ' }
69
84
setMethod ("dbWriteTable ", c("ODBCConnection", "character", "data.frame"), function(conn, name, value, overwrite=FALSE, append=FALSE, ...) {
70
85
sqlSave(conn @ odbc , dat = value , tablename = name , safer = ! overwrite , append = append , ... )
71
86
invisible (TRUE )
72
87
})
73
88
74
89
# ' Does the table exist?
75
90
# '
76
- # ' @param conn An existing \code{\linkS4class{SQLiteConnection }}
91
+ # ' @param conn An existing \code{\linkS4class{ODBCConnection }}
77
92
# ' @param name String, name of table. Match is case insensitive.
78
93
# ' @export
79
94
setMethod ("dbExistsTable ", c("ODBCConnection", "character"), function(conn, name) {
@@ -107,13 +122,15 @@ setMethod("dbRemoveTable", c("ODBCConnection", "character"), function(conn, name
107
122
# '
108
123
# ' @param conn a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}
109
124
# ' @param name a character string specifying a table name.
125
+ # ' @param row.names a character string specifying a table name.
110
126
# ' @param check.names If \code{TRUE}, the default, column names will be converted to valid R identifiers.
111
127
# ' @param select.cols A SQL statement (in the form of a character vector of
112
128
# ' length 1) giving the columns to select. E.g. "*" selects all columns,
113
129
# ' "x,y,z" selects three columns named as listed.
114
130
# ' @inheritParams DBI::rownamesToColumn
115
131
# ' @export
116
132
# ' @examples
133
+ # ' \dontrun{
117
134
# ' library(DBI)
118
135
# ' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
119
136
# ' dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
@@ -125,6 +142,7 @@ setMethod("dbRemoveTable", c("ODBCConnection", "character"), function(conn, name
125
142
# ' dbGetQuery(con, "SELECT * FROM mtcars WHERE cyl = 8", row.names = FALSE)
126
143
# '
127
144
# ' dbDisconnect(con)
145
+ # ' }
128
146
setMethod ("dbReadTable ", c("ODBCConnection", "character"), function(conn, name, row.names = NA, check.names = TRUE, select.cols = "*") {
129
147
out <- dbGetQuery(conn , paste(" SELECT" , select.cols , " FROM" , name ), row.names = row.names )
130
148
if (check.names ) {
@@ -133,6 +151,16 @@ setMethod("dbReadTable", c("ODBCConnection", "character"), function(conn, name,
133
151
out
134
152
})
135
153
154
+ # ' Close a current session.
155
+ # '
156
+ # ' @rdname dbDisconnect
157
+ # ' @param conn a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}
158
+ # ' @examples
159
+ # ' \dontrun{
160
+ # ' library(DBI)
161
+ # ' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
162
+ # ' dbDisconnect(con)
163
+ # ' }
136
164
# ' @export
137
165
setMethod ("dbDisconnect ", "ODBCConnection", function(conn) {
138
166
if (RODBC ::: odbcValidChannel(conn @ odbc )){
0 commit comments