% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Sql.R
\name{querySql}
\alias{querySql}
\title{Retrieve data to a data.frame}
\usage{
querySql(
  connection,
  sql,
  errorReportFile = file.path(getwd(), "errorReportSql.txt"),
  snakeCaseToCamelCase = FALSE,
  integerAsNumeric = getOption("databaseConnectorIntegerAsNumeric", default = TRUE),
  integer64AsNumeric = getOption("databaseConnectorInteger64AsNumeric", default = TRUE)
)
}
\arguments{
\item{connection}{The connection to the database server created using either
\code{\link[=connect]{connect()}} or \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.}

\item{sql}{The SQL to be send.}

\item{errorReportFile}{The file where an error report will be written if an error occurs.
Defaults to 'errorReportSql.txt' in the current working directory.}

\item{snakeCaseToCamelCase}{If true, field names are assumed to use snake_case, and are converted to camelCase.}

\item{integerAsNumeric}{Logical: should 32-bit integers be converted to numeric (double) values? If FALSE
32-bit integers will be represented using R's native \code{Integer} class.}

\item{integer64AsNumeric}{Logical: should 64-bit integers be converted to numeric (double) values? If FALSE
64-bit integers will be represented using \code{bit64::integer64}.}
}
\value{
A data frame.
}
\description{
This function sends SQL to the server, and returns the results.
}
\details{
Fields will be automatically converted for improved consistenty in these situations:
\itemize{
\item SQLite: Fields with names ending in \verb{_date} will be converted to DATE fields. Rationale: SQLite
does not support DATE fields.
\item SQLite: Fields with names ending in \verb{_datetime} will be converted to POSIXct fields. Rationale:
SQLite does not support DATETIME fields.
\item BigQuery and Snowflake: Integer fields will be converted to Integer if it fits in an integer, or
will remain Integer64 otherwise. Rationale: these platforms do not distinguish between INT and
BIGINT.
}

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.
}
\examples{
\dontrun{
connectionDetails <- createConnectionDetails(
  dbms = "postgresql",
  server = "localhost",
  user = "root",
  password = "blah",
  schema = "cdm_v4"
)
conn <- connect(connectionDetails)
count <- querySql(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)
}
}
