From 8071b0aca2ca5c89e0a8173e90e3efe133d2b308 Mon Sep 17 00:00:00 2001 From: schuemie Date: Thu, 29 Jul 2021 04:43:44 -0400 Subject: [PATCH] Fixing issues when fetching dates from SQLite. Fixes #150 --- NEWS.md | 6 +++--- R/Sql.R | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2ed4a7bd..df5bd5e9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,14 +7,14 @@ Changes: 2. Reusing byte buffer when passing 64-bit integers from Java to R for efficiency. -3. Adding support for SQLite with extended types (DATE and DATETIME), with `dbms = 'sqlite extended'`. - -4. Adding support for connecting to Spark. +3. Adding support for connecting to Spark. Bugfixes: 1. Fixing field type of numeric fields on Oracle when fetching data. +2. Fixing issues when fetching dates from SQLite (needed casting to numeric in some scenarios before conversion to date in R). + DatabaseConnector 4.0.2 ======================= diff --git a/R/Sql.R b/R/Sql.R index 9eb212b7..829dd4ac 100644 --- a/R/Sql.R +++ b/R/Sql.R @@ -445,12 +445,11 @@ convertFields <- function(dbms, result) { if (dbms == "sqlite") { for (colname in colnames(result)) { if (grepl("DATE$", colname)) { - result[[colname]] <- as.Date(as.POSIXct(result[[colname]], origin = "1970-01-01", tz = "GMT")) + result[[colname]] <- as.Date(as.POSIXct(as.numeric(result[[colname]]), origin = "1970-01-01", tz = "GMT")) } if (grepl("DATETIME$", colname)) { - result[[colname]] <- as.POSIXct(result[[colname]], origin = "1970-01-01", tz = "GMT") + result[[colname]] <- as.POSIXct(as.numeric(result[[colname]]), origin = "1970-01-01", tz = "GMT") } - } } if (dbms %in% c("bigquery")) {