Skip to content

Commit ddd23ff

Browse files
committed
Merge pull request #7 from teramonagi/feature/issue1
First release(ver 0.1)
2 parents 506a375 + 1405a9c commit ddd23ff

15 files changed

+112
-19
lines changed

DESCRIPTION

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Package: RODBCDBI
22
Type: Package
33
Version: 0.1
4-
Title: Provides access to databases through the ODBC interface
4+
Title: Provides Access to Databases Through the ODBC Interface
55
Author: teramonagi
6-
Maintainer: teramonagi <[email protected]>
7-
Description: RODBCDBI is an implementation of R's DBI interface using ODBC as a
6+
Maintainer: Nagi Teramo <[email protected]>
7+
Description: An implementation of R's DBI interface using ODBC package as a
88
back-end. This allows R to connect to any DBMS that has a ODBC driver.
9-
License: BSD
9+
License: MIT + file LICENSE
1010
Imports:
1111
methods,
1212
DBI,

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2015-2015
2+
COPYRIGHT HOLDER: Nagi Teramo

R/ODBCConnection.R

+32-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ setClass(
1212
slots=list(odbc="RODBC")
1313
)
1414

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
1520
#' @export
1621
#' @rdname odbc-query
1722
setMethod("dbSendQuery", "ODBCConnection", function(conn, statement, ...) {
@@ -21,22 +26,27 @@ setMethod("dbSendQuery", "ODBCConnection", function(conn, statement, ...) {
2126
new("ODBCResult", connection=conn, sql=statement, state=env)
2227
})
2328

29+
#' Get DBMS metadata.
30+
#'
31+
#' @param dbObj An object inheriting from \code{\linkS4class{ODBCConnection}}, \code{\linkS4class{ODBCDriver}}, or a \code{\linkS4class{ODBCResult}}
2432
#' @export
2533
#' @rdname ODBCConnection-class
26-
setMethod("dbGetInfo", "ODBCConnection", function(dbObj, ...) {odbcGetInfo(dbObj@odbc)})
34+
setMethod("dbGetInfo", "ODBCConnection", function(dbObj, ...) {dbObj(dbObj@odbc)})
2735

2836

2937
#' List fields in specified table.
3038
#'
31-
#' @param conn An existing \code{\linkS4class{RODBCConnection}}
39+
#' @param conn An existing \code{\linkS4class{ODBCConnection}}
3240
#' @param name a length 1 character vector giving the name of a table.
3341
#' @export
3442
#' @examples
43+
#' \dontrun{
3544
#' library(DBI)
3645
#' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
3746
#' dbWriteTable(con, "iris", iris, overwrite=TRUE)
3847
#' dbListFields(con, "iris")
3948
#' dbDisconnect(con)
49+
#' }
4050
setMethod("dbListFields", c("ODBCConnection", "character"), function(conn, name) {
4151
sqlColumns(conn@odbc, name)$COLUMN_NAME
4252
})
@@ -53,27 +63,32 @@ setMethod("dbListTables", "ODBCConnection", function(conn){
5363
#'
5464
#' @export
5565
#' @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}}
5767
#' @param name a character string specifying a table name. ODBCConnection table names
5868
#' are \emph{not} case sensitive, e.g., table names \code{ABC} and \code{abc}
5969
#' are considered equal.
6070
#' @param value a data.frame (or coercible to data.frame) object or a
6171
#' 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.
6275
#' @export
6376
#' @examples
77+
#' \dontrun{
6478
#' library(DBI)
6579
#' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
6680
#' dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
6781
#' dbReadTable(con, "mtcars")
6882
#' dbDisconnect(con)
83+
#' }
6984
setMethod("dbWriteTable", c("ODBCConnection", "character", "data.frame"), function(conn, name, value, overwrite=FALSE, append=FALSE, ...) {
7085
sqlSave(conn@odbc, dat=value, tablename=name, safer=!overwrite, append=append, ...)
7186
invisible(TRUE)
7287
})
7388

7489
#' Does the table exist?
7590
#'
76-
#' @param conn An existing \code{\linkS4class{SQLiteConnection}}
91+
#' @param conn An existing \code{\linkS4class{ODBCConnection}}
7792
#' @param name String, name of table. Match is case insensitive.
7893
#' @export
7994
setMethod("dbExistsTable", c("ODBCConnection", "character"), function(conn, name) {
@@ -107,13 +122,15 @@ setMethod("dbRemoveTable", c("ODBCConnection", "character"), function(conn, name
107122
#'
108123
#' @param conn a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}
109124
#' @param name a character string specifying a table name.
125+
#' @param row.names a character string specifying a table name.
110126
#' @param check.names If \code{TRUE}, the default, column names will be converted to valid R identifiers.
111127
#' @param select.cols A SQL statement (in the form of a character vector of
112128
#' length 1) giving the columns to select. E.g. "*" selects all columns,
113129
#' "x,y,z" selects three columns named as listed.
114130
#' @inheritParams DBI::rownamesToColumn
115131
#' @export
116132
#' @examples
133+
#' \dontrun{
117134
#' library(DBI)
118135
#' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
119136
#' dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
@@ -125,6 +142,7 @@ setMethod("dbRemoveTable", c("ODBCConnection", "character"), function(conn, name
125142
#' dbGetQuery(con, "SELECT * FROM mtcars WHERE cyl = 8", row.names = FALSE)
126143
#'
127144
#' dbDisconnect(con)
145+
#' }
128146
setMethod("dbReadTable", c("ODBCConnection", "character"), function(conn, name, row.names = NA, check.names = TRUE, select.cols = "*") {
129147
out <- dbGetQuery(conn, paste("SELECT", select.cols, "FROM", name), row.names = row.names)
130148
if (check.names) {
@@ -133,6 +151,16 @@ setMethod("dbReadTable", c("ODBCConnection", "character"), function(conn, name,
133151
out
134152
})
135153

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+
#' }
136164
#' @export
137165
setMethod("dbDisconnect", "ODBCConnection", function(conn) {
138166
if (RODBC:::odbcValidChannel(conn@odbc)){

R/ODBCDriver.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#' @export
66
#' @import methods DBI
77
#' @examples
8-
#' library(DBI)
8+
#' \dontrun{
9+
#' #' library(DBI)
910
#' RODBCDBI::ODBC()
11+
#' }
1012
ODBC <- function() {new("ODBCDriver")}
1113

1214
#' ODBCDriver and methods.

R/ODBCResult.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ is_done <- function(x) {
3232
#' @inheritParams DBI::rownamesToColumn
3333
#' @export
3434
#' @rdname odbc-query
35-
setMethod("dbFetch", "ODBCResult", function(res, n = -1, ..., row.names = NA) {
35+
setMethod("dbFetch", "ODBCResult", function(res, n = -1, ...) {
3636
result <- sqlQuery(res@connection@odbc, res@sql)
3737
res
3838
is_done(res) <- TRUE
@@ -58,9 +58,11 @@ setMethod("dbClearResult", "ODBCResult", function(res, ...) {
5858
#'
5959
#' See documentation of generics for more details.
6060
#'
61+
#' @param dbObj An object inheriting from \code{\linkS4class{ODBCConnection}}, \code{\linkS4class{ODBCDriver}}, or a \code{\linkS4class{ODBCResult}}
6162
#' @param res An object of class \code{\linkS4class{ODBCResult}}
6263
#' @param ... Ignored. Needed for compatibility with generic
6364
#' @examples
65+
#' \dontrun{
6466
#' library(DBI)
6567
#' data(USArrests)
6668
#' con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
@@ -87,11 +89,12 @@ setMethod("dbClearResult", "ODBCResult", function(res, ...) {
8789
#' names(dbGetInfo(con))
8890
#'
8991
#' dbDisconnect(con)
92+
#' }
9093
#' @name odbc-meta
9194
NULL
9295

93-
#' @export
9496
#' @rdname odbc-meta
97+
#' @export
9598
setMethod("dbGetRowCount", "ODBCResult", function(res, ...) {
9699
unlist(dbGetQuery(res@connection, "SELECT count(*) FROM iris"))
97100
})
@@ -105,6 +108,6 @@ setMethod("dbGetStatement", "ODBCResult", function(res, ...) {
105108
#' @rdname odbc-meta
106109
#' @export
107110
setMethod("dbGetInfo", "ODBCResult", function(dbObj, ...) {
108-
#
111+
# mock implementation
109112
NULL
110113
})

man/ODBC.Rd

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ ODBC()
1010
This driver never needs to be unloaded and hence \code{dbUnload()} is a null-op.
1111
}
1212
\examples{
13-
library(DBI)
13+
\dontrun{
14+
#' library(DBI)
1415
RODBCDBI::ODBC()
1516
}
17+
}
1618

man/ODBCConnection-class.Rd

+5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
\usage{
99
\S4method{dbGetInfo}{ODBCConnection}(dbObj, ...)
1010
}
11+
\arguments{
12+
\item{dbObj}{An object inheriting from \code{\linkS4class{ODBCConnection}}, \code{\linkS4class{ODBCDriver}}, or a \code{\linkS4class{ODBCResult}}}
13+
}
1114
\description{
1215
\code{ODBCConnection} objects are usually created by \code{\link[DBI]{dbConnect}}
16+
17+
Get DBMS metadata.
1318
}
1419
\keyword{internal}
1520

man/dbDisconnect.Rd

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/ODBCConnection.R
3+
\docType{methods}
4+
\name{dbDisconnect,ODBCConnection-method}
5+
\alias{dbDisconnect,ODBCConnection-method}
6+
\title{Close a current session.}
7+
\usage{
8+
\S4method{dbDisconnect}{ODBCConnection}(conn)
9+
}
10+
\arguments{
11+
\item{conn}{a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}}
12+
}
13+
\description{
14+
Close a current session.
15+
}
16+
\examples{
17+
\dontrun{
18+
library(DBI)
19+
con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
20+
dbDisconnect(con)
21+
}
22+
}
23+

man/dbExistsTable-ODBCConnection-character-method.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
\S4method{dbExistsTable}{ODBCConnection,character}(conn, name)
99
}
1010
\arguments{
11-
\item{conn}{An existing \code{\linkS4class{SQLiteConnection}}}
11+
\item{conn}{An existing \code{\linkS4class{ODBCConnection}}}
1212

1313
\item{name}{String, name of table. Match is case insensitive.}
1414
}

man/dbListFields-ODBCConnection-character-method.Rd

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
\S4method{dbListFields}{ODBCConnection,character}(conn, name)
99
}
1010
\arguments{
11-
\item{conn}{An existing \code{\linkS4class{RODBCConnection}}}
11+
\item{conn}{An existing \code{\linkS4class{ODBCConnection}}}
1212

1313
\item{name}{a length 1 character vector giving the name of a table.}
1414
}
1515
\description{
1616
List fields in specified table.
1717
}
1818
\examples{
19+
\dontrun{
1920
library(DBI)
2021
con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
2122
dbWriteTable(con, "iris", iris, overwrite=TRUE)
2223
dbListFields(con, "iris")
2324
dbDisconnect(con)
2425
}
26+
}
2527

man/dbReadTable-ODBCConnection-character-method.Rd

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
\item{name}{a character string specifying a table name.}
1515

16+
\item{row.names}{a character string specifying a table name.}
17+
1618
\item{check.names}{If \code{TRUE}, the default, column names will be converted to valid R identifiers.}
1719

1820
\item{select.cols}{A SQL statement (in the form of a character vector of
@@ -33,6 +35,7 @@ Note that the data.frame returned by \code{dbReadTable} only has
3335
primitive data, e.g., it does not coerce character data to factors.
3436
}
3537
\examples{
38+
\dontrun{
3639
library(DBI)
3740
con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
3841
dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
@@ -45,4 +48,5 @@ dbGetQuery(con, "SELECT * FROM mtcars WHERE cyl = 8", row.names = FALSE)
4548

4649
dbDisconnect(con)
4750
}
51+
}
4852

man/dbWriteTable.Rd

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@
99
overwrite = FALSE, append = FALSE, ...)
1010
}
1111
\arguments{
12+
\item{conn}{a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}}
13+
1214
\item{name}{a character string specifying a table name. ODBCConnection table names
1315
are \emph{not} case sensitive, e.g., table names \code{ABC} and \code{abc}
1416
are considered equal.}
1517

1618
\item{value}{a data.frame (or coercible to data.frame) object or a
1719
file name (character). when \code{value} is a character, it is interpreted as a file name and its contents imported to ODBC.}
1820

19-
\item{con,conn}{a \code{\linkS4class{ODBCConnection}} object, produced by \code{\link[DBI]{dbConnect}}}
21+
\item{overwrite}{logical. Should data be overwritten?}
22+
23+
\item{append}{logical. Should data be appended to an existing table?}
24+
25+
\item{...}{additional arguments passed to the generic.}
2026
}
2127
\description{
2228
Write a local data frame or file to the database.
2329
}
2430
\examples{
31+
\dontrun{
2532
library(DBI)
2633
con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
2734
dbWriteTable(con, "mtcars", mtcars, overwrite=TRUE)
2835
dbReadTable(con, "mtcars")
2936
dbDisconnect(con)
3037
}
38+
}
3139

man/odbc-meta.Rd

+4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
\item{res}{An object of class \code{\linkS4class{ODBCResult}}}
1919

2020
\item{...}{Ignored. Needed for compatibility with generic}
21+
22+
\item{dbObj}{An object inheriting from \code{\linkS4class{ODBCConnection}}, \code{\linkS4class{ODBCDriver}}, or a \code{\linkS4class{ODBCResult}}}
2123
}
2224
\description{
2325
See documentation of generics for more details.
2426
}
2527
\examples{
28+
\dontrun{
2629
library(DBI)
2730
data(USArrests)
2831
con <- dbConnect(RODBCDBI::ODBC(), dsn="test", user="sa", password="Password12!")
@@ -50,4 +53,5 @@ names(dbGetInfo(con))
5053

5154
dbDisconnect(con)
5255
}
56+
}
5357

man/odbc-query.Rd

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66
\alias{dbFetch,ODBCResult-method}
77
\alias{dbHasCompleted,ODBCResult-method}
88
\alias{dbSendQuery,ODBCConnection-method}
9-
\title{Execute a SQL statement on a database connection}
9+
\title{Execute a statement on a given database connection.}
1010
\usage{
1111
\S4method{dbSendQuery}{ODBCConnection}(conn, statement, ...)
1212

13-
\S4method{dbFetch}{ODBCResult}(res, n = -1, ..., row.names = NA)
13+
\S4method{dbFetch}{ODBCResult}(res, n = -1, ...)
1414

1515
\S4method{dbHasCompleted}{ODBCResult}(res, ...)
1616

1717
\S4method{dbClearResult}{ODBCResult}(res, ...)
1818
}
1919
\arguments{
20+
\item{conn}{An existing \code{\linkS4class{ODBCConnection}}}
21+
22+
\item{statement}{a character vector of length 1 containing SQL}
23+
24+
\item{...}{Other parameters passed on to methods}
25+
2026
\item{res}{Code a \linkS4class{ODBCResult} produced by \code{\link[DBI]{dbSendQuery}}.}
2127

2228
\item{n}{Number of rows to return. If less than zero returns all rows.}
2329
}
2430
\description{
31+
Execute a statement on a given database connection.
32+
2533
To retrieve results a chunk at a time, use \code{dbSendQuery},
2634
\code{dbFetch}, then \code{ClearResult}. Alternatively, if you want all the
2735
results (and they'll fit in memory) use \code{dbGetQuery} which sends,

tests/testthat.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
library("testthat")
22
library("RODBCDBI")
3-
test_check("RODBCDBI")
3+
if (identical(Sys.getenv("NOT_CRAN"), "true")){
4+
test_check("RODBCDBI")
5+
}

0 commit comments

Comments
 (0)