-
Notifications
You must be signed in to change notification settings - Fork 33
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
Improve validation #153
Merged
Merged
Improve validation #153
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
777745c
Improve validation
hadley f3dd7fe
Standardise validation query formats
hadley 62fba23
Use alternative strategy to force validation
hadley 2236166
Test that validateQuery is cached
hadley eef06dd
Use helper for accessing pool metadata
hadley 4bfc67f
Use withr::defer() to correct order of closing
hadley 41d6435
Restrict query size
hadley 9d76b49
Add news bullets
hadley f752703
Move helper to correct place
hadley 94cc8e8
Add comments to query options
hadley b1336bc
Merge commit 'f8c85ec244a3cf02ad08579b561f9ae37d81f12f'
hadley 348cbeb
Improve scope of tryCatch()
hadley c75bcc4
Correct test name
hadley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ Imports: | |
DBI, | ||
later (>= 1.0.0), | ||
R6, | ||
rlang | ||
rlang (>= 1.0.0) | ||
Suggests: | ||
covr, | ||
dbplyr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ setMethod("onDestroy", "DBIConnection", function(object) { | |
#' @export | ||
#' @rdname object | ||
setMethod("onValidate", "DBIConnection", function(object) { | ||
pool <- attr(object, "pool_metadata", exact = TRUE)$pool | ||
pool <- pool_metadata(object)$pool | ||
query <- pool$state$validateQuery | ||
|
||
if (!is.null(query)) { | ||
|
@@ -39,13 +39,13 @@ setMethod("onValidate", "DBIConnection", function(object) { | |
options <- c( | ||
"SELECT 1", | ||
"SELECT 1 FROM DUAL", | ||
"SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS", | ||
"SELECT * FROM INFORMATION_SCHEMA.TABLES", | ||
"SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS WHERE 0=1", | ||
"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE 0=1", | ||
"VALUES 1", | ||
"SELECT 1 FROM SYSIBM.SYSDUMMY1", | ||
"select count(*) from systables", | ||
"select count(*) from SYS_TABLES", | ||
"select count(*) from SYS.TABLES" | ||
"SELECT 1 FROM SYSIBM.SYSDUMMY1 WHERE 0=1", | ||
hadley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"SELECT 1 FROM systables WHERE 0=1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced |
||
"SELECT 1 FROM SYS_TABLES WHERE 0=1", | ||
"SELECT 1 FROM SYS.TABLES WHERE 0=1" | ||
) | ||
|
||
## Iterates through the possible validation queries: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# poolReturn() errors if object is not valid | ||
|
||
Code | ||
poolReturn("x") | ||
Condition | ||
Error in `poolReturn()`: | ||
! `object` is not an pooled object. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test_that("onValidate() caches query", { | ||
pool <- local_pool() | ||
# reset cache from initial creation + validation | ||
pool$state$validateQuery <- NULL | ||
|
||
con <- poolCheckout(pool) | ||
withr::defer(poolReturn(con)) | ||
onValidate(con) | ||
expect_equal(pool$state$validateQuery, "SELECT 1") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the change that fixed the underlying problem: now we have a helper that ensures we're always accessing the correct attribute.