xlConnDB: Database connection commands

Description Usage Arguments Value Examples

Description

These functions standardlise various database connection methods and use a fairly uniform way to create connection objects which can then be used in subsequent SQL queries.

Usage

1
2
3
xlConnPostgres(u, pw, db, server, port, ...)

xlConnSQLServ(u = NULL, pw = NULL, db, server, instance, trusted = T, ...)

Arguments

u

Username of the database credentials.

pw

Password of the database credentials.

db

The name of the database.

server

The server name or host name (in the case of AWS RedShift).

port

The port for the database.

...

Any additional arguments passed to respective function.

instance

The instance of the connection, suitable for a SQL Server.

trusted

Logical input, instructing the connection to use the operating system's credientials if TRUE, in which case no value is needed for either u or pw.

Value

xlConnPostgres returns a postgres source object src from src_postgres, to be used in table references like this one: tbl(src, sql('<sql_query>')). xlConnSQLServ passes arguments to odbcDriverConnect, which returns the RODBC object conn to be used in a function such as sqlQuery(cnn, '<sql_query>').

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
src <- xlConnPostgres(u, pw, db, server, port)
sample_table <- tbl(src, sql('select top 100 * from table1'))

## End(Not run)


## Not run: 
conn <- xlConnSQLServ(db, server, instance)
sqlQuery(conn, 'select * from information_schema.tables')

## End(Not run)

xinye1/xltools documentation built on Dec. 2, 2020, 7:23 p.m.