SQLQueryFactory: SQLQueryFactory

Description Usage Arguments Details Examples

Description

Represents an SQL query factory, responsible for building SQL queries. By simply calling the available methods and supplying them with your needs, you get an SQLQuery object containing a query that can bring the information from the database.

Usage

1
2
3
4
5
sqlFactory <- SQLQueryFactory$new()

sqlFactory$createSelect(tableMap, joinMap, distinct, where, groupBy, having)
sqlFactory$createView(viewName, tableMap, distinct, where, groupBy, having)
sqlFactory$deleteView(viewName)

Arguments

tableName

Name of the table inside a database.

viewName

Name of the view inside a database.

tableMap

Dataframe specifing which tables and columns should be used to extract information.

joinMap

Dataframe specifing which tables to join and repective atributes.

distinct

Logical that dictates if the data retrieved should be distinct or not.

where

Filters the results by the specified conditions.

groupBy

Groups the results by the values of one or more columns.

having

Further filters the results, by allowing the use of agreggation functions (e.g. COUNT, SUM, ...)

Details

$new() Creates an instance of DBAbstractR.

$connectToDatabase(dataSourceName = "", userID = "", password = "") Performs the connection to a database, returning its information.

$listTables Returns a dataframe with all the tables (name and description) in the database.

$listTableInformation(tableName = "") Returns a dataframe with the information (names of the columns, their type and nullability) about a given table.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
# Building the SQLQueryFactory object.
sqlQueryFactory <- SQLQueryFactory$new()

# Selecting both the username and last_login from the user table.
tableMap <- data.frame(tableName = "user", columns = "username", "last_login")

sqlQueryFactory$createSelect(tableMap)

# Creating a view based on the user table where all registered users date from under 2009.
tableMap <- data.frame(tablename = "user", columns = "*")
where <- "register_date < 2010-01-01"

# Droping an existing view
sqlQueryFactory$deleteView("old_users")

## End(Not run)

PedroMiguelFMoreira/DBAbstractR documentation built on May 8, 2019, 1:28 a.m.