1+ # Test script for DuckDB config functionality
2+ library(DatabaseConnector )
3+ library(duckdb )
4+
5+ # Create a temporary DuckDB file
6+ temp_db_file <- tempfile(fileext = " .duckdb" )
7+
8+ # Test 1: Connection without config (existing behavior)
9+ cat(" Test 1: Connection without config\n " )
10+ connectionDetails1 <- createConnectionDetails(
11+ dbms = " duckdb" ,
12+ server = temp_db_file
13+ )
14+
15+ tryCatch({
16+ connection1 <- connect(connectionDetails1 )
17+ cat(" ✓ Connection without config successful\n " )
18+ disconnect(connection1 )
19+ }, error = function (e ) {
20+ cat(" ✗ Connection without config failed:" , e $ message , " \n " )
21+ })
22+
23+ # Test 2: Connection with config (new functionality)
24+ cat(" \n Test 2: Connection with config\n " )
25+ connectionDetails2 <- createConnectionDetails(
26+ dbms = " duckdb" ,
27+ server = temp_db_file ,
28+ extraSettings = list (
29+ config = list (
30+ memory_limit = " 8GB" ,
31+ preserve_insertion_order = " false"
32+ )
33+ )
34+ )
35+
36+ tryCatch({
37+ connection2 <- connect(connectionDetails2 )
38+ cat(" ✓ Connection with config successful\n " )
39+
40+ # Verify that the config was applied by checking memory_limit setting
41+ result <- querySql(connection2 , " SELECT current_setting('memory_limit') as memory_limit" )
42+ cat(" Memory limit setting:" , result $ MEMORY_LIMIT , " \n " )
43+
44+ disconnect(connection2 )
45+ }, error = function (e ) {
46+ cat(" ✗ Connection with config failed:" , e $ message , " \n " )
47+ })
48+
49+ # Test 3: Connection with invalid config (error handling)
50+ cat(" \n Test 3: Connection with invalid config\n " )
51+ connectionDetails3 <- createConnectionDetails(
52+ dbms = " duckdb" ,
53+ server = temp_db_file ,
54+ extraSettings = list (
55+ config = list (
56+ invalid_setting = " invalid_value"
57+ )
58+ )
59+ )
60+
61+ tryCatch({
62+ connection3 <- connect(connectionDetails3 )
63+ cat(" ✗ Connection with invalid config should have failed\n " )
64+ disconnect(connection3 )
65+ }, error = function (e ) {
66+ cat(" ✓ Connection with invalid config correctly failed:" , e $ message , " \n " )
67+ })
68+
69+ # Cleanup
70+ unlink(temp_db_file )
71+ cat(" \n Test completed\n " )
0 commit comments