From 7d2a95ce12e22d214c463c94aee6d750e64da64b Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 16 Jan 2026 16:56:52 -0600 Subject: [PATCH 1/2] 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] From 784e4b2540f45c81d890906e131e01f43d2fc482 Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 9 Feb 2026 10:58:49 -0600 Subject: [PATCH 2/2] docs: Add NEWS entry for SQL Server compatibility fix Co-Authored-By: Claude Opus 4.6 --- pkg-r/NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg-r/NEWS.md b/pkg-r/NEWS.md index 6d33918e..acdf4b99 100644 --- a/pkg-r/NEWS.md +++ b/pkg-r/NEWS.md @@ -1,5 +1,7 @@ # querychat (development version) +* `DBISource` now uses database-agnostic SQL for column and type detection, replacing `LIMIT` syntax with `WHERE 1=0` and `dbFetch(n=1)`. This fixes compatibility with SQL Server and other databases that don't support `LIMIT`. (#112, #197) + # querychat 0.2.0 * The update tool now requires that the SQL query returns all columns from the original data source, ensuring that the dashboard can display the complete data frame after filtering or sorting. If the query does not return all columns, an informative error message will be provided. (#180)