Skip to content
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
27 changes: 21 additions & 6 deletions R/Connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -860,20 +860,35 @@ connectDuckdb <- function(connectionDetails) {
bigint = "integer64"
)
)
# Check if ICU extension if installed, and if not, try to install it:
# Check if ICU extension is installed, and if not, try to install it.
isInstalled <- querySql(
connection = connection,
connection = connection,
sql = "SELECT installed FROM duckdb_extensions() WHERE extension_name = 'icu';"
)[1, 1]
canLoadIcu <- isInstalled
if (!isInstalled) {
warning("The ICU extension of DuckDB is not installed. Attempting to install it.")
tryCatch(
executeSql(connection, "INSTALL icu"),
canLoadIcu <- tryCatch(
{
executeSql(connection, "INSTALL icu")
TRUE
},
error = function(e) {
warning("Attempting to install the ICU extension of DuckDB failed.\n",
warning("Attempting to install the ICU extension of DuckDB failed.\n",
"You may need to check your internet connection.\n",
"For more detail, try 'executeSql(connection, \"INSTALL icu\")'.\n",
"Be aware that some time and date functionality will not be available.")
"Be aware that some time and date functionality will not be available.")
return(FALSE)
}
)
}
if (canLoadIcu) {
tryCatch(
executeSql(connection, "LOAD icu"),
error = function(e) {
warning("Attempting to load the ICU extension of DuckDB failed.\n",
"For more detail, try 'executeSql(connection, \"LOAD icu\")'.\n",
"Be aware that some time and date functionality will not be available.")
return(NULL)
}
)
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,23 @@ test_that("dbms function maps DBI connections to correct SQL dialect", {
expect_equal(dbms(mockConnection), dialect)
}
})

test_that("DuckDB ICU extension is loaded on connect", {
skip_if_not_installed("duckdb")
duckdbFile <- tempfile(fileext = ".duckdb")
withr::defer(unlink(duckdbFile, force = TRUE))

connection <- connect(createConnectionDetails(
dbms = "duckdb",
server = duckdbFile
))
withr::defer(disconnect(connection))

extension <- querySql(
connection,
"SELECT installed, loaded FROM duckdb_extensions() WHERE extension_name = 'icu';"
)

expect_true(extension[1, 1])
expect_true(extension[1, 2])
})