Skip to content

Commit

Permalink
version 1.0-4
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored and cran-robot committed Dec 20, 2017
1 parent b2d08f0 commit 89486dd
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 52 deletions.
12 changes: 8 additions & 4 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Encoding: UTF-8
Package: RPostgres
Version: 1.0-3
Date: 2017-12-06
Version: 1.0-4
Date: 2017-12-20
Title: 'Rcpp' Interface to 'PostgreSQL'
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
Expand All @@ -16,6 +16,10 @@ Authors@R: c(
Description:
Fully 'DBI'-compliant 'Rcpp'-backed interface to 'PostgreSQL' <https://www.postgresql.org/>,
an open-source relational database.
URL: https://github.com/r-dbi/RPostgres
BugReports: https://github.com/r-dbi/RPostgres/issues
SystemRequirements: libpq >= 9.0: libpq-dev (deb) or postgresql-devel
(rpm)
License: GPL-2
LazyLoad: true
Depends: R (>= 3.1.0)
Expand All @@ -28,7 +32,7 @@ Collate: 'PqDriver.R' 'PqConnection.R' 'PqResult.R' 'RPostgres-pkg.R'
'transactions.R' 'utils.R'
RoxygenNote: 6.0.1
NeedsCompilation: yes
Packaged: 2017-12-06 00:17:52 UTC; muelleki
Packaged: 2017-12-20 13:58:34 UTC; muelleki
Author: Hadley Wickham [aut],
Jeroen Ooms [aut],
Kirill Müller [cre],
Expand All @@ -39,4 +43,4 @@ Author: Hadley Wickham [aut],
Kungliga Tekniska Högskolan [ctb] (Source code for timegm)
Maintainer: Kirill Müller <krlmlr+r@mailbox.org>
Repository: CRAN
Date/Publication: 2017-12-06 10:21:43 UTC
Date/Publication: 2017-12-20 15:50:56 UTC
26 changes: 13 additions & 13 deletions MD5
@@ -1,6 +1,6 @@
488ff95ba8e2d7e9719b961276dff586 *DESCRIPTION
4832eb107246f1c494d8b0a0a12e0426 *DESCRIPTION
feec1bfbc596fa53152300f94a3a7ab7 *NAMESPACE
466d97216e230f9984d18d9eba02221e *NEWS.md
4f803550504bcf1c80e414b6d4dab64b *NEWS.md
d3949d39c6e0d3ebb30f5f47e69ed7d2 *R/PqConnection.R
03a867755b841450b855879abbf62b30 *R/PqDriver.R
b91897c5beee9b99af6fd55051171a80 *R/PqResult.R
Expand All @@ -11,36 +11,36 @@ ff99d2cac7decf472cd0bc8291a78e49 *R/default.R
178feaef07207f895f30fd44b038ace6 *R/tables.R
bbad0daadf44d8a9a43a0a720bef3803 *R/transactions.R
c3efac6c8ef323cae26e037cce6c0d16 *R/utils.R
f3da0de24104764362936f522e26ec6f *README.md
8131313a7c1ae9b3ca097dc23a33918d *configure
f68cbc04ffaf966382f11d77aff0ada5 *README.md
593b73f88532bd8bca65acc012047767 *configure
d41d8cd98f00b204e9800998ecf8427e *configure.win
254056c489b1f3e7cc8cdc9fe4a14255 *man/Postgres.Rd
fcfcf00fa9190113b6ee073f9fd11e2c *man/PqConnection-class.Rd
26ccd704aecacc6484f3ea5b2e3eaa5f *man/PqDriver-class.Rd
6ebae0927715384b8e90764e3ad2ba87 *man/PqResult-class.Rd
16132b2b8d5c154d5ad5f9f4bf63cc81 *man/RPostgres-package.Rd
fb4dbf64f44d7e1bdbb2c89f242429e4 *man/RPostgres-package.Rd
3968c41c099acd7c228e85cc99655961 *man/dbConnect-PqDriver-method.Rd
dda833f4b2c036ce15b0555c49add570 *man/dbDataType.Rd
549393f4e48dad8a411932f23b543930 *man/postgres-query.Rd
8e99dd84756b338faa2981ff82a8bfc0 *man/postgres-tables.Rd
068c48521487f453e0c5b15bc6605cfe *man/postgres-transactions.Rd
0f380511ba5e72720224904f24e3a42b *man/postgresHasDefault.Rd
c4a8dbefb34cf9b1b599d26fc3ab3612 *man/quote.Rd
fac812734f22d35b7a19561ea33d2a7c *src/DbColumn.cpp
a567f5b302cec3ac90c52fd40be56c7d *src/DbColumn.cpp
0d0f6283e1aee5ba374ac6c30ce35a57 *src/DbColumn.h
1bead3e4afde4eb4237507be9fd81801 *src/DbColumnDataSource.cpp
c1bd654b0f1d00b85c0213fb15266100 *src/DbColumnDataSource.h
b54f1bed5e031730d84ea6ac5678d57c *src/DbColumnDataSourceFactory.cpp
bdb2b7ed1a0c451b46b90f5ba0cae405 *src/DbColumnDataSourceFactory.h
1ba5afa61895d800dbe19155f7d2c492 *src/DbColumnDataType.h
4d4e148248bbebe297320f33a3244def *src/DbColumnStorage.cpp
42a9a49f416883265bc88ef5d9b35b9a *src/DbColumnStorage.cpp
00308bd348a82fa234bc3faf490c3bb5 *src/DbColumnStorage.h
e6793b8d19bb3599363801a69f689fb7 *src/DbConnection.cpp
b568eeeb2a620abb473f6e96e925dc9e *src/DbConnection.cpp
91fd7039d2c543d73abf05c10937928a *src/DbConnection.h
52f74e46125617344b9ef6c064922057 *src/DbDataFrame.cpp
ce8cede04ec884229dfec09a95128ad9 *src/DbDataFrame.h
add0543c36d85ecd4d07d3aec205a3d1 *src/DbResult.cpp
a924adc6fcb47073a85a603d579bb3fc *src/DbResult.h
548a2a51f2beb996158270d790cfb7d2 *src/DbResult.cpp
8fcd22187e896f842ec2a034eeca9844 *src/DbResult.h
111e1efb50ff675feb507ea42a24b300 *src/Makevars.in
c5a5d51517569b4577b384cbbc412ad5 *src/Makevars.win
16024658adfb1ccb34b929298ac0396e *src/PqColumnDataSource.cpp
Expand All @@ -49,8 +49,8 @@ d94f34a4e740f7d2f7b1f46c5bbc9411 *src/PqColumnDataSourceFactory.cpp
5932e6e86bc3c43a31954bfd1dac8117 *src/PqColumnDataSourceFactory.h
8dd8d1fe7af6e996859ef849d6b72993 *src/PqDataFrame.cpp
3fb6f7104460055e29d87402ef538b55 *src/PqDataFrame.h
f0cc2e38a2445b24a32298045d42396b *src/PqResultImpl.cpp
68d9a7002c6ded7a86df79e6281b367c *src/PqResultImpl.h
d73945444948561434167824978e0d2e *src/PqResultImpl.cpp
53c364304523ba77289d3c77c6ff9b33 *src/PqResultImpl.h
4601b2b6e925fa6761186d25fa93f9f5 *src/PqResultSource.cpp
e2d8563ac79450e3f2347ebc5259ba0e *src/PqResultSource.h
74630eb1d3dd72f0e20c90f0deac0ba6 *src/RPostgres-init.c
Expand All @@ -74,7 +74,7 @@ f251e8d8c1249e774674be514615eeec *tests/testthat/helper-with_table.R
000f052dbee7a744d411e507f6efbb9e *tests/testthat/test-DBItest.R
29890f7f72946cbf870c714ebeaee604 *tests/testthat/test-bigint.R
d0d355c427d7373ab8e6a85d655a381b *tests/testthat/test-data-type.R
3fb2c6809894d3fc84a1832ca0509707 *tests/testthat/test-dbConnect.R
1eb01045fcf55d6094c6d528af1df1af *tests/testthat/test-dbConnect.R
9939d01b8b9c8b6c138e1466a1a74c09 *tests/testthat/test-dbGetQuery.R
dfc643c4d14d440fb7b02648551dca58 *tests/testthat/test-dbWriteTable.R
07ec38d74f52ade1ddc67997730ad1ca *tests/testthat/test-encoding.R
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
@@ -1,3 +1,12 @@
# RPostgres 1.0-4 (2017-12-20)

- Only call `PQcancel()` if the query hasn't completed, fixes transactions on Amazon RedShift (#159, @mmuurr).
- Fix installation on MacOS.
- Check libpq version in configure script (need at least 9.0).
- Fix UBSAN warning: reference binding to null pointer (#156).
- Fix rchk warning: PROTECT internal temporary SEXP objects (#157).
- Fix severe memory leak when fetching results (#154).

# RPostgres 1.0-3 (2017-12-01)

Initial release, compliant to the DBI specification.
Expand Down
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -9,17 +9,18 @@ RPostgres is an DBI-compliant interface to the postgres database. It's a ground-
* Automatically cleans up open connections and result sets, ensuring that you
don't need to worry about leaking connections or memory.

* Is a little faster, saving ~5 ms per query. (For refernce, it takes around 5ms
* Is a little faster, saving ~5 ms per query. (For reference, it takes around 5ms
to retrive a 1000 x 25 result set from a local database, so this is
decent speed up for smaller queries.)

* A simplified build process that relies on system libpq.

## Installation

RPostgres isn't available from CRAN yet, but you can get it from github with:

```R
# Install the latest RPostgres release from CRAN:
install.packages("RPostgres")

# Or the the development version from GitHub:
# install.packages("remotes")
remotes::install_github("r-dbi/RPostgres")
```
Expand Down
25 changes: 16 additions & 9 deletions configure
Expand Up @@ -22,18 +22,22 @@ PKG_LIBS_STATIC="-lpq -lssl -lcrypto -lldap"
if [ $(command -v pkg-config) ]; then
PKGCONFIG_CFLAGS=$(pkg-config --cflags --silence-errors ${PKG_CONFIG_NAME})
PKGCONFIG_LIBS=$(pkg-config --libs --silence-errors ${PKG_CONFIG_NAME})
PKGCONFIG_MODVERSION=$(pkg-config --modversion --silence-errors ${PKG_CONFIG_NAME})

# MacOS seems to ship a broken libpq.pc file
if [[ "$PKGCONFIG_CFLAGS" == *"Internal.sdk"* ]]; then
unset PKGCONFIG_CFLAGS
unset PKGCONFIG_LIBS
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$PKGCONFIG_CFLAGS" == *"Internal.sdk"* ]] || [[ -z "$PKGCONFIG_CFLAGS" ]]; then
unset PKGCONFIG_CFLAGS
unset PKGCONFIG_LIBS
fi
fi
fi

# pg_config values (if available)
if [ $(command -v pg_config) ]; then
PG_INC_DIR=$(pg_config --includedir)
PG_LIB_DIR=$(pg_config --libdir)
PG_VERSION=$(pg_config --version)
fi

# Note that cflags may be empty in case of success
Expand All @@ -42,11 +46,15 @@ if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Using pkg-config cflags and libs!"
echo "Found pkg-config cflags and libs ($PKG_CONFIG_NAME $PKGCONFIG_MODVERSION)!"
PKG_CFLAGS=${PKGCONFIG_CFLAGS}
PKG_LIBS=${PKGCONFIG_LIBS}
elif [ "$PG_INC_DIR" ] || [ "$PG_LIB_DIR" ]; then
echo "Using pg_config includedir and libdir!"
echo "Found pg_config includedir and libdir ($PG_VERSION)!"
if [[ "$PG_VERSION" == "PostgreSQL 8"* ]]; then
echo "This version of libpq is too old! We need at least 9.0!"
exit 1
fi
PKG_CFLAGS="-I${PG_INC_DIR}"
PKG_LIBS="-L${PG_LIB_DIR} ${PKG_LIBS}"
elif [[ "$OSTYPE" == "darwin"* ]]; then
Expand Down Expand Up @@ -94,11 +102,10 @@ fi

# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars.new
if [ ! -f src/Makevars.new ] || (which diff > /dev/null && ! diff -q src/Makevars src/Makevars.new); then
mv src/Makevars.new src/Makevars
else
rm src/Makevars.new
if [ ! -f src/Makevars ] || (which diff > /dev/null && ! diff -q src/Makevars src/Makevars.new); then
cp -f src/Makevars.new src/Makevars
fi
rm -f src/Makevars.new

# Success
exit 0
8 changes: 8 additions & 0 deletions man/RPostgres-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/DbColumn.cpp
Expand Up @@ -72,12 +72,13 @@ void DbColumn::warn_type_conflicts(const String& name) const {

DbColumn::operator SEXP() const {
DATA_TYPE dt = get_last_storage()->get_data_type();
SEXP ret = DbColumnStorage::allocate(n, dt);
SEXP ret = PROTECT(DbColumnStorage::allocate(n, dt));
int pos = 0;
for (size_t k = 0; k < storage.size(); ++k) {
const DbColumnStorage& current = storage[k];
pos += current.copy_to(ret, dt, pos);
}
UNPROTECT(1);
return ret;
}

Expand Down
6 changes: 4 additions & 2 deletions src/DbColumnStorage.cpp
Expand Up @@ -38,9 +38,10 @@ SEXP DbColumnStorage::allocate(const R_xlen_t length, DATA_TYPE dt) {
SEXPTYPE type = sexptype_from_datatype(dt);
RObject class_ = class_from_datatype(dt);

SEXP ret = Rf_allocVector(type, length);
SEXP ret = PROTECT(Rf_allocVector(type, length));
if (!Rf_isNull(class_)) Rf_setAttrib(ret, R_ClassSymbol, class_);
set_attribs_from_datatype(ret, dt);
UNPROTECT(1);
return ret;
}

Expand Down Expand Up @@ -209,7 +210,8 @@ Rcpp::RObject DbColumnStorage::class_from_datatype(DATA_TYPE dt) {
void DbColumnStorage::set_attribs_from_datatype(SEXP x, DATA_TYPE dt) {
switch (dt) {
case DT_TIME:
Rf_setAttrib(x, CharacterVector::create("units"), CharacterVector::create("secs"));
Rf_setAttrib(x, PROTECT(CharacterVector::create("units")), PROTECT(CharacterVector::create("secs")));
UNPROTECT(2);
break;

default:
Expand Down
32 changes: 23 additions & 9 deletions src/DbConnection.cpp
@@ -1,6 +1,7 @@
#include "pch.h"
#include "DbConnection.h"
#include "encode.h"
#include "DbResult.h"


DbConnection::DbConnection(std::vector<std::string> keys, std::vector<std::string> values) :
Expand Down Expand Up @@ -44,34 +45,45 @@ PGconn* DbConnection::conn() {
}

void DbConnection::set_current_result(const DbResult* pResult) {
// Cancels previous query, if needed.
// same result pointer, nothing to do.
if (pResult == pCurrentResult_)
return;

// try to clean up remnants of any previous queries.
// (even if (the new) pResult is NULL, we should try to reset the back-end.)
if (pCurrentResult_ != NULL) {
if (pResult != NULL)
warning("Cancelling previous query");
if (pResult != NULL) {
warning("Closing open result set, cancelling previous query");
}

cleanup_query();
}

pCurrentResult_ = pResult;
}


/**
* Documentation for canceling queries:
* https://www.postgresql.org/docs/9.6/static/libpq-cancel.html
**/
void DbConnection::cancel_query() {
check_connection();

// Cancel running query
// first allocate a 'cancel command' data structure.
// should only return NULL if either:
// * the connection is NULL or
// * the connection is invalid.
PGcancel* cancel = PQgetCancel(pConn_);
if (cancel == NULL) {
warning("Failed to cancel running query");
return;
}
if (cancel == NULL) stop("Connection error detected via PQgetCancel()");

// PQcancel() actually issues the cancel command to the backend.
char errbuf[256];
if (!PQcancel(cancel, errbuf, sizeof(errbuf))) {
warning(errbuf);
}

// free up the data structure allocated by PQgetCancel().
PQfreeCancel(cancel);
}

Expand Down Expand Up @@ -217,6 +229,8 @@ void DbConnection::conn_stop(PGconn* conn, const char* msg) {
}

void DbConnection::cleanup_query() {
cancel_query();
if(pCurrentResult_ != NULL && !(pCurrentResult_->complete())) {
cancel_query();
}
finish_query();
}
4 changes: 2 additions & 2 deletions src/DbResult.cpp
Expand Up @@ -50,8 +50,8 @@ int DbResult::n_rows_fetched() {
return impl->n_rows_fetched();
}

bool DbResult::complete() {
return impl->complete();
bool DbResult::complete() const {
return (impl == NULL) || impl->complete();
}

List DbResult::get_column_info() {
Expand Down
2 changes: 1 addition & 1 deletion src/DbResult.h
Expand Up @@ -25,7 +25,7 @@ class DbResult : boost::noncopyable {
~DbResult();

public:
bool complete();
bool complete() const;
bool active() const;
int n_rows_fetched();
int n_rows_affected();
Expand Down

0 comments on commit 89486dd

Please sign in to comment.