From 7d2a95ce12e22d214c463c94aee6d750e64da64b Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 16 Jan 2026 16:56:52 -0600 Subject: [PATCH] fix(pkg-r): Use database-agnostic SQL for SQL Server compatibility Replace LIMIT syntax with database-agnostic alternatives in DBISource: - Use `WHERE 1=0` instead of `LIMIT 0` to get column names - Use `dbSendQuery()` + `dbFetch(n=1)` instead of `LIMIT 1` for sampling Fixes #112 Co-Authored-By: Claude Opus 4.5 --- pkg-r/R/DBISource.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg-r/R/DBISource.R b/pkg-r/R/DBISource.R index f27f6ebe..4867a9bf 100644 --- a/pkg-r/R/DBISource.R +++ b/pkg-r/R/DBISource.R @@ -68,10 +68,11 @@ DBISource <- R6::R6Class( self$table_name <- table_name # Store original column names for validation + # Use WHERE 1=0 instead of LIMIT 0 for SQL Server compatibility private$colnames <- colnames(DBI::dbGetQuery( conn, sprintf( - "SELECT * FROM %s LIMIT 0", + "SELECT * FROM %s WHERE 1=0", DBI::dbQuoteIdentifier(conn, table_name) ) )) @@ -205,12 +206,14 @@ get_schema_impl <- function( text_columns <- character(0) # Get sample of data to determine types + # Use dbFetch(n=1) instead of LIMIT 1 for SQL Server compatibility sample_query <- paste0( "SELECT * FROM ", - DBI::dbQuoteIdentifier(conn, table_name), - " LIMIT 1" + DBI::dbQuoteIdentifier(conn, table_name) ) - sample_data <- DBI::dbGetQuery(conn, prep_query(sample_query)) + rs <- DBI::dbSendQuery(conn, prep_query(sample_query)) + sample_data <- DBI::dbFetch(rs, n = 1) + DBI::dbClearResult(rs) for (col in columns) { col_class <- class(sample_data[[col]])[1]