Skip to content

Commit

Permalink
Conflicts with the master branch resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Aug 28, 2018
2 parents d6dcba9 + 950f872 commit 591ae3f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 33 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
@@ -1,3 +1,4 @@
^\.github$
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
Expand Down
21 changes: 21 additions & 0 deletions .github/move.yml
@@ -0,0 +1,21 @@
# Configuration for move-issues bot - https://github.com/dessant/move-issues

# Delete the command comment when it contains no other content
deleteCommand: true

# Close the source issue after moving
closeSourceIssue: true

# Lock the source issue after moving
lockSourceIssue: false

# Mention issue and comment authors
mentionAuthors: true

# Preserve mentions in the issue content
keepContentMentions: true

# Set custom aliases for targets
# aliases:
# r: repo
# or: owner/repo
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: RPostgres
Title: 'Rcpp' Interface to 'PostgreSQL'
Version: 1.1.2
Date: 2018-08-25
Version: 1.1.1.9002
Date: 2018-08-28
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Jeroen", "Ooms", role = "aut"),
Expand Down
14 changes: 13 additions & 1 deletion NEWS.md
@@ -1,7 +1,19 @@
# RPostgres 1.1.2 (2018-08-25)
# RPostgres 1.1.9002

- Add user interrupt check while waiting for query results to be ready. Allows safe interruption of long-running queries (@zozlak).


# RPostgres 1.1.1.9001

