Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# odbc (development version)

* Fix writing of [R] date/time values that have integer storage. (#952)

* Oracle:
- Fix writing values to `DATE` targets. (#959)

* SQL Server:
- Fix time zone interpretation in `DATETIMEOFFSET` data; now follows
ISO 8061 convention where positive offset denotes time zone east of Greenwich. (#946)
Expand Down
4 changes: 2 additions & 2 deletions R/driver-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ setMethod("odbcConnectionColumns_", c("Oracle", "character"),
# (#349, #350, #391).
res$data_type <- as.numeric(res$data_type)
isDate <- res$field.type == "DATE"
res$data_type[isDate] <- 91
res$column_size[isDate] <- 6
res$data_type[isDate] <- 93
res$column_size[isDate] <- 16
isTimestamp <- grepl("TIMESTAMP", res$field.type)
res$data_type[isTimestamp] <- 93
res$column_size[isTimestamp] <- 16
Expand Down
2 changes: 1 addition & 1 deletion src/nanodbc/nanodbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ void statement::statement_impl::bind(
bind_len_or_null_[param_index][i] = param.size_;
}

bound_buffer<T> buffer(values, batch_size);
bound_buffer<T> buffer(values, batch_size, sizeof(T));
bind_parameter(param, buffer);
}

Expand Down
3 changes: 0 additions & 3 deletions src/odbc_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ void odbc_result::bind_columns(
bind_date<T, double>(obj, data, column, start, size, buffers);
break;
case datetime_int_t:
Rcpp::Rcout << "bindings int datetime";
bind_datetime<T, int>(obj, data, column, start, size, buffers);
break;
case datetime_double_t:
Rcpp::Rcout << "bindings double datetime";
bind_datetime<T, double>(obj, data, column, start, size, buffers);
break;
case double_t:
Expand Down Expand Up @@ -733,7 +731,6 @@ std::vector<r_type> odbc_result::column_types(Rcpp::List const& list) {
if (x.inherits("Date")) {
types.push_back(date_int_t);
} else if (x.inherits("POSIXct")) {
Rcpp::Rcout << "Pushing datetime_int_t";
types.push_back(datetime_int_t);
} else {
types.push_back(integer_t);
Expand Down
27 changes: 25 additions & 2 deletions tests/testthat/test-driver-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,37 @@ test_that("can detect existence of table", {
test_that("Writing date/datetime with batch size > 1", {
# See #349, #350, #391
con <- test_con("ORACLE")
tbl <- "test_batched_write_w_dates"

values <- data.frame(
datetime = as.POSIXct(as.numeric(iris$Petal.Length * 10), origin = "2024-01-01", tz = "UTC"),
date = as.Date(as.numeric(iris$Petal.Length * 10), origin = "2024-01-01", tz = "UTC"),
integer = as.integer(iris$Petal.Width * 100),
double = iris$Sepal.Length,
varchar = iris$Species)
tbl <- local_table(con, "test_batched_write_w_dates", values)
res <- dbReadTable(con, "test_batched_write_w_dates")
tbl <- local_table(con, tbl, values)
res <- dbReadTable(con, tbl)
expect_true(nrow(res) == nrow(values))
# Now write character dates and datetimes to these targets
# Issue #959
valuesMod <- values
valuesMod$date <- as.character(values$date)
dbAppendTable(con, tbl, valuesMod)
res <- dbReadTable(con, tbl)
expect_true(nrow(res) == 2 * nrow(values))
valuesMod$date <- as.character(values$datetime)
dbAppendTable(con, tbl, valuesMod)
res <- dbReadTable(con, tbl)
expect_true(nrow(res) == 3 * nrow(values))
valuesMod$datetime <- as.character(values$datetime)
dbAppendTable(con, tbl, valuesMod)
res <- dbReadTable(con, tbl)
expect_true(nrow(res) == 4 * nrow(values))
# Finally write dates to datetime targets
# Issue #959, continued
valuesMod$datetime <- values$date
dbAppendTable(con, tbl, valuesMod)
res <- dbReadTable(con, tbl)
expect_true(nrow(res) == 5 * nrow(values))

})
Loading