Skip to content

Commit

Permalink
version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored and cran-robot committed Dec 18, 2019
1 parent 405168b commit e84ce2c
Show file tree
Hide file tree
Showing 48 changed files with 701 additions and 285 deletions.
55 changes: 33 additions & 22 deletions DESCRIPTION
@@ -1,37 +1,48 @@
Package: RPostgres
Title: 'Rcpp' Interface to 'PostgreSQL'
Version: 1.1.3
Date: 2019-12-05
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Jeroen", "Ooms", role = "aut"),
person("Kirill", "M\u00fcller", role = c("aut", "cre"), email = "krlmlr+r@mailbox.org", comment = c(ORCID = "0000-0002-1416-3412")),
person("RStudio", role = "cph"),
person("R Consortium", role = "fnd"),
person("Tomoaki", "Nishiyama", role = "ctb",
comment = "Code for encoding vectors into strings derived from RPostgreSQL")
)
Description:
Fully 'DBI'-compliant 'Rcpp'-backed interface to 'PostgreSQL' <https://www.postgresql.org/>,
an open-source relational database.
License: GPL-2
URL: https://github.com/r-dbi/RPostgres
Version: 1.2.0
Date: 2019-12-17
Authors@R:
c(person(given = "Hadley",
family = "Wickham",
role = "aut"),
person(given = "Jeroen",
family = "Ooms",
role = "aut"),
person(given = "Kirill",
family = "M\u00fcller",
role = c("aut", "cre"),
email = "krlmlr+r@mailbox.org",
comment = c(ORCID = "0000-0002-1416-3412")),
person(given = "RStudio",
role = "cph"),
person(given = "R Consortium",
role = "fnd"),
person(given = "Tomoaki",
family = "Nishiyama",
role = "ctb",
comment = "Code for encoding vectors into strings derived from RPostgreSQL"))
Description: Fully 'DBI'-compliant 'Rcpp'-backed interface to
'PostgreSQL' <https://www.postgresql.org/>, an open-source relational
database.
License: GPL-3
URL: https://rpostgres.r-dbi.org, https://github.com/r-dbi/RPostgres
BugReports: https://github.com/r-dbi/RPostgres/issues
Depends: R (>= 3.1.0)
Imports: bit64, blob (>= 1.1.1), DBI (>= 1.0.0), hms, methods, Rcpp (>=
0.11.4.2), withr
Suggests: DBItest, testthat
Imports: bit64, blob (>= 1.2.0), DBI (>= 1.1.0), hms (>= 0.5.0),
methods, Rcpp (>= 0.11.4.2), withr
Suggests: DBItest (>= 1.7.0), testthat
LinkingTo: BH, plogr (>= 0.2.0), Rcpp
Encoding: UTF-8
LazyLoad: true
RoxygenNote: 6.0.1.9000
RoxygenNote: 7.0.2
SystemRequirements: libpq >= 9.0: libpq-dev (deb) or postgresql-devel
(rpm)
Collate: 'PqDriver.R' 'PqConnection.R' 'PqResult.R' 'RPostgres-pkg.R'
'RcppExports.R' 'default.R' 'export.R' 'names.R' 'quote.R'
'tables.R' 'transactions.R' 'utils.R'
NeedsCompilation: yes
Packaged: 2019-12-07 12:01:35 UTC; kirill
Packaged: 2019-12-18 08:47:19 UTC; kirill
Author: Hadley Wickham [aut],
Jeroen Ooms [aut],
Kirill Müller [aut, cre] (<https://orcid.org/0000-0002-1416-3412>),
Expand All @@ -41,4 +52,4 @@ Author: Hadley Wickham [aut],
from RPostgreSQL)
Maintainer: Kirill Müller <krlmlr+r@mailbox.org>
Repository: CRAN
Date/Publication: 2019-12-07 15:40:02 UTC
Date/Publication: 2019-12-18 09:50:02 UTC
89 changes: 47 additions & 42 deletions MD5
@@ -1,33 +1,33 @@
4697e9cad3d8c27124adda08f128a705 *DESCRIPTION
932441c19d5ccd05b7f44c78580e9686 *DESCRIPTION
0c8c9e67470d022b724f52ebaef8dd3d *NAMESPACE
2cab1d6b7df043c8bfe265dc1551c9f7 *NEWS.md
ea0b679f7bd7080deb4d7702f03190e0 *R/PqConnection.R
528f400dd08dc6f21674359e80b67d91 *R/PqDriver.R
2cb26c936e4c57df05b78767fd5827d0 *R/PqResult.R
5997112b3533461734a1b950beb7938c *NEWS.md
4424ea2614caded2cee6fc0c488e3bd2 *R/PqConnection.R
db09b03d1b1aded985caf84e0261c04d *R/PqDriver.R
a74994de4f57026e7de1b917a676f6d9 *R/PqResult.R
0b846aae48eacea9831cd61b50eedea2 *R/RPostgres-pkg.R
971e28b404b0401f5b8c38db70e85ff2 *R/RcppExports.R
ff21aec224911293cfbba6b5ff459a51 *R/RcppExports.R
c5497949eb1f47b24120170f688d4d04 *R/default.R
568aecb1066757bc112c6798174ba377 *R/export.R
55d0f1da7f7a73971d0a58339fb99b6c *R/names.R
ff2c51f565a54d438a9384c8dd8a139b *R/quote.R
0fea880df54bdc46f6d0a0a716e7f524 *R/tables.R
9f7151baba23ec78f1da5b297d652854 *R/quote.R
83e9f072e4f6a2d054fbd5828a6b0ed2 *R/tables.R
bbad0daadf44d8a9a43a0a720bef3803 *R/transactions.R
c3efac6c8ef323cae26e037cce6c0d16 *R/utils.R
fd1af0835186a29508665ac416772551 *README.md
22824e9abd9b0a99ea42edf515701240 *R/utils.R
6c4d140402bbbe64e7f160b943b59812 *README.md
e76f161d3cb1c6ff5af082f337057027 *configure
d41d8cd98f00b204e9800998ecf8427e *configure.win
254056c489b1f3e7cc8cdc9fe4a14255 *man/Postgres.Rd
809eb0aa572aeae0521d78fc27f5854c *man/PqConnection-class.Rd
26ccd704aecacc6484f3ea5b2e3eaa5f *man/PqDriver-class.Rd
6ebae0927715384b8e90764e3ad2ba87 *man/PqResult-class.Rd
10051d734f12cf564e1e1300a73edc19 *man/RPostgres-package.Rd
83bc1c5516b1b9c1acff5779e70e304d *man/dbConnect-PqDriver-method.Rd
dda833f4b2c036ce15b0555c49add570 *man/dbDataType.Rd
549393f4e48dad8a411932f23b543930 *man/postgres-query.Rd
154ecab97ddc220653561ea7db71c27b *man/postgres-tables.Rd
068c48521487f453e0c5b15bc6605cfe *man/postgres-transactions.Rd
0f380511ba5e72720224904f24e3a42b *man/postgresHasDefault.Rd
7e701610d5c1fb8fa7b3a8fac3cc872f *man/quote.Rd
f0cda4140152c4d9260438779f2baca6 *man/PqDriver-class.Rd
757d0e726b6ce92bc25efc7e65a07dbe *man/PqResult-class.Rd
d0fc7a2597d7248a2eceb8abe1c7b2cc *man/RPostgres-package.Rd
0778be10b7dfdfbe0e626390d3f89c3f *man/dbConnect-PqDriver-method.Rd
5f8eee318fabf2e8ecb3f4f38340ba40 *man/dbDataType.Rd
0e52e6a257c93a43bd5c047d24e3ffe3 *man/postgres-query.Rd
42a4ef31eecc95f1389a2bc316006345 *man/postgres-tables.Rd
fde1edb3bc84ef52ed377201233aed84 *man/postgres-transactions.Rd
c5604a39840f787a2f8b4b3a43ff855c *man/postgresHasDefault.Rd
8af1850b90bfee5f443b74088457e31b *man/quote.Rd
ab3e334858adafd39904d78c90b3b3e0 *man/reexports.Rd
a567f5b302cec3ac90c52fd40be56c7d *src/DbColumn.cpp
0d0f6283e1aee5ba374ac6c30ce35a57 *src/DbColumn.h
Expand All @@ -36,53 +36,58 @@ c1bd654b0f1d00b85c0213fb15266100 *src/DbColumnDataSource.h
b54f1bed5e031730d84ea6ac5678d57c *src/DbColumnDataSourceFactory.cpp
bdb2b7ed1a0c451b46b90f5ba0cae405 *src/DbColumnDataSourceFactory.h
1ba5afa61895d800dbe19155f7d2c492 *src/DbColumnDataType.h
42a9a49f416883265bc88ef5d9b35b9a *src/DbColumnStorage.cpp
00308bd348a82fa234bc3faf490c3bb5 *src/DbColumnStorage.h
635e7a8ce8fad8137bb62dac19e44acd *src/DbConnection.cpp
91fd7039d2c543d73abf05c10937928a *src/DbConnection.h
25c0a46c3f755b3bcc28eb2052b3cf79 *src/DbDataFrame.cpp
7f3a277cb7d4726f3c5d0fddc43048a6 *src/DbColumnStorage.cpp
e24e7165514d9c6d82259d8c0ed4dfe6 *src/DbColumnStorage.h
4cd3d1578b8bd07c838f05a673a47f47 *src/DbConnection.cpp
9b53b0beef2d04b871d8df5f77497f31 *src/DbConnection.h
e089124da5acaa0c87cc7a22c69c2e52 *src/DbDataFrame.cpp
aa6b004a18a443064e92833378f109c6 *src/DbDataFrame.h
863c387085575330973494a7ec75f061 *src/DbResult.cpp
1b26b8077ef82ec2a40c598aadccd5b9 *src/DbResult.h
111e1efb50ff675feb507ea42a24b300 *src/Makevars.in
96ae4c931ee1599e2f8fd62ddea8c95e *src/Makevars.win
20cbb613c26d6e2125e550ece6803cfc *src/DbResult.cpp
df6ee010b5f5637ba69f417d9d3ac656 *src/DbResult.h
6c1a9122d8aeef539983d71fb6d7fa9e *src/DbResultImpl.h
ff55e7f9ffcc22262b9f25b3f5c02491 *src/DbResultImplDecl.h
377c2a05032d7b1c566b0a11bc7f40b4 *src/Makevars.in
9fd2217c2fcdd90eaf94a4d56ca4763f *src/Makevars.win
d2da0737c49f3be0e57b1dca3c57f431 *src/PqColumnDataSource.cpp
5b65a687e65c37ef8b4f6b0427313c9b *src/PqColumnDataSource.h
7ea23ce015d4e0a8c47581ae646f4f61 *src/PqColumnDataSourceFactory.cpp
5932e6e86bc3c43a31954bfd1dac8117 *src/PqColumnDataSourceFactory.h
ad51c490ab4c9bf3aaba14544108be4c *src/PqDataFrame.cpp
50318e54863d1df1c4dbec190934c5f4 *src/PqDataFrame.h
bcab2e04b35529b4f8a0c8df523ac5a4 *src/PqResultImpl.cpp
5313fb679f2743c3479aacb53b01173b *src/PqResultImpl.h
27a71f2130145a0634545f8306660eea *src/PqDataFrame.cpp
e991d1583380c2955033c447eb117afc *src/PqDataFrame.h
a2669d7238dd67e99a9be4a6b3d9682d *src/PqResult.cpp
17a3e10f931738042a5d9af943bdf283 *src/PqResult.h
c17968fed41931d4a88e4d4ab7d8a99e *src/PqResultImpl.cpp
de491504b5eb076e4bcaff541f123c4b *src/PqResultImpl.h
4601b2b6e925fa6761186d25fa93f9f5 *src/PqResultSource.cpp
e2d8563ac79450e3f2347ebc5259ba0e *src/PqResultSource.h
8dfa99fe35180785119bedf906a81471 *src/PqUtils.cpp
721fb987c03729a6ca2da77db92b4425 *src/PqUtils.h
74630eb1d3dd72f0e20c90f0deac0ba6 *src/RPostgres-init.c
5fd33ab4f8ba8480acb085aa8a5bf94d *src/RPostgres_types.h
57b657eeee6da528d4522e3c31781597 *src/RcppExports.cpp
83b12136f175fa871cc07329823adc43 *src/configure.bash
861292357d8bb45348cbc0a2c3c00d2c *src/connection.cpp
0921b50ce945035c653a12012dab3435 *src/RcppExports.cpp
72665b36a2a367d378e79f8631bd5126 *src/configure.bash
871f96540848a8ad364f77af54a39827 *src/connection.cpp
2802c3b6e9aaed4521e887934f17b1db *src/encode.cpp
dfb7deb192ff48e8d33f196f1afaa3d6 *src/encode.h
6b44efff9fefa69c04f41a3cbf3b1ce3 *src/encrypt.cpp
9a3d1653a1ced0d8daac4102701ec18a *src/integer64.h
ecf4e945c36fea5564e665ff5012c19d *src/logging.cpp
7291096e5ad632a53bf9483e3020c1ea *src/pch.h
60dca4ef2333c74e57542dc491fccc40 *src/result.cpp
a1a5fe3a3d0be95b53107e2b21cdee17 *src/result.cpp
a9f6581105458f9b9a9bcc0b7bf4971f *src/workarounds/XPtr.h
4111945e05f4e4a31c72f6ef63b1f1e6 *tests/testthat.R
a74d10622304ddd4ebf25b9b2a11b71c *tests/testthat/helper-DBItest.R
60e9b2574eb76a3da502315b6630c2a5 *tests/testthat/helper-astyle.R
5f99bf46169a27c39db6b35611d0da42 *tests/testthat/helper-with_database_connection.R
f251e8d8c1249e774674be514615eeec *tests/testthat/helper-with_table.R
78eff1c41624d5eb4d7e5036b59b7d80 *tests/testthat/helper-without_rownames.R
000f052dbee7a744d411e507f6efbb9e *tests/testthat/test-DBItest.R
e13d279c7012f495ada22f6b8f0c3896 *tests/testthat/test-DBItest.R
29890f7f72946cbf870c714ebeaee604 *tests/testthat/test-bigint.R
d0d355c427d7373ab8e6a85d655a381b *tests/testthat/test-data-type.R
a43898d0ffd33f8ad8fff8e6805d74c3 *tests/testthat/test-data-type.R
1eb01045fcf55d6094c6d528af1df1af *tests/testthat/test-dbConnect.R
be8d2023b9ff4f2659fc383c893c89ac *tests/testthat/test-dbGetQuery.R
114c33dfaee7e16c55788e1b1a05bb50 *tests/testthat/test-dbWriteTable.R
a81f5dd62df14a99a5c959e5748c0091 *tests/testthat/test-dbGetQuery.R
7373bd9dc8dab391a83ebfbcc52633c3 *tests/testthat/test-dbQuoteIdentifier.R
5f5c2b16815966fb98a31c5bc11eae96 *tests/testthat/test-dbWriteTable.R
07ec38d74f52ade1ddc67997730ad1ca *tests/testthat/test-encoding.R
76b610eb3c1116bb15b7f76834e41209 *tests/testthat/test-types.R
5170ffd2f4d60933fe94753bc048c7f2 *tools/winlibs.R
14abd2023341cbf0b71e250107c1feb3 *tools/winlibs.R
37 changes: 37 additions & 0 deletions NEWS.md
@@ -1,3 +1,40 @@
# RPostgres 1.2.0