- Avoid aggressive rounding when passing numeric values to the database (#184).


# RPostgres 1.1.1.9000

- Fix partial argument matching in `dbAppendTable()` (r-dbi/DBI#249).
- Fix binding for whole numbers and `POSIXt` timestamps (#191).


# RPostgres 1.1.1 (2018-05-05)

- Add support for `bigint` argument to `dbConnect()`, supported values are `"integer64"`, `"integer"`, `"numeric"` and `"character"`. Large integers are returned as values of that type (r-dbi/DBItest#133).
Expand Down
24 changes: 18 additions & 6 deletions R/PqResult.R
Expand Up @@ -178,8 +178,9 @@ setMethod("dbBind", "PqResult", function(res, params, ...) {
}

params <- factor_to_string(params, warn = TRUE)
params <- posixlt_to_posixct(params)
params <- fix_posixt(params)
params <- difftime_to_hms(params)
params <- fix_numeric(params)
params <- prepare_for_binding(params)
result_bind(res@ptr, params)
invisible(res)
Expand All @@ -194,9 +195,12 @@ factor_to_string <- function(value, warn = FALSE) {
value
}

posixlt_to_posixct <- function(value) {
is_posixlt <- vlapply(value, inherits, "POSIXlt")
value[is_posixlt] <- lapply(value[is_posixlt], as.POSIXct)
fix_posixt <- function(value) {
is_posixt <- vlapply(value, function(c) inherits(c, "POSIXt"))
withr::with_options(
list(digits.secs = 6),
value[is_posixt] <- lapply(value[is_posixt], function(col) format_keep_na(col, usetz = T))
)
value
}

Expand All @@ -206,10 +210,18 @@ difftime_to_hms <- function(value) {
value
}

fix_numeric <- function(value) {
is_numeric <- vlapply(value, is.numeric)
value[is_numeric] <- lapply(
value[is_numeric],
function(x) format_keep_na(x, digits = 17, decimal.mark = ".", scientific = FALSE, na.encode = FALSE)
)
value
}

prepare_for_binding <- function(value) {
is_list <- vlapply(value, is.list)
value[!is_list] <- lapply(value[!is_list], as.character)
value[!is_list] <- lapply(value[!is_list], enc2utf8)
value[!is_list] <- lapply(value[!is_list], function(x) enc2utf8(as.character(x)))
value[is_list] <- lapply(value[is_list], vcapply, function(x) {
if (is.null(x)) NA_character_
else if (is.raw(x)) {
Expand Down
23 changes: 6 additions & 17 deletions R/tables.R
Expand Up @@ -138,15 +138,11 @@ setMethod("sqlData", "PqConnection", function(con, value, row.names = FALSE, ...

# C code takes care of atomic vectors, just need to coerce objects
is_object <- vlapply(value, is.object)
is_posix <- vlapply(value, function(c) inherits(c, "POSIXt"))
is_difftime <- vlapply(value, function(c) inherits(c, "difftime"))
is_blob <- vlapply(value, function(c) is.list(c))
is_whole_number <- vlapply(value, is_whole_number_vector)

withr::with_options(
list(digits.secs = 6),
value[is_posix] <- lapply(value[is_posix], function(col) format_keep_na(col, usetz = T))
)
value <- fix_posixt(value)

value[is_difftime] <- lapply(value[is_difftime], function(col) format_keep_na(hms::as.hms(col)))
value[is_blob] <- lapply(
value[is_blob],
Expand All @@ -162,14 +158,7 @@ setMethod("sqlData", "PqConnection", function(con, value, row.names = FALSE, ...
}
)

value[is_whole_number] <- lapply(
value[is_whole_number],
function(x) {
is_value <- which(!is.na(x))
x[is_value] <- format(x[is_value], scientific = FALSE, na.encode = FALSE)
x
}
)
value <- fix_numeric(value)

value[is_object] <- lapply(value[is_object], as.character)
value
Expand All @@ -178,7 +167,7 @@ setMethod("sqlData", "PqConnection", function(con, value, row.names = FALSE, ...
format_keep_na <- function(x, ...) {
is_na <- is.na(x)
ret <- format(x, ...)
ret[is_na] <- NA
ret[is_na] <- NA_character_
ret
}

Expand All @@ -199,8 +188,8 @@ setMethod("dbAppendTable", signature("DBIConnection"),
pattern = "1",
...
)
values <- sqlRownamesToColumn(value, row.names)
dbExecute(conn, query, param = unname(as.list(value)))

dbExecute(conn, query, params = unname(as.list(value)))
}
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

[![Travis-CI Build Status](https://travis-ci.org/r-dbi/RPostgres.png?branch=master)](https://travis-ci.org/r-dbi/RPostgres) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/r-dbi/RPostgres?branch=master&svg=true)](https://ci.appveyor.com/project/r-dbi/RPostgres) [![codecov](https://codecov.io/gh/r-dbi/RPostgres/branch/master/graph/badge.svg)](https://codecov.io/gh/r-dbi/RPostgres)

RPostgres is an DBI-compliant interface to the postgres database. It's a ground-up rewrite using C++ and Rcpp. Compared to RPostgresSQL, it:
RPostgres is an DBI-compliant interface to the postgres database. It's a ground-up rewrite using C++ and Rcpp. Compared to RPostgreSQL, it:

* Has full support for parameterised queries via `dbSendQuery()`, and `dbBind()`.

Expand Down
3 changes: 1 addition & 2 deletions src/PqDataFrame.cpp
Expand Up @@ -6,8 +6,7 @@
PqDataFrame::PqDataFrame(PqResultSource* result_source,
const std::vector<std::string>& names,
const int n_max_,
const std::vector<DATA_TYPE>& types,
std::vector<Oid> oids) :
const std::vector<DATA_TYPE>& types) :
DbDataFrame(new PqColumnDataSourceFactory(result_source, types), names, n_max_, types)
{
}
Expand Down
3 changes: 1 addition & 2 deletions src/PqDataFrame.h
Expand Up @@ -10,8 +10,7 @@ class PqDataFrame : public DbDataFrame {
PqDataFrame(PqResultSource* result_source,
const std::vector<std::string>& names,
const int n_max_,
const std::vector<DATA_TYPE>& types,
std::vector<Oid> oids);
const std::vector<DATA_TYPE>& types);
~PqDataFrame();
};

Expand Down
4 changes: 2 additions & 2 deletions src/PqResultImpl.cpp
Expand Up @@ -350,7 +350,7 @@ void PqResultImpl::after_bind(bool params_have_rows) {
List PqResultImpl::fetch_rows(const int n_max, int& n) {
n = (n_max < 0) ? 100 : n_max;

PqDataFrame data(this, cache.names_, n_max, cache.types_, cache.oids_);
PqDataFrame data(this, cache.names_, n_max, cache.types_);

if (complete_ && data.get_ncols() == 0) {
warning("Don't need to call dbFetch() for statements, only for queries");
Expand Down Expand Up @@ -435,7 +435,7 @@ bool PqResultImpl::step_done() {
}

List PqResultImpl::peek_first_row() {
PqDataFrame data(this, cache.names_, 1, cache.types_, cache.oids_);
PqDataFrame data(this, cache.names_, 1, cache.types_);

if (!complete_)
data.set_col_values();
Expand Down

0 comments on commit 591ae3f

Please sign in to comment.