diff --git a/R/TrexDialect.R b/R/TrexDialect.R index 78815b25..95e54520 100644 --- a/R/TrexDialect.R +++ b/R/TrexDialect.R @@ -1,32 +1,47 @@ #' Switch SQL dialect for Trex connection #' -#' This function conditionally switches the SQL dialect to DuckDB for -#' when the 'trex_connection' environment variable is set to "true". +#' This function conditionally switches the SQL dialect based on the +#' value of the 'trex_connection' environment variable. Supported values: +#' "trex", "trex_hana" (or unset). +#' +#' - If 'trex_connection' is not set, returns the original dialect. +#' - If 'trex_connection' == "trex" and dialect != "hana", returns "duckdb". +#' - If 'trex_connection' == "trex_hana", returns "hana". +#' - For any other value, returns the original dialect. #' #' @param dialect A character string specifying the original SQL dialect #' (e.g., "postgresql", "mysql", "sqlite", etc.) #' #' @return A character string representing the SQL dialect to use: #' \itemize{ -#' \item Returns "duckdb" if trex_connection environment variable is "true" and dialect is not "hana" -#' \item Returns the original dialect otherwise +#' \item If 'trex_connection' is not set, returns the original dialect +#' \item If 'trex_connection' == "trex" and dialect != "hana", returns "duckdb" +#' \item If 'trex_connection' == "trex_hana", returns "hana" +#' \item For any other value, returns the original dialect #' } #' #' @details #' The function checks the 'trex_connection' environment variable: #' \itemize{ #' \item If the environment variable is not set (NA), returns the original dialect -#' \item If set to "true" and the dialect is not "hana", returns "duckdb" +#' \item If set to "trex" and the dialect is not "hana", returns "duckdb" +#' \item If set to "trex_hana", returns "hana" #' \item Otherwise, returns the original dialect unchanged #' } #' #' @examples #' # Set environment variable for testing -#' Sys.setenv(trex_connection = "true") +#' Sys.setenv(trex_connection = "trex") #' trexDialect("postgresql") # Returns "duckdb" #' trexDialect("hana") # Returns "hana" (unchanged) #' -#' # Unset environment variable +#' Sys.setenv(trex_connection = "trex_hana") +#' trexDialect("postgresql") # Returns "hana" +#' trexDialect("hana") # Returns "hana" +#' +#' Sys.setenv(trex_connection = "other_value") +#' trexDialect("postgresql") # Returns "postgresql" +#' #' Sys.unsetenv("trex_connection") #' trexDialect("postgresql") # Returns "postgresql" #' @@ -38,9 +53,11 @@ trexDialect <- function(dialect) { if (is.na(trex_env)) { return(dialect) } - if (trex_env == "true" && dialect != "hana") { - return("duckdb") - } else { - return(dialect) - } + if (trex_env == "trex" && dialect != "hana") { + return("duckdb") + } else if (trex_env == "trex_hana") { + return("hana") + } else { + return(dialect) + } } \ No newline at end of file diff --git a/inst/csv/replacementPatterns.csv b/inst/csv/replacementPatterns.csv index 0824787c..9cec9708 100644 --- a/inst/csv/replacementPatterns.csv +++ b/inst/csv/replacementPatterns.csv @@ -1480,10 +1480,10 @@ hana,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","D hana,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table')) THEN DROP TABLE @table; END IF; END;" hana,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table')) THEN DROP TABLE @table; END IF; END;" hana,"DROP TABLE IF EXISTS @table_name;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table_name')) THEN DROP TABLE @table_name; END IF; END;" -hana,CREATE TABLE #@table (@definition);,CREATE LOCAL TEMPORARY TABLE #@table (@definition); -hana,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE LOCAL TEMPORARY TABLE #@d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e); +hana,CREATE TABLE #@table (@definition);,CREATE TABLE #@table (@definition); +hana,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE TABLE #@d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e); hana,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e); -hana,SELECT @a INTO #@b FROM @c;,CREATE LOCAL TEMPORARY TABLE #@b AS(\nSELECT\n@a\nFROM\n@c); +hana,SELECT @a INTO #@b FROM @c;,CREATE TABLE #@b AS(\nSELECT\n@a\nFROM\n@c); hana,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS(\nSELECT\n@a\nFROM\n@c); hana,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a; hana,#, diff --git a/inst/java/SqlRender-1.19.2-SNAPSHOT.jar b/inst/java/SqlRender-1.19.2-SNAPSHOT.jar new file mode 100644 index 00000000..bdd70996 Binary files /dev/null and b/inst/java/SqlRender-1.19.2-SNAPSHOT.jar differ diff --git a/inst/java/SqlRender.jar b/inst/java/SqlRender.jar index e2ba4fd1..bdd70996 100644 Binary files a/inst/java/SqlRender.jar and b/inst/java/SqlRender.jar differ