Skip to content
Browse files

Fixing up test.R yet again

  • Loading branch information...
1 parent d250054 commit b347adef5a508c5f2fa592faa04d9c9b19b7b47f @jeffreyhorner jeffreyhorner committed
Showing with 88 additions and 86 deletions.
  1. +2 −3 DESCRIPTION
  2. +51 −64 tests/tests.R
  3. +35 −19 tests/tests.Rout.save
View
5 DESCRIPTION
@@ -1,6 +1,6 @@
Package: RMySQL
-Version: 0.9-2
-Date: 2012-01-12
+Version: 0.9-3
+Date: 2012-01-17
Title: R interface to the MySQL database
Author: David A. James and Saikat DebRoy
Maintainer: Jeffrey Horner <jeffrey.horner@gmail.com>
@@ -13,4 +13,3 @@ License: GPL-2
URL: http://biostat.mc.vanderbilt.edu/RMySQL,
https://github.com/jeffreyhorner/RMySQL
Collate: S4R.R zzz.R MySQLSupport.R dbObjectId.R MySQL.R
-Packaged: 2011-06-03 17:41:17 UTC; hornerj
View
115 tests/tests.R
@@ -1,79 +1,66 @@
-library(RMySQL)
-
-
-## 0 dbConnect()
-user <- Sys.getenv("MYSQL_USER", unset = NA)
+library(RMySQL)
+
+
+## 0 dbConnect()
+user <- Sys.getenv("MYSQL_USER", unset = NA)
password <- Sys.getenv("MYSQL_PASSWORD", unset = '')
dbname <- Sys.getenv("MYSQL_DATABASE", unset = "test")
drv <- dbDriver("MySQL")
+
conn <- try(if (is.na(user)) {
# in this leg user and password should be set in my.ini or my.cnf files
dbConnect(drv, dbname = dbname)
} else {
dbConnect(drv, user = user, password = password, dbname = dbname)
})
+
if (inherits(conn, "try-error")) {
cat("unable to connect to MySQL\n")
q()
}
-
-# dbListTables(conn)
-
-## 1 Ensure that dbWriteTable doesn't add trailing \r
-dbRemoveTable(conn, "myDF") # precaution
-## RMySQL is not very clever: it does not convert to factor,
-## and converts row names to character.
-myDF <- data.frame(x = paste("x", 1:5, sep = ""),
- y = paste("y", 1:5, sep = ""),
- row.names = letters[1:5],
- stringsAsFactors = FALSE)
-dbWriteTable(conn, name= "myDF", value = myDF)
-myDF2 <- dbReadTable(conn, "myDF")
-stopifnot(identical(myDF, myDF2))
-dbRemoveTable(conn, "myDF")
-dbDisconnect(conn)
-
-## 2 Exercise fetch.default.rec and dbGetRowCount... along with
-## dbSendQuery() and fetch()
-drv <- MySQL(fetch.default.rec=2)
-conn <- try(if (is.na(user) && is.na(password)) {
- # in this leg user and password should be set in my.ini or my.cnf files
- dbConnect(drv, dbname = dbname)
-} else {
- # in this leg they were specified via environment variables
- dbConnect(drv, user = user, password = password, dbname = dbname)
-})
-if (inherits(conn, "try-error")) {
- cat("unable to connect to MySQL\n")
- q()
+
+## 1 Ensure that dbWriteTable doesn't add trailing \r
+dbRemoveTable(conn, "myDF") # precaution
+## RMySQL is not very clever: it does not convert to factor,
+## and converts row names to character.
+myDF <- data.frame(x = paste("x", 1:5, sep = ""),
+ y = paste("y", 1:5, sep = ""),
+ row.names = letters[1:5],
+ stringsAsFactors = FALSE)
+dbWriteTable(conn, name= "myDF", value = myDF)
+myDF2 <- dbReadTable(conn, "myDF")
+stopifnot(identical(myDF, myDF2))
+dbRemoveTable(conn, "myDF")
+
+## 2 Exercise fetch.default.rec and dbGetRowCount... along with
+## dbSendQuery() and fetch()
+
+dbRemoveTable(conn, "iris") # precaution
+dbWriteTable(conn,name='iris',value=iris,row.names=FALSE)
+rso <- dbSendQuery(conn,"select * from iris where Species='versicolor'")
+x <- fetch(rso,n=2)
+rowCount <- nrow(x)
+stopifnot(rowCount==2)
+stopifnot(rowCount==dbGetRowCount(rso))
+while(nrow(x)) {
+ x <- fetch(rso)
+ rowCount <- rowCount + nrow(x)
+ stopifnot(rowCount==dbGetRowCount(rso))
}
-
-dbRemoveTable(conn, "iris") # precaution
-dbWriteTable(conn,name='iris',value=iris,row.names=FALSE)
-rso <- dbSendQuery(conn,"select * from iris where Species='versicolor'")
-x <- fetch(rso,n=2)
-rowCount <- nrow(x)
-stopifnot(rowCount==2)
-stopifnot(rowCount==dbGetRowCount(rso))
-while(nrow(x)) {
- x <- fetch(rso)
- rowCount <- rowCount + nrow(x)
- stopifnot(rowCount==dbGetRowCount(rso))
-}
-
-## 2 Exercise dbRowsAffected()
-nrows <- nrow(iris[iris$Species=='versicolor',])
-rso <- dbSendQuery(conn,"delete from iris where Species='versicolor'")
-stopifnot(nrows==dbGetRowsAffected(rso))
-
-## 3 Exercise dbGetQuery()
-stopifnot(
- identical(
- iris[iris$Species!='versicolor','Sepal.Length'],
- dbGetQuery(conn,'select * from iris')$Sepal_Length
- )
-)
-
-dbDisconnect(conn)
-dbUnloadDriver(drv)
+
+## 2 Exercise dbRowsAffected()
+nrows <- nrow(iris[iris$Species=='versicolor',])
+rso <- dbSendQuery(conn,"delete from iris where Species='versicolor'")
+stopifnot(nrows==dbGetRowsAffected(rso))
+
+## 3 Exercise dbGetQuery()
+stopifnot(
+ identical(
+ iris[iris$Species!='versicolor','Sepal.Length'],
+ dbGetQuery(conn,'select * from iris')$Sepal_Length
+ )
+)
+
+dbDisconnect(conn)
+dbUnloadDriver(drv)
View
54 tests/tests.Rout.save
@@ -26,19 +26,19 @@ Loading required package: DBI
> dbname <- Sys.getenv("MYSQL_DATABASE", unset = "test")
>
> drv <- dbDriver("MySQL")
+>
> conn <- try(if (is.na(user)) {
+ # in this leg user and password should be set in my.ini or my.cnf files
+ dbConnect(drv, dbname = dbname)
+ } else {
+ dbConnect(drv, user = user, password = password, dbname = dbname)
+ })
+>
> if (inherits(conn, "try-error")) {
+ cat("unable to connect to MySQL\n")
+ q()
+ }
>
-> # dbListTables(conn)
->
> ## 1 Ensure that dbWriteTable doesn't add trailing \r
> dbRemoveTable(conn, "myDF") # precaution
[1] FALSE
@@ -54,24 +54,40 @@ Loading required package: DBI
> stopifnot(identical(myDF, myDF2))
> dbRemoveTable(conn, "myDF")
[1] TRUE
-> dbDisconnect(conn)
-[1] TRUE
>
> ## 2 Exercise fetch.default.rec and dbGetRowCount... along with
> ## dbSendQuery() and fetch()
-> drv <- MySQL(fetch.default.rec=2)
-> conn <- try(if (is.na(user) && is.na(password)) {
-+ # in this leg user and password should be set in my.ini or my.cnf files
-+ dbConnect(drv, dbname = dbname)
-+ } else {
-+ # in this leg they were specified via environment variables
-+ dbConnect(drv, user = user, password = password, dbname = dbname)
-+ })
-Error in mysqlNewConnection(drv, ...) :
- RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'NA'@'localhost' (using password: NO)
-)
-> if (inherits(conn, "try-error")) {
-+ cat("unable to connect to MySQL\n")
-+ q()
+>
+> dbRemoveTable(conn, "iris") # precaution
+[1] TRUE
+> dbWriteTable(conn,name='iris',value=iris,row.names=FALSE)
+[1] TRUE
+> rso <- dbSendQuery(conn,"select * from iris where Species='versicolor'")
+> x <- fetch(rso,n=2)
+> rowCount <- nrow(x)
+> stopifnot(rowCount==2)
+> stopifnot(rowCount==dbGetRowCount(rso))
+> while(nrow(x)) {
++ x <- fetch(rso)
++ rowCount <- rowCount + nrow(x)
++ stopifnot(rowCount==dbGetRowCount(rso))
+ }
-unable to connect to MySQL
+>
+> ## 2 Exercise dbRowsAffected()
+> nrows <- nrow(iris[iris$Species=='versicolor',])
+> rso <- dbSendQuery(conn,"delete from iris where Species='versicolor'")
+> stopifnot(nrows==dbGetRowsAffected(rso))
+>
+> ## 3 Exercise dbGetQuery()
+> stopifnot(
++ identical(
++ iris[iris$Species!='versicolor','Sepal.Length'],
++ dbGetQuery(conn,'select * from iris')$Sepal_Length
++ )
++ )
+>
+> dbDisconnect(conn)
+[1] TRUE
+> dbUnloadDriver(drv)
+[1] TRUE
+>

0 comments on commit b347ade

Please sign in to comment.
Something went wrong with that request. Please try again.