## Communication with the database

- Breaking: Translate floating-point values to `DOUBLE PRECISION` by default (#194).
- Avoid aggressive rounding when passing numeric values to the database (#184).
- Avoid adding extra spaces for numerics (#216).
- Column names and error messages are UTF-8 encoded (#172).
- `dbWriteTable(copy = FALSE)`, `sqlData()` and `dbAppendTable()` now work for character columns (#209), which are always converted to UTF-8.

## New features

- Add `timezone` argument to `dbConnect()` (#187, @trafficonese).
- Implement `dbGetInfo()` for the driver and the connection object.
- `dbConnect()` gains `check_interrupts` argument that allows interrupting execution safely while waiting for query results to be ready (#193, @zozlak).
- `dbUnquoteIdentifier()` also handles unquoted identifiers of the form `table` or `schema.table`, for compatibility with dbplyr. In addition, a `catalog` component is supported for quoting and unquoting with `Id()`.
- `dbQuoteLiteral()` available for `"character"` (#209).
- Windows: update libpq to 11.1.0.
- Fulfill CII badge requirements (#227, @TSchiefer).

## Bug fixes

- Hide unused symbols in shared library (#230, @troels).
- Fix partial argument matching in `dbAppendTable()` (r-dbi/DBI#249).
- Fix binding for whole numbers and `POSIXt` timestamps (#191).

## Internal

- `sqlData(copy = FALSE)` now uses `dbQuoteLiteral()` (#209).
- Add tests for `dbUnquoteIdentifier()` (#220, @baileych).
- Improved tests for numerical precision (#203, @harvey131).
- Fix test: change from `REAL` to `DOUBLE PRECISION` (#204, @harvey131).
- Implement `dbAppendTable()` for own connection class, don't hijack base class implementation (r-dbi/RMariaDB#119).
- Avoid including the call in errors.
- Align `DbResult` and other classes with RSQLite and RMariaDB.


# RPostgres 1.1.3

- Replace `std::mem_fn()` by `boost::mem_fn()` which works for older compilers.
Expand Down
25 changes: 17 additions & 8 deletions R/PqConnection.R
Expand Up @@ -73,7 +73,7 @@ get_data_type <- function(obj) {
if (inherits(obj, "integer64")) return("BIGINT")
switch(typeof(obj),
integer = "INTEGER",
double = "REAL",
double = "DOUBLE PRECISION",
character = "TEXT",
logical = "BOOLEAN",
list = "BYTEA",
Expand Down Expand Up @@ -142,6 +142,11 @@ setMethod("dbGetInfo", "PqConnection", function(dbObj, ...) {
#' @param bigint The R type that 64-bit integer types should be mapped to,
#' default is [bit64::integer64], which allows the full range of 64 bit
#' integers.
#' @param check_interrupts Should user interrupts be checked during the query execution (before
#' first row of data is available)? Setting to `TRUE` allows interruption of queries
#' running too long.
#' @param timezone Sets the timezone for the connection. The default is `"UTC"`.
#' If `NULL` then no timezone is set, which defaults to localtime.
#' @param conn Connection to disconnect.
#' @export
#' @examples
Expand All @@ -154,26 +159,30 @@ setMethod("dbGetInfo", "PqConnection", function(dbObj, ...) {
setMethod("dbConnect", "PqDriver",
function(drv, dbname = NULL,
host = NULL, port = NULL, password = NULL, user = NULL, service = NULL, ...,
bigint = c("integer64", "integer", "numeric", "character")) {
bigint = c("integer64", "integer", "numeric", "character"),
check_interrupts = FALSE, timezone = "UTC") {

opts <- unlist(list(dbname = dbname, user = user, password = password,
host = host, port = as.character(port), service = service, client_encoding = "utf8", ...))
if (!is.character(opts)) {
stop("All options should be strings", call. = FALSE)
}
bigint <- match.arg(bigint)
stopifnot(is.logical(check_interrupts), all(!is.na(check_interrupts)), length(check_interrupts) == 1)

if (length(opts) == 0) {
ptr <- connection_create(character(), character())
ptr <- connection_create(character(), character(), check_interrupts)
} else {
ptr <- connection_create(names(opts), as.vector(opts))
ptr <- connection_create(names(opts), as.vector(opts), check_interrupts)
}

con <- new("PqConnection", ptr = ptr, bigint = bigint, typnames = data.frame())
dbExecute(con, "SET TIMEZONE='UTC'")
con@typnames <- dbGetQuery(con, "SELECT oid, typname FROM pg_type")
conn <- new("PqConnection", ptr = ptr, bigint = bigint, typnames = data.frame())
if (!is.null(timezone)) {
dbExecute(conn, paste0("SET TIMEZONE='", timezone, "'"))
}
conn@typnames <- dbGetQuery(conn, "SELECT oid, typname FROM pg_type")

con
conn
})

# dbDisconnect() (after dbConnect() to maintain order in documentation)
Expand Down
24 changes: 24 additions & 0 deletions R/PqDriver.R
Expand Up @@ -31,3 +31,27 @@ setMethod("dbUnloadDriver", "PqDriver", function(drv, ...) {
setMethod("dbIsValid", "PqDriver", function(dbObj, ...) {
TRUE
})


# Set during installation time for the correct library
PACKAGE_VERSION <- utils::packageVersion(utils::packageName())

#' @rdname PqDriver-class
#' @export
setMethod("dbGetInfo", "PqDriver", function(dbObj, ...) {
client_version <- client_version()
major <- client_version %/% 10000
minor <- (client_version - major * 10000) %/% 100
rev <- client_version - major * 10000 - minor * 100

if (major >= 10) {
client_version <- package_version(paste0(major, ".", rev))
} else {
client_version <- package_version(paste0(major, ".", minor, ".", rev))
}

list(
driver.version = PACKAGE_VERSION,
client.version = client_version
)
})
30 changes: 19 additions & 11 deletions R/PqResult.R
Expand Up @@ -172,14 +172,11 @@ setMethod("dbBind", "PqResult", function(res, params, ...) {
stop("Named parameters not supported", call. = FALSE)
}
if (!is.list(params)) params <- as.list(params)
lengths <- unique(viapply(params, length))
if (length(lengths) > 1) {
stop("All parameters must have the same length.", call. = FALSE)
}

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,22 +191,33 @@ 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
}

difftime_to_hms <- function(value) {
is_difftime <- vlapply(value, inherits, "difftime")
value[is_difftime] <- lapply(value[is_difftime], hms::as.hms)
value[is_difftime] <- lapply(value[is_difftime], hms::as_hms)
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, trim = TRUE)
)
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

0 comments on commit e84ce2c

Please sign in to comment.