Skip to content

Commit

Permalink
version 1.0-3
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored and cran-robot committed Dec 6, 2017
0 parents commit b2d08f0
Show file tree
Hide file tree
Showing 82 changed files with 4,927 additions and 0 deletions.
42 changes: 42 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,42 @@
Encoding: UTF-8
Package: RPostgres
Version: 1.0-3
Date: 2017-12-06
Title: 'Rcpp' Interface to 'PostgreSQL'
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Jeroen", "Ooms", role = "aut"),
person("Kirill", "Müller", role = "cre", email = "krlmlr+r@mailbox.org"),
person("RStudio", role = "cph"),
person("R Consortium", role = "cph"),
person("Tomoaki", "Nishiyama", role = "ctb",
comment = "Code for encoding vectors into strings derived from RPostgreSQL"),
person("Kungliga Tekniska Högskolan", role = "ctb", comment = "Source code for timegm")
)
Description:
Fully 'DBI'-compliant 'Rcpp'-backed interface to 'PostgreSQL' <https://www.postgresql.org/>,
an open-source relational database.
License: GPL-2
LazyLoad: true
Depends: R (>= 3.1.0)
Imports: bit64, blob, DBI (>= 0.7), hms, methods, Rcpp (>= 0.11.4.2),
withr
Suggests: DBItest, testthat
LinkingTo: BH, plogr, Rcpp
Collate: 'PqDriver.R' 'PqConnection.R' 'PqResult.R' 'RPostgres-pkg.R'
'RcppExports.R' 'default.R' 'quote.R' 'tables.R'
'transactions.R' 'utils.R'
RoxygenNote: 6.0.1
NeedsCompilation: yes
Packaged: 2017-12-06 00:17:52 UTC; muelleki
Author: Hadley Wickham [aut],
Jeroen Ooms [aut],
Kirill Müller [cre],
RStudio [cph],
R Consortium [cph],
Tomoaki Nishiyama [ctb] (Code for encoding vectors into strings derived
from RPostgreSQL),
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
81 changes: 81 additions & 0 deletions MD5
@@ -0,0 +1,81 @@
488ff95ba8e2d7e9719b961276dff586 *DESCRIPTION
feec1bfbc596fa53152300f94a3a7ab7 *NAMESPACE
466d97216e230f9984d18d9eba02221e *NEWS.md
d3949d39c6e0d3ebb30f5f47e69ed7d2 *R/PqConnection.R
03a867755b841450b855879abbf62b30 *R/PqDriver.R
b91897c5beee9b99af6fd55051171a80 *R/PqResult.R
0b846aae48eacea9831cd61b50eedea2 *R/RPostgres-pkg.R
971e28b404b0401f5b8c38db70e85ff2 *R/RcppExports.R
ff99d2cac7decf472cd0bc8291a78e49 *R/default.R
4ab74e90a8c8573ecb483e069793bb28 *R/quote.R
178feaef07207f895f30fd44b038ace6 *R/tables.R
bbad0daadf44d8a9a43a0a720bef3803 *R/transactions.R
c3efac6c8ef323cae26e037cce6c0d16 *R/utils.R
f3da0de24104764362936f522e26ec6f *README.md
8131313a7c1ae9b3ca097dc23a33918d *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
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
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
00308bd348a82fa234bc3faf490c3bb5 *src/DbColumnStorage.h
e6793b8d19bb3599363801a69f689fb7 *src/DbConnection.cpp
91fd7039d2c543d73abf05c10937928a *src/DbConnection.h
52f74e46125617344b9ef6c064922057 *src/DbDataFrame.cpp
ce8cede04ec884229dfec09a95128ad9 *src/DbDataFrame.h
add0543c36d85ecd4d07d3aec205a3d1 *src/DbResult.cpp
a924adc6fcb47073a85a603d579bb3fc *src/DbResult.h
111e1efb50ff675feb507ea42a24b300 *src/Makevars.in
c5a5d51517569b4577b384cbbc412ad5 *src/Makevars.win
16024658adfb1ccb34b929298ac0396e *src/PqColumnDataSource.cpp
5b65a687e65c37ef8b4f6b0427313c9b *src/PqColumnDataSource.h
d94f34a4e740f7d2f7b1f46c5bbc9411 *src/PqColumnDataSourceFactory.cpp
5932e6e86bc3c43a31954bfd1dac8117 *src/PqColumnDataSourceFactory.h
8dd8d1fe7af6e996859ef849d6b72993 *src/PqDataFrame.cpp
3fb6f7104460055e29d87402ef538b55 *src/PqDataFrame.h
f0cc2e38a2445b24a32298045d42396b *src/PqResultImpl.cpp
68d9a7002c6ded7a86df79e6281b367c *src/PqResultImpl.h
4601b2b6e925fa6761186d25fa93f9f5 *src/PqResultSource.cpp
e2d8563ac79450e3f2347ebc5259ba0e *src/PqResultSource.h
74630eb1d3dd72f0e20c90f0deac0ba6 *src/RPostgres-init.c
5fd33ab4f8ba8480acb085aa8a5bf94d *src/RPostgres_types.h
57b657eeee6da528d4522e3c31781597 *src/RcppExports.cpp
861292357d8bb45348cbc0a2c3c00d2c *src/connection.cpp
40ca6054ebb1ae2e41a65c4f7d8ee5f3 *src/encode.cpp
dfb7deb192ff48e8d33f196f1afaa3d6 *src/encode.h
6b44efff9fefa69c04f41a3cbf3b1ce3 *src/encrypt.cpp
9a3d1653a1ced0d8daac4102701ec18a *src/integer64.h
ecf4e945c36fea5564e665ff5012c19d *src/logging.cpp
7291096e5ad632a53bf9483e3020c1ea *src/pch.h
99039714005147435bebbbd0a640d897 *src/result.cpp
e2f57a97ad5e5d484dc0de7d0656faea *src/win32/timegm.c
4111945e05f4e4a31c72f6ef63b1f1e6 *tests/testthat.R
a74d10622304ddd4ebf25b9b2a11b71c *tests/testthat/helper-DBItest.R
ac3971b62e24ae2cc633a12eb1aa0d3d *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
29890f7f72946cbf870c714ebeaee604 *tests/testthat/test-bigint.R
d0d355c427d7373ab8e6a85d655a381b *tests/testthat/test-data-type.R
3fb2c6809894d3fc84a1832ca0509707 *tests/testthat/test-dbConnect.R
9939d01b8b9c8b6c138e1466a1a74c09 *tests/testthat/test-dbGetQuery.R
dfc643c4d14d440fb7b02648551dca58 *tests/testthat/test-dbWriteTable.R
07ec38d74f52ade1ddc67997730ad1ca *tests/testthat/test-encoding.R
5170ffd2f4d60933fe94753bc048c7f2 *tools/winlibs.R
44 changes: 44 additions & 0 deletions NAMESPACE
@@ -0,0 +1,44 @@
# Generated by roxygen2: do not edit by hand

