Learn R Programming

rpg (version 1.6)

ping: Database connection utilities

Description

Conection reporting and defaults

Usage

ping(opts = "")

get_conn_error()

get_conn_defaults(all = FALSE)

get_conn_info(what = NULL, hide_password = TRUE)

set_conn_defaults(...)

set_default_password(password = NULL)

reset_conn_defaults()

Arguments

opts

a libpq connection string

all

if false return only defaults with settings

what

the fields to return or all if NULL

hide_password

if true, do not reveal password used

...

a named list of arguments giving new defaults

password

the password

Value

ping returns one of the following:

PQPING_OK Server reachable
PQPING_REJECT Server reachable but not accepting connections
PQPING_NO_RESPONSE Server unreachable
PQPING_NO_ATTEMPT Connection string is nonsense

get_conn_error: an error string

get_conn_defaults: a data frame with defaults listed

get_conn_info: a list of values

Details

ping will ignore any keywords not directly related to the database host (e.g., username, dbname) as it does not connect; it only detect the server port is responding.

get_conn_defaults returns a data frame containing all of the possible connection string keywords, the names of environment variables used to override the defaults, the compiled in default value and the current value of the keyword.

get_conn_info returns a list containing information about the current connection. For readability, it will print as though it is a matrix. If you want to see it as a list, try unclass(get_conn_info()).

If length(what) == 1 then get_conn_info returns a scalar

set_conn_defaults sets the connection defaults by calling Sys.setenv and setting the environment variable associated with the connection keywords returned by get_conn_defaults(all = TRUE). These settings will only last as long as the current shell session and will reset after a new login.

set_default_password will query for a password (if not supplied) and set the PGPASSWORD environment variable accordingly. This can be used with psql and copy_to.

reset_conn_defaults unsets all environment variables returned by get_conn_defaults(all = TRUE).

Examples

Run this code
# NOT RUN {
ping("connect_timeout = 3, host = www.keittlab.org")
connect()
get_conn_defaults()
set_conn_defaults(dbname = "test")
get_conn_defaults()
reset_conn_defaults()
get_conn_defaults()
get_conn_defaults(all = TRUE)
get_conn_info()
get_conn_error()
disconnect()
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab