Skip to content

Commit

Permalink
sql server: fix writing to tmp tables with FreeTDS (#886)
Browse files Browse the repository at this point in the history
* sql server: fix writing to tmp tables with FreeTDS

* add NEWS entry

* sql-server: add method to plug s4 dispatch
  • Loading branch information
detule authored Jan 27, 2025
1 parent 6b5635c commit 1e81ed2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# odbc (development version)

* SQL Server: Fix data truncation when writing to temp tables with
`FreeTDS` (#866).

* SQL Server: Writing to DATETIME2 targets respects precision (#793).

* Addressed issue where error messages rethrown from some drivers would be
Expand Down
47 changes: 47 additions & 0 deletions R/driver-sql-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,50 @@ setMethod("odbcDataType", "Microsoft SQL Server",
)
}
)

#' @description
#' ## `odbcConnectionColumns_()`
#'
#' If temp table, query the database for the
#' actual table name.
#' @rdname SQLServer
#' @usage NULL
setMethod("odbcConnectionColumns_", c("Microsoft SQL Server", "character"),
function(conn,
name,
...,
catalog_name = NULL,
schema_name = NULL,
column_name = NULL,
exact = FALSE) {
if (isTempTable(conn, name, catalog_name, schema_name, column_name, exact)) {
catalog_name <- "tempdb"
schema_name <- "dbo"
query <- paste0("SELECT name FROM tempdb.sys.tables WHERE ",
"object_id = OBJECT_ID('tempdb..", name, "')")
name <- dbGetQuery(conn, query)[[1]]
}

callNextMethod(
conn = conn,
name = name,
...,
catalog_name = catalog_name,
schema_name = schema_name,
column_name = column_name,
exact = exact
)
}
)

#' @description
#' ## `odbcConnectionColumns_()`
#'
#' Copied over from odbc-connection to avoid S4 dispatch NOTEs.
#' @rdname SQLServer
#' @usage NULL
setMethod("odbcConnectionColumns_", c("Microsoft SQL Server", "SQL"),
function(conn, name, ...) {
odbcConnectionColumns_(conn, dbUnquoteIdentifier(conn, name)[[1]], ...)
}
)

0 comments on commit 1e81ed2

Please sign in to comment.