export(Postgres)
export(postgresDefault)
export(postgresHasDefault)
exportClasses(PqConnection)
exportClasses(PqDriver)
exportClasses(PqResult)
exportMethods(dbBegin)
exportMethods(dbBind)
exportMethods(dbClearResult)
exportMethods(dbColumnInfo)
exportMethods(dbCommit)
exportMethods(dbConnect)
exportMethods(dbDataType)
exportMethods(dbDisconnect)
exportMethods(dbExistsTable)
exportMethods(dbFetch)
exportMethods(dbGetInfo)
exportMethods(dbGetRowCount)
exportMethods(dbGetRowsAffected)
exportMethods(dbGetStatement)
exportMethods(dbHasCompleted)
exportMethods(dbIsValid)
exportMethods(dbListFields)
exportMethods(dbListTables)
exportMethods(dbQuoteIdentifier)
exportMethods(dbQuoteLiteral)
exportMethods(dbQuoteString)
exportMethods(dbReadTable)
exportMethods(dbRemoveTable)
exportMethods(dbRollback)
exportMethods(dbSendQuery)
exportMethods(dbUnloadDriver)
exportMethods(dbWriteTable)
exportMethods(show)
exportMethods(sqlData)
import(DBI)
import(methods)
importFrom(Rcpp,evalCpp)
importFrom(bit64,integer64)
importFrom(blob,blob)
importFrom(hms,hms)
useDynLib(RPostgres, .registration = TRUE)
10 changes: 10 additions & 0 deletions NEWS.md
@@ -0,0 +1,10 @@
# RPostgres 1.0-3 (2017-12-01)

Initial release, compliant to the DBI specification.

- Test almost all test cases of the DBI specification.
- Fully support parametrized queries.
- Spec-compliant transactions.
- 64-bit integers are now supported through the `bit64` package. This also means that numeric literals (as in `SELECT 1`) are returned as 64-bit integers. The `bigint` argument to `dbConnect()` allows overriding the data type on a per-connection basis.
- Correct handling of DATETIME and TIME columns.
- New default `row.names = FALSE`.
174 changes: 174 additions & 0 deletions R/PqConnection.R
@@ -0,0 +1,174 @@
#' @include PqDriver.R
NULL

#' PqConnection and methods.
#'
#' @keywords internal
#' @export
setClass("PqConnection",
contains = "DBIConnection",
slots = list(ptr = "externalptr", bigint = "character")
)

# show()
#' @export
#' @rdname PqConnection-class
setMethod("show", "PqConnection", function(object) {
info <- dbGetInfo(object)

if (info$host == "") {
host <- "socket"
} else {
host <- paste0(info$host, ":", info$port)
}

cat("<PqConnection> ", info$dbname, "@", host, "\n", sep = "")
})

# dbIsValid()
#' @export
#' @rdname PqConnection-class
setMethod("dbIsValid", "PqConnection", function(dbObj, ...) {
connection_valid(dbObj@ptr)
})

