querySql: Retrieve data to a data.frame

Description Usage Arguments Details Value Examples

View source: R/Sql.R

Description

This function sends SQL to the server, and returns the results.

Usage

1
2
querySql(connection, sql, errorReportFile = file.path(getwd(),
  "errorReport.txt"))

Arguments

connection

The connection to the database server.

sql

The SQL to be send.

errorReportFile

The file where an error report will be written if an error occurs. Defaults to 'errorReport.txt' in the current working directory.

Details

This function sends the SQL to the server and retrieves the results. If an error occurs during SQL execution, this error is written to a file to facilitate debugging. Null values in the database are converted to NA values in R.

Value

A data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
connectionDetails <- createConnectionDetails(dbms = "mysql",
                                             server = "localhost",
                                             user = "root",
                                             password = "blah",
                                             schema = "cdm_v4")
conn <- connect(connectionDetails)
count <- querySql(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)

## End(Not run)

OHDSI/DatabaseConnector documentation built on Nov. 16, 2018, 6:20 p.m.