Internal function to test and get the database connection of the target data system.
db_connection(
system_name = NULL,
db_type,
headless = FALSE,
from_env = TRUE,
settings = NULL,
timeout = 30,
logfile_dir = NULL,
lib_path = NULL
)
(Default = NULL) A character. Name of the database system. Used to find the correct settings from the env. If you don't want to load the settings from the environment, use the `settings` parameter. Otherwise this funcion will search for all settings beginning with `system_name` in the environment. If `system_name = "i2b2"` settings like `I2B2_HOST` or `I2B2_PORT` (notice the uppercase) will be loaded from the environment. You can load such an env file e.g. by using `DIZutils::set_env_vars(path_to_file)`.
A character. Type of the database system. Currently implemented systems are: 'postgres', 'oracle'.
A boolean (default: `FALSE`). Indicating, if the function is run only in the console (`headless = TRUE`) or on a GUI frontend (`headless = FALSE`).
A boolean (default: `TRUE`). Should database connection be read from the environment or from a settings file. All necessary parameters must be uppercase and have the prefix of the db_name. E.g.: `I2B2_HOST` or `I2B2_PORT`. See the `settings` parameter for all necessary variables.
A list. Required if `from_env == FALSE`. A list containing settings for the database connection. Required fields are `host`, `db_name`, `port`, `user` and `password`. Additionally for Oracle DB's: `sid` (instead of `db_name`). If `settings` is set, `from_env` will be set to `FALSE` automatically.
A timeout in sec. for the db-connection establishment. Values below 2 seconds are not recommended. Default is 30 seconds.
(Optional, String, default: "tempdir()") The absolute path to folder where the logfile will be stored.
A character string. The path to the ojdbc*.jar file. If you run one of the R-containers from the UK-Erlangen DIZ, there might be a lib for oracle here: `lib_path = "/opt/libs/ojdbc8.jar"`
If successful, the result will be the established connection. Otherwise the result will be null.
# NOT RUN {
db_con <- DIZutils::db_connection(
db_name = "i2b2",
db_type = "postgres",
headless = TRUE,
logfile_dir = tempdir()
)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab