Skip to content

Commit

Permalink
Sett variabel lagd av rapOpenDbConnection til NULL når ferdig (#197)
Browse files Browse the repository at this point in the history
Så det var gjort flere plasser. Mulig det vil hjelpe på corrupt db
feil-melding
  • Loading branch information
arnfinn authored Dec 16, 2024
1 parent e16dae1 commit 9c9100c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/log.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ appendLog <- function(event, name) {
con <- rapOpenDbConnection(config$r$raplog$key)$con
DBI::dbAppendTable(con, name, event, row.names = NULL)
rapCloseDbConnection(con)
con <- NULL
} else {
stop(paste0(
"Target ", target, " is not supported. ",
Expand Down Expand Up @@ -342,6 +343,7 @@ createLogDbTabs <- function() {
RMariaDB::dbExecute(con, queries[i])
}
rapbase::rapCloseDbConnection(con)
con <- NULL
}


Expand Down Expand Up @@ -464,6 +466,7 @@ sanitizeLog <- function() {
)
DBI::dbExecute(con, query)
rapCloseDbConnection(con)
con <- NULL
}

NULL
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-auto-report-db.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ createAutoReportTab <- function() {
RMariaDB::dbExecute(con, queries[i])
}
rapbase::rapCloseDbConnection(con)
con <- NULL
}

test_that("a db for auto report defs can be created", {
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-dbConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ test_that("A mysql db connection and driver can be provided and cleaned", {
expect_true(RMariaDB::dbIsValid(l$con))
rapCloseDbConnection(l$con)
expect_false(RMariaDB::dbIsValid(l$con))
l <- NULL
})

test_that("Deprecated defunct interface provides an error", {
Expand Down Expand Up @@ -153,6 +154,7 @@ test_that("Bigints are returned as integers (not bit64::integer64)", {
query <- "SELECT * FROM testTable;"
df <- DBI::dbGetQuery(l$con, query)
rapCloseDbConnection(l$con)
l <- NULL
expect_is(df[["someBigInt"]], "integer")
})

Expand All @@ -170,6 +172,7 @@ if (is.null(checkDb(is_test_that = FALSE))) {
con <- rapbase::rapOpenDbConnection(regName)$con
RMariaDB::dbExecute(con, "DROP DATABASE rapbase;")
rapbase::rapCloseDbConnection(con)
con <- NULL
}

# restore initial state
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-moduleExport.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ if (is.null(checkDb(is_test_that = FALSE))) {
con <- rapbase::rapOpenDbConnection(regName)$con
RMariaDB::dbExecute(con, "DROP DATABASE rapbase;")
rapbase::rapCloseDbConnection(con)
con <- NULL
}


Expand Down

0 comments on commit 9c9100c

Please sign in to comment.