Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Better checks in get_connection #83

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# SCDB (development version)

## Minor Improvements and Fixes

* Improved checks on `get_connection()`:
- If given, `host` does not need to look like an IP address (e.g. "localhost" is not unrealistic).
- A `character` input for `port` is allowed if it is a string of digits.
- Now checks if `timezone` and `timezone_out` is an IANA time zone.

* `get_connection()` now checks the value of any `timezone` and `timezone_out` arguments.

# SCDB 0.3

* Added support for Microsoft SQL Server using ODBC (#77).
Expand Down
16 changes: 10 additions & 6 deletions R/connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#' @param host
#' Character string giving the ip of the host to connect to
#' @param port
#' Host port to connect to (numeric)
#' Host port to connect to. Must be a number or a numeric string.
#' @param dbname
#' Name of the database located at the host
#' @param user
#' Username to login with
#' @param password
#' Password to login with
#' @param timezone
#' Sets the timezone of DBI::dbConnect()
#' Sets the timezone of DBI::dbConnect(). Must be in [OlsonNames()].
#' @param timezone_out
#' Sets the timezone_out of DBI::dbConnect()
#' Sets the timezone_out of DBI::dbConnect(). Must be in [OlsonNames()].
#' @param ...
#' Additional parameters sent to DBI::dbConnect()
#' @inheritParams RPostgres::dbConnect_PqDriver
Expand Down Expand Up @@ -47,13 +47,17 @@
check_interrupts = TRUE) {

# Check arguments
checkmate::assert_character(host, pattern = r"{^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$}", null.ok = TRUE)
checkmate::assert_character(host, null.ok = TRUE)
if (is.character(port)) {
checkmate::assert_character(port, pattern = "^[:digit:]*$")

Check warning on line 52 in R/connection.R

View check run for this annotation

Codecov / codecov/patch

R/connection.R#L52

Added line #L52 was not covered by tests
port <- as.numeric(port) # nocov
}
checkmate::assert_numeric(port, null.ok = TRUE)
checkmate::assert_character(dbname, null.ok = TRUE)
checkmate::assert_character(user, null.ok = TRUE)
checkmate::assert_character(password, null.ok = TRUE)
checkmate::assert_character(timezone, null.ok = TRUE)
checkmate::assert_character(timezone_out, null.ok = TRUE)
checkmate::assert_choice(timezone, OlsonNames(), null.ok = TRUE)
checkmate::assert_choice(timezone_out, OlsonNames(), null.ok = TRUE)

# Set PostgreSQL-specific options
if (inherits(drv, "PqDriver")) {
Expand Down
6 changes: 3 additions & 3 deletions man/get_connection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.