@@ -177,6 +177,36 @@ connection_flatten_object_types <- function(object_tree) {
177177 return (TRUE )
178178}
179179
180+ # Helper to reconstruct ODBC connection code from connection info
181+ .ps.odbc_connection_code <- function (info ) {
182+ # Try to reconstruct a reasonable connection string
183+ # Priority: DSN > connection string parameters
184+ if (! is.null(info $ sourcename ) && nzchar(info $ sourcename )) {
185+ # DSN-based connection
186+ sprintf(' odbc::dbConnect(odbc::odbc(), dsn = "%s")' , info $ sourcename )
187+ } else {
188+ # Build connection string from available parameters
189+ params <- character ()
190+
191+ if (! is.null(info $ servername ) && nzchar(info $ servername )) {
192+ params <- c(params , sprintf(' server = "%s"' , info $ servername ))
193+ }
194+ if (! is.null(info $ dbname ) && nzchar(info $ dbname )) {
195+ params <- c(params , sprintf(' database = "%s"' , info $ dbname ))
196+ }
197+
198+ if (length(params ) > 0 ) {
199+ sprintf(
200+ " odbc::dbConnect(odbc::odbc(), %s)" ,
201+ paste(params , collapse = " , " )
202+ )
203+ } else {
204+ # Fallback if we can't determine connection parameters
205+ " # Connection opened from Variables Pane"
206+ }
207+ }
208+ }
209+
180210# ' @export
181211.ps.connection_icon <- function (id , ... ) {
182212 con <- get(id , getOption(" connectionObserver" )$ .connections )
@@ -329,33 +359,3 @@ setHook(
329359 )
330360 }
331361)
332-
333- # Helper to reconstruct ODBC connection code from connection info
334- .ps.odbc_connection_code <- function (info ) {
335- # Try to reconstruct a reasonable connection string
336- # Priority: DSN > connection string parameters
337- if (! is.null(info $ sourcename ) && nzchar(info $ sourcename )) {
338- # DSN-based connection
339- sprintf(' odbc::dbConnect(odbc::odbc(), dsn = "%s")' , info $ sourcename )
340- } else {
341- # Build connection string from available parameters
342- params <- character ()
343-
344- if (! is.null(info $ servername ) && nzchar(info $ servername )) {
345- params <- c(params , sprintf(' server = "%s"' , info $ servername ))
346- }
347- if (! is.null(info $ dbname ) && nzchar(info $ dbname )) {
348- params <- c(params , sprintf(' database = "%s"' , info $ dbname ))
349- }
350-
351- if (length(params ) > 0 ) {
352- sprintf(
353- " odbc::dbConnect(odbc::odbc(), %s)" ,
354- paste(params , collapse = " , " )
355- )
356- } else {
357- # Fallback if we can't determine connection parameters
358- " # Connection opened from Variables Pane"
359- }
360- }
361- }
0 commit comments