Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable additional JVM parameters on JDBC() instantiation #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

setClass("JDBCDriver", representation("DBIDriver", identifier.quote="character", jdrv="jobjRef"))

JDBC <- function(driverClass='', classPath='', identifier.quote=NA) {
JDBC <- function(driverClass='', classPath='', identifier.quote=NA, jvmParams=NA) {
## expand all paths in the classPath
classPath <- path.expand(unlist(strsplit(classPath, .Platform$path.sep)))
.jinit(classPath) ## this is benign in that it's equivalent to .jaddClassPath if a JVM is running
#.jinit(classPath) ## this is benign in that it's equivalent to .jaddClassPath if a JVM is running
.jinit(classpath=classPath, parameters=jvmParams)
.jaddClassPath(system.file("java", "RJDBC.jar", package="RJDBC"))
if (nchar(driverClass) && is.jnull(.jfindClass(as.character(driverClass)[1])))
stop("Cannot find JDBC driver class ",driverClass)
Expand Down
0 test.sh → test-mysql.sh
100644 → 100755
File renamed without changes.
70 changes: 70 additions & 0 deletions test-pgsql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh

## Poor man's test suite -- if you want to run it,
## you'll need PostgreSQL on the local machine and
## adjust the paths/names below as needed

DRIVER="/opt/jdbc/postgresql-9.4-1204-jdbc4.jar"
DRVCLASS="org.postgresql.Driver"

##---- cut here ----

if [ ! -e "$DRIVER" ]; then
echo "Cannot find JDBC driver for PostgreSQL, cannot perform tests"
exit 1
fi

echo "library(RJDBC)

## load driver
drv<-JDBC('$DRVCLASS', '$DRIVER', '\"')

## connect
c<-dbConnect(drv, 'jdbc:postgresql://localhost/postgres', 'postgres', 'postgres')

## table operations write/read
data(iris)
dbWriteTable(c, 'iris', iris, overwrite=TRUE)
dbReadTable(c, 'iris')

## simple send query
fetch(r <- dbSendQuery(c, 'SELECT count(*) FROM iris'), 1)

## query info - some people need this
dbGetInfo(r)
dbHasCompleted(r)

## prepared send query
fetch(r <- dbSendQuery(c, 'SELECT Species as Kind, count(Species) as Count FROM iris WHERE \"Sepal.Width\" > ? GROUP BY Species', 3), 1e3, block=1e3)
dbColumnInfo(r)

## simple update
dbSendUpdate(c, 'DROP TABLE IF EXISTS foo')
dbSendUpdate(c, 'CREATE TABLE foo (alpha VARCHAR(32), beta INT)')

## prepared update
dbSendUpdate(c, 'INSERT INTO foo VALUES (?, ?)', 'foo', 123)
dbSendUpdate(c, 'INSERT INTO foo VALUES (?, ?)', 'bar', 456)

## vectorized update
dbSendUpdate(c, 'INSERT INTO foo VALUES (?, ?)', c('x','y','z'), 1:3)
fetch(dbSendQuery(c, 'SELECT * FROM foo'), -1)

## list
dbGetTables(c)
dbListTables(c)

## calls
#dbSendUpdate(c, 'CREATE PROCEDURE bar() BEGIN SELECT * FROM foo; END')
#fetch(dbSendQuery(c, '{call bar()}'), -1)
#dbSendUpdate(c, 'DROP PROCEDURE bar')
## parametrized
#dbSendUpdate(c, 'CREATE PROCEDURE foobar(IN x INT) BEGIN SELECT * FROM foo WHERE beta >= x; END')
#fetch(dbSendQuery(c, '{call foobar(222)}'), -1)
#dbSendUpdate(c, 'DROP PROCEDURE foobar')

dbDisconnect(c)
" > $0.r

cat $0.r | R --vanilla --quiet || echo '*** TEST FAILED ***'