Learn R Programming

⚠️There's a newer version (6.3.3) of this package.Take me there.

DatabaseConnector

DatabaseConnector is part of HADES.

Introduction

This R package provides function for connecting to various DBMSs. Together with the SqlRender package, the main goal of DatabaseConnector is to provide a uniform interface across database platforms: the same code should run and produce equivalent results, regardless of the database back end.

Features

  • Create connections to the various database platforms:
    • MicrosoftSQL Server
    • Oracle
    • PostgresSql
    • Microsoft Parallel Data Warehouse (a.k.a. Analytics Platform System)
    • Amazon Redshift
    • Apache Impala
    • Google BigQuery
    • IBM Netezza
    • SQLite
    • Spark
  • Statements for executing queries with
    • Error reporting to file
    • Progress reporting
    • Multiple statements per query
  • Support for fetching data to Andromeda objects
  • Insert data frame to a database table
  • Supports the DBI interface, with SQL statements automatically translated to the appropriate dialect.
  • Supports the dbplyr interface.
  • Integrates with RStudio's Connections tab

Examples

connectionDetails <- createConnectionDetails(dbms="postgresql", 
                                             server="localhost",
                                             user="root",
                                             password="blah")
conn <- connect(connectionDetails)
querySql(conn,"SELECT COUNT(*) FROM person")
disconnect(conn)

Technology

DatabaseConnector is an R package using Java's JDBC drivers and other DBI drivers.

System Requirements

Running the package requires R with the package rJava installed. Also requires Java 1.8 or higher.

Installation

  1. See the instructions here for configuring your R environment, including Java.

  2. To install the latest stable version, install from CRAN:

install.packages("DatabaseConnector")
  1. Download the database drivers as described here.

  2. (Optionally) To use Windows Authentication for SQL Server, download the authentication DDL file as described here.

User Documentation

Documentation can be found on the package website.

PDF versions of the documentation are also available:

Support

  • Developer questions/comments/feedback: OHDSI Forum
  • We use the GitHub issue tracker for all bugs/issues/enhancements

Contributing

Read here how you can contribute to this package.

License

DatabaseConnector is licensed under Apache License 2.0. The JDBC drivers fall under their own respective licenses.

Development

DatabaseConnector is being developed in R Studio.

Development status

Stable. The code is actively being used in several projects.

Acknowledgements

  • This project is supported in part through the National Science Foundation grant IIS 1251151.

Copy Link

Version

Install

install.packages('DatabaseConnector')

Monthly Downloads

3,296

Version

6.1.0

License

Apache License

Issues

Pull Requests

Stars

Forks

Maintainer

Martijn Schuemie

Last Published

March 15th, 2023

Functions in DatabaseConnector (6.1.0)

day

Extract the day from a date
computeDataHash

Compute hash of data
dateAdd

Add an interval to a date
dateDiff

Compute difference between dates
createDbiConnectionDetails

Create DBI connection details
dbConnect,DatabaseConnectorDriver-method

Create a connection to a DBMS
createConnectionDetails

createConnectionDetails
connect

connect
createZipFile

Compress files and/or folders into a single zip file
dateFromParts

Construct a date from parts
downloadJdbcDrivers

Download DatabaseConnector JDBC Jar files
dropEmulatedTempTables

Drop all emulated temp tables.
executeSql

Execute SQL code
extractQueryTimes

Extract query times from a ParallelLogger log file
existsTable

Does the table exist?
eoMonth

Return the end of the month
disconnect

Disconnect from the server
dbUnloadDriver,DatabaseConnectorDriver-method

Load and unload database drivers
dbms

Get the database platform from a connection
dbGetInfo,DatabaseConnectorDriver-method

Get DBMS metadata
inDatabaseSchema

Refer to a table in a database schema
lowLevelExecuteSql

Execute SQL code
lowLevelQuerySqlToAndromeda

Low level function for retrieving data to a local Andromeda object
month

Extract the month from a date
insertTable

Insert a table on the server
lowLevelQuerySql

Low level function for retrieving data to a data frame
renderTranslateExecuteSql

Render, translate, execute SQL code
getTableNames

List all tables in a database schema.
renderTranslateQueryApplyBatched

Render, translate, and perform process to batches of data.
getAvailableJavaHeapSpace

Get available Java heap space
querySqlToAndromeda

Retrieves data to a local Andromeda object
querySql

Retrieve data to a data.frame
jdbcDrivers

How to download and use JDBC drivers for the various data platforms.
isSqlReservedWord

Test a character vector of SQL names for SQL reserved words
renderTranslateQuerySql

Render, translate, and query to data.frame
renderTranslateQuerySqlToAndromeda

Render, translate, and query to local Andromeda
year

Extract the year from a date
show,DatabaseConnectorDriver-method

Show an Object
requiresTempEmulation

Does the DBMS require temp table emulation?
DatabaseConnectorConnection-class

DatabaseConnectorConnection class.
assertTempEmulationSchemaSet

Assert the temp emulation schema is set
DatabaseConnectorDriver

Create a DatabaseConnectorDriver object
DatabaseConnectorJdbcConnection-class

DatabaseConnectorJdbcConnection class.
DatabaseConnectorDbiConnection-class

DatabaseConnectorDbiConnection class.
DatabaseConnectorJdbcResult-class

DatabaseConnector JDBC results class.
Microsoft SQL Server-class

Microsoft SQL Server class.
DatabaseConnector-package

DatabaseConnector: Connecting to Various Database Platforms
DatabaseConnectorDriver-class

DatabaseConnectorDriver class.
DatabaseConnectorDbiResult-class

DatabaseConnector DBI results class.