# dbDisconnect()
#' @export
#' @rdname dbConnect-PqDriver-method
setMethod("dbDisconnect", "PqConnection", function(conn, ...) {
connection_release(conn@ptr)
invisible(TRUE)
})

# dbSendQuery()

# dbSendStatement()

# dbDataType()
#' @export
#' @rdname dbDataType
setMethod("dbDataType", "PqConnection", function(dbObj, obj, ...) {
if (is.data.frame(obj)) return(vapply(obj, dbDataType, "", dbObj = dbObj))
get_data_type(obj)
})

get_data_type <- function(obj) {
if (is.factor(obj)) return("TEXT")
if (inherits(obj, "POSIXt")) return("TIMESTAMPTZ")
if (inherits(obj, "Date")) return("DATE")
if (inherits(obj, "difftime")) return("TIME")
switch(typeof(obj),
integer = "INTEGER",
double = "REAL",
character = "TEXT",
logical = "BOOLEAN",
list = "BYTEA",
stop("Unsupported type", call. = FALSE)
)
}

# dbQuoteString()

# dbQuoteIdentifier()

# dbWriteTable()

# dbReadTable()

# dbListTables()

# dbExistsTable()

# dbListFields()

# dbRemoveTable()

# dbGetInfo()
#' @export
#' @rdname PqConnection-class
setMethod("dbGetInfo", "PqConnection", function(dbObj, ...) {
connection_info(dbObj@ptr)
})

# dbBegin()

# dbCommit()

# dbRollback()

# other

#' Connect to a PostgreSQL database.
#'
#' Manually disconnecting a connection is not necessary with RPostgres, but
#' still recommended;
#' if you delete the object containing the connection, it will be automatically
#' disconnected during the next GC with a warning.
#'
#' @param drv `RPostgres::Postgres()`
#' @param dbname Database name. If `NULL`, defaults to the user name.
#' Note that this argument can only contain the database name, it will not
#' be parsed as a connection string (internally, `expand_dbname` is set to
#' `false` in the call to
#' [`PQconnectdbParams()`](https://www.postgresql.org/docs/9.6/static/libpq-connect.html)).
#' @param user,password User name and password. If `NULL`, will be
#' retrieved from `PGUSER` and `PGPASSWORD` envvars, or from the
#' appropriate line in `~/.pgpass`. See
#' <http://www.postgresql.org/docs/9.6/static/libpq-pgpass.html> for
#' more details.
#' @param host,port Host and port. If `NULL`, will be retrieved from
#' `PGHOST` and `PGPORT` env vars.
#' @param service Name of service to connect as. If `NULL`, will be
#' ignored. Otherwise, connection parameters will be loaded from the pg_service.conf
#' file and used. See <http://www.postgresql.org/docs/9.6/static/libpq-pgservice.html>
#' for details on this file and syntax.
#' @param ... Other name-value pairs that describe additional connection
#' options as described at
#' <http://www.postgresql.org/docs/9.6/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS>
#' @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 conn Connection to disconnect.
#' @export
#' @examples
#' if (postgresHasDefault()) {
#' library(DBI)
#' # Pass more arguments as necessary to dbConnect()
#' con <- dbConnect(RPostgres::Postgres())
#' dbDisconnect(con)
#' }
setMethod("dbConnect", "PqDriver",
function(drv, dbname = NULL,
host = NULL, port = NULL, password = NULL, user = NULL, service = NULL, ...,
bigint = c("integer64", "integer", "numeric", "character")) {

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)

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

con <- new("PqConnection", ptr = ptr, bigint = bigint)
dbExecute(con, "SET TIMEZONE='UTC'")
con
})


#' Determine database type for R vector.
#'
#' @export
#' @param dbObj Postgres driver or connection.
#' @param obj Object to convert
#' @keywords internal
#' @rdname dbDataType
setMethod("dbDataType", "PqDriver", function(dbObj, obj, ...) {
if (is.data.frame(obj)) return(vapply(obj, dbDataType, "", dbObj = dbObj))
get_data_type(obj)
})
33 changes: 33 additions & 0 deletions R/PqDriver.R
@@ -0,0 +1,33 @@
#' Postgres driver
#'
#' This driver never needs to be unloaded and hence `dbUnload()` is a
#' null-op.
#'
#' @export
#' @useDynLib RPostgres, .registration = TRUE
#' @importFrom Rcpp evalCpp
#' @import methods DBI
#' @examples
#' library(DBI)
#' RPostgres::Postgres()
Postgres <- function() {
new("PqDriver")
}

#' PqDriver and methods.
#'
#' @export
#' @keywords internal
setClass("PqDriver", contains = "DBIDriver")

#' @export
#' @rdname PqDriver-class
setMethod("dbUnloadDriver", "PqDriver", function(drv, ...) {
NULL
})

#' @rdname PqResult-class
#' @export
setMethod("dbIsValid", "PqDriver", function(dbObj, ...) {
TRUE
})

0 comments on commit b2d08f0

Please sign in to comment.