├── .travis.yml ├── README.md ├── RPostgreSQL ├── ChangeLog ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R │ ├── PostgreSQL.R │ ├── PostgreSQLSupport.R │ ├── S4R.R │ ├── dbObjectId.R │ └── zzz.R ├── cleanup ├── configure ├── configure.ac ├── configure.win ├── inst │ ├── ANNOUNCEMENT │ ├── NEWS │ ├── README │ ├── THANKS │ ├── TODO │ └── devTests │ │ ├── PostgreSQLDataTypeTest.r │ │ ├── copyTest.sh │ │ ├── datetime.r │ │ ├── demo.r │ │ ├── timeTypeComparison.r │ │ ├── transactionManagement.r │ │ └── typeTest.r ├── man │ ├── PostgreSQL.Rd │ ├── PostgreSQLConnection-class.Rd │ ├── PostgreSQLDriver-class.Rd │ ├── PostgreSQLObject-class.Rd │ ├── PostgreSQLResult-class.Rd │ ├── S4R.Rd │ ├── dbApply-methods.Rd │ ├── dbApply.Rd │ ├── dbCallProc-methods.Rd │ ├── dbCommit-methods.Rd │ ├── dbConnect-methods.Rd │ ├── dbDataType-methods.Rd │ ├── dbDriver-methods.Rd │ ├── dbGetInfo-methods.Rd │ ├── dbListTables-methods.Rd │ ├── dbObjectId-class.Rd │ ├── dbReadTable-methods.Rd │ ├── dbSendQuery-methods.Rd │ ├── dbSetDataMappings-methods.Rd │ ├── fetch-methods.Rd │ ├── isPostgresqlIdCurrent.Rd │ ├── make.db.names-methods.Rd │ ├── postgresqlBuildTableDefinition.Rd │ ├── postgresqlDBApply.Rd │ ├── postgresqlSupport.Rd │ └── summary-methods.Rd └── src │ ├── Makevars.in │ ├── Makevars.win │ ├── RS-DBI.c │ ├── RS-DBI.h │ ├── RS-PQescape.c │ ├── RS-PostgreSQL.c │ ├── RS-PostgreSQL.h │ ├── RS-pgsql-copy.c │ ├── RS-pgsql-getResult.c │ ├── RS-pgsql-pqexec.c │ ├── RS-pgsql-pqexecparams.c │ ├── S4R.h │ ├── config.guess │ ├── config.sub │ ├── install-sh │ └── libpq │ ├── .gitignore │ ├── COPYRIGHT │ ├── Makefile.darwin │ ├── Makefile.global.darwin │ ├── Makefile.global.win32 │ ├── Makefile.global.win64 │ ├── Makefile.port.darwin │ ├── Makefile.shlib.darwin │ ├── Makefile.win │ ├── Makefile.win32 │ ├── README │ ├── auth.h │ ├── bcc32.mak │ ├── be-fsstubs.h │ ├── blibpqdll.def │ ├── c.h │ ├── chklocale.c │ ├── common │ └── fe_memutils.h │ ├── crypt.c │ ├── crypt.h │ ├── encnames.c │ ├── exports.txt │ ├── fe-auth.c │ ├── fe-auth.h │ ├── fe-connect.c │ ├── fe-exec.c │ ├── fe-lobj.c │ ├── fe-misc.c │ ├── fe-print.c │ ├── fe-protocol2.c │ ├── fe-protocol3.c │ ├── fe-secure-openssl.c │ ├── fe-secure.c │ ├── getaddrinfo.c │ ├── getaddrinfo.h │ ├── hba.h │ ├── inet_aton.c │ ├── inet_net_ntop.c │ ├── ip.c │ ├── ip.h │ ├── libpq-be.h │ ├── libpq-dist.rc │ ├── libpq-events.c │ ├── libpq-events.h │ ├── libpq-fe.h │ ├── libpq-fs.h │ ├── libpq-int.h │ ├── libpq.h │ ├── libpq.pc │ ├── libpq.rc │ ├── libpq.rc.in │ ├── libpq │ ├── auth.h │ ├── be-fsstubs.h │ ├── crypt.h │ ├── hba.h │ ├── ip.h │ ├── libpq-be.h │ ├── libpq-fs.h │ ├── libpq.h │ ├── md5.h │ ├── pqcomm.h │ ├── pqformat.h │ └── pqsignal.h │ ├── libpqddll.def │ ├── libpqdll.def │ ├── mb │ └── pg_wchar.h │ ├── md5.c │ ├── md5.h │ ├── nls.mk │ ├── noblock.c │ ├── open.c │ ├── pg_config.h.darwin │ ├── pg_config.h.win │ ├── pg_config_ext.h │ ├── pg_config_ext.h.win32 │ ├── pg_config_manual.h │ ├── pg_config_os.h.darwin │ ├── pg_config_os.h.win │ ├── pg_config_paths.h │ ├── pg_config_paths.h.darwin │ ├── pg_config_paths.h.win │ ├── pg_service.conf.sample │ ├── pgsleep.c │ ├── pgstrcasecmp.c │ ├── po │ ├── cs.po │ ├── de.po │ ├── es.po │ ├── fr.po │ ├── it.po │ ├── ja.po │ ├── ko.po │ ├── pl.po │ ├── pt_BR.po │ ├── ru.po │ ├── tr.po │ ├── zh_CN.po │ └── zh_TW.po │ ├── port.h │ ├── postgres_ext.h │ ├── postgres_fe.h │ ├── pqcomm.h │ ├── pqexpbuffer.c │ ├── pqexpbuffer.h │ ├── pqformat.h │ ├── pqsignal.c │ ├── pqsignal.h │ ├── pthread-win32.c │ ├── pthread-win32.h │ ├── snprintf.c │ ├── strlcpy.c │ ├── system.c │ ├── thread.c │ ├── utils │ └── palloc.h │ ├── wchar.c │ ├── win32.c │ ├── win32.h │ ├── win32.mak │ ├── win32error.c │ ├── win32setlocale.c │ └── wininclude │ ├── arpa │ └── inet.h │ ├── netdb.h │ ├── netinet │ └── in.h │ ├── pwd.h │ └── sys │ ├── socket.h │ └── wait.h ├── build_check_with_vars.sh ├── check_with_vars.sh └── exttests ├── bytea.R ├── bytea.Rout.save ├── connectWithNull.R ├── connectWithNull.Rout.save ├── datetimeTests.R ├── dbColumnInfo.R ├── dbWriteTableFailTest.R ├── dbWriteTableFailTest.Rout.save ├── selectWhereZero.R ├── selectWhereZero.Rout.save └── unknowntype.R /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | 3 | sudo: enabled 4 | 5 | env: 6 | - POSTGRES_USER=postgres POSTGRES_PASSWD= POSTGRES_HOST=localhost POSTGRES_DATABASE=testdb 7 | 8 | 9 | addons: 10 | postgresql: "9.6" 11 | apt: 12 | packages: 13 | - postgresql-9.6 14 | - postgresql-client-9.6 15 | - postgresql-9.6-postgis-2.3 16 | - postgresql-server-dev-9.6 17 | 18 | apt_packages: 19 | - libpq-dev 20 | 21 | services: 22 | - postgresql 23 | 24 | r_packages: 25 | - DBI 26 | 27 | before_script: 28 | - psql -c 'create database testdb;' -U postgres 29 | before_install: 30 | - Rscript -e 'install.packages("DBI");' 31 | 32 | install: 33 | - sh build_check_with_vars.sh 34 | - R CMD INSTALL RPostgreSQL 35 | 36 | script: 37 | - travis_wait 30 time sh check_with_vars.sh 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RPostgreSQL 2 | An R Interface to PostgreSQL. 3 | 4 | Releases go to CRAN at 5 | https://CRAN.R-project.org/package=RPostgreSQL 6 | 7 | Check status of the release in various platforms can be found at 8 | https://cran.r-project.org/web/checks/check_results_RPostgreSQL.html 9 | 10 | Tests automatically run at Travis ci can be found 11 | https://travis-ci.com/tomoakin/RPostgreSQL 12 | -------------------------------------------------------------------------------- /RPostgreSQL/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RPostgreSQL 2 | Version: 0.7-8 3 | Date: 2025-03-28 4 | Title: R Interface to the 'PostgreSQL' Database System 5 | Maintainer: Tomoaki Nishiyama 6 | Description: Database interface and 'PostgreSQL' driver for 'R'. 7 | This package provides a Database Interface 'DBI' compliant 8 | driver for 'R' to access 'PostgreSQL' database systems. 9 | In order to build and install this package from source, 'PostgreSQL' 10 | itself must be present your system to provide 'PostgreSQL' functionality 11 | via its libraries and header files. These files are provided as 12 | 'postgresql-devel' package under some Linux distributions. 13 | On 'macOS' and 'Microsoft Windows' system the attached 'libpq' library source will be used. 14 | LazyLoad: true 15 | Depends: R (>= 3.4.0), methods, DBI (>= 0.3) 16 | License: GPL-3 | file LICENSE 17 | Copyright: Authors listed above, PostgreSQL Global Development Group, 18 | and The Regents of the University of California 19 | Collate: S4R.R zzz.R PostgreSQLSupport.R dbObjectId.R PostgreSQL.R 20 | URL: https://github.com/tomoakin/RPostgreSQL, 21 | https://cran.r-project.org/package=DBI, 22 | https://www.postgresql.org 23 | Authors@R: c(person(given = "Joe", 24 | family = "Conway", 25 | role = "aut"), 26 | person(given = "Dirk", 27 | family = "Eddelbuettel", 28 | role = "aut"), 29 | person(given = "Tomoaki", 30 | family = "Nishiyama", 31 | role = c("aut", "cre"), 32 | email = "tomoaki@sci.u-toyama.ac.jp"), 33 | person(given = c("Sameer", "Kumar"), 34 | family = "Prayaga", 35 | role = "aut", 36 | comment = "during 2008"), 37 | person(given = "Neil", 38 | family = "Tiffin", 39 | role = "aut")) 40 | NeedsCompilation: yes 41 | Packaged: 2025-03-28 01:35:52 UTC; tomoaki 42 | Author: Joe Conway [aut], 43 | Dirk Eddelbuettel [aut], 44 | Tomoaki Nishiyama [aut, cre], 45 | Sameer Kumar Prayaga [aut] (during 2008), 46 | Neil Tiffin [aut] 47 | -------------------------------------------------------------------------------- /RPostgreSQL/LICENSE: -------------------------------------------------------------------------------- 1 | This package as a whole is distributed under GPL-3 (GNU GENERAL PUBLIC LICENSE 2 | version 3). See the file COPYING in the top level of the R directory 3 | tree for further details. 4 | 5 | The files under src/libpq/ and libpq.dll are distributed under the 6 | PostgreSQL License (see below). That is, if you take only that part out of the 7 | package you may redistribute only under the restriction of 8 | PostgreSQL License. 9 | Most of this package are distributed under GPL-2|GPL-3. 10 | But now that, new versions of config.guess and config.sub are under GPL-3, 11 | the whole should be handled as GPL-3. 12 | 13 | PostgreSQL License: 14 | PostgreSQL Database Management System 15 | (formerly known as Postgres, then as Postgres95) 16 | 17 | Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group 18 | 19 | Portions Copyright (c) 1994, The Regents of the University of California 20 | 21 | Permission to use, copy, modify, and distribute this software and its 22 | documentation for any purpose, without fee, and without a written agreement 23 | is hereby granted, provided that the above copyright notice and this 24 | paragraph and the following two paragraphs appear in all copies. 25 | 26 | IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 27 | DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 28 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 29 | DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | 32 | THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 33 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 34 | AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 35 | ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO 36 | PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 37 | -------------------------------------------------------------------------------- /RPostgreSQL/NAMESPACE: -------------------------------------------------------------------------------- 1 | 2 | import(methods) 3 | import(DBI) 4 | importFrom("utils", "count.fields", "read.table") 5 | 6 | useDynLib(RPostgreSQL, .registration = TRUE) 7 | 8 | ## Classes 9 | exportClasses( 10 | dbObjectId, 11 | PostgreSQLObject, 12 | PostgreSQLDriver, 13 | PostgreSQLConnection, 14 | PostgreSQLResult 15 | ) 16 | 17 | ## Methods/Generics 18 | exportMethods( 19 | coerce, 20 | dbApply, 21 | dbBegin, 22 | dbCallProc, 23 | dbClearResult, 24 | dbColumnInfo, 25 | dbCommit, 26 | dbConnect, 27 | dbDataType, 28 | dbDisconnect, 29 | # dbEscapeStrings, 30 | dbExistsTable, 31 | dbGetException, 32 | dbGetInfo, 33 | dbGetQuery, 34 | dbGetRowCount, 35 | dbGetRowsAffected, 36 | dbGetStatement, 37 | dbHasCompleted, 38 | dbListConnections, 39 | dbListFields, 40 | dbListResults, 41 | dbListTables, 42 | # dbMoreResults, 43 | # dbNextResult, 44 | dbReadTable, 45 | dbRemoveTable, 46 | dbRollback, 47 | dbSendQuery, 48 | dbUnloadDriver, 49 | dbWriteTable, 50 | fetch, 51 | format, 52 | initialize, 53 | isSQLKeyword, 54 | make.db.names, 55 | show, 56 | SQLKeywords, 57 | summary 58 | ) 59 | 60 | ## regular functions (most of these will be made private) 61 | export( 62 | PostgreSQL, 63 | postgresqlBuildTableDefinition, 64 | isPostgresqlIdCurrent, 65 | # .PostgreSQLKeywords, 66 | postgresqlInitDriver, 67 | postgresqlCloseDriver, 68 | postgresqlDescribeDriver, 69 | postgresqlDriverInfo, 70 | postgresqlNewConnection, 71 | postgresqlCloneConnection, 72 | postgresqlDescribeConnection, 73 | postgresqlConnectionInfo, 74 | postgresqlCloseConnection, 75 | postgresqlExecStatement, 76 | postgresqlpqExec, 77 | postgresqlCopyIn, 78 | postgresqlCopyInDataframe, 79 | postgresqlgetResult, 80 | postgresqlQuickSQL, 81 | postgresqlDBApply, 82 | postgresqlFetch, 83 | postgresqlResultInfo, 84 | postgresqlDescribeResult, 85 | postgresqlDescribeFields, 86 | postgresqlCloseResult, 87 | postgresqlImportFile, 88 | postgresqlReadTable, 89 | postgresqlWriteTable, 90 | postgresqlEscapeStrings, 91 | postgresqlEscapeBytea, 92 | postgresqlUnescapeBytea, 93 | postgresqlDataType, 94 | postgresqlQuoteId, 95 | postgresqlTableRef 96 | ) 97 | 98 | ## constants 99 | #export( 100 | # CLIENT_LONG_PASSWORD, 101 | # CLIENT_FOUND_ROWS, 102 | # CLIENT_LONG_FLAG, 103 | # CLIENT_CONNECT_WITH_DB, 104 | # CLIENT_NO_SCHEMA, 105 | # CLIENT_COMPRESS, 106 | # CLIENT_ODBC, 107 | # CLIENT_LOCAL_FILES, 108 | # CLIENT_IGNORE_SPACE, 109 | # CLIENT_PROTOCOL_41, 110 | # CLIENT_INTERACTIVE, 111 | # CLIENT_SSL, 112 | # CLIENT_IGNORE_SIGPIPE, 113 | # CLIENT_TRANSACTIONS, 114 | # CLIENT_RESERVED, 115 | # CLIENT_SECURE_CONNECTION, 116 | # CLIENT_MULTI_STATEMENTS, 117 | # CLIENT_MULTI_RESULTS 118 | #) 119 | -------------------------------------------------------------------------------- /RPostgreSQL/R/S4R.R: -------------------------------------------------------------------------------- 1 | ## R/S-Plus compatibility 2 | ## $Id$ 3 | 4 | ## This package was developed as a part of Summer of Code program organized by Google. 5 | ## Thanks to David A. James & Saikat DebRoy, the authors of RMySQL package. 6 | ## Code from RMySQL package was reused with the permission from the authors. 7 | ## Also Thanks to my GSoC mentor Dirk Eddelbuettel for helping me in the development. 8 | 9 | 10 | usingR <- function(major=0, minor=0){ 11 | if(is.null(version$language)) 12 | return(FALSE) 13 | if(version$language!="R") 14 | return(FALSE) 15 | version$major>=major && version$minor>=minor 16 | } 17 | 18 | ## constant holding the appropriate error class returned by try() 19 | if(usingR()){ 20 | ErrorClass <- "try-error" 21 | } else { 22 | ErrorClass <- "Error" 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /RPostgreSQL/R/dbObjectId.R: -------------------------------------------------------------------------------- 1 | ## Class: dbObjectId 2 | ## $Id$ 3 | 4 | ## This package was developed as a part of Summer of Code program organized by Google. 5 | ## Thanks to David A. James & Saikat DebRoy, the authors of RMySQL package. 6 | ## Code from RMySQL package was reused with the permission from the authors. 7 | ## Also Thanks to my GSoC mentor Dirk Eddelbuettel for helping me in the development. 8 | 9 | 10 | ## 11 | ## This mixin helper class is NOT part of the database interface definition, 12 | ## but it is extended by the Oracle, MySQL,PostgreSQL and SQLite implementations 13 | ## to allow us to conviniently (and portably) 14 | ## implement all database foreign objects methods (i.e., methods for show(), 15 | ## print() format() the dbManger, dbConnection, dbResultSet, etc.) 16 | ## A dbObjectId is an identifier into an actual remote database objects. 17 | ## This class and its derived classes Object need to 18 | ## be VIRTUAL to avoid coercion (green book, p.293) during method dispatching. 19 | 20 | setClass("dbObjectId", representation(Id = "integer", "VIRTUAL")) 21 | 22 | ## coercion methods 23 | setAs("dbObjectId", "integer", 24 | def = function(from) as(slot(from,"Id"), "integer") 25 | ) 26 | setAs("dbObjectId", "numeric", 27 | def = function(from) as(slot(from, "Id"), "integer") 28 | ) 29 | setAs("dbObjectId", "character", 30 | def = function(from) as(slot(from, "Id"), "character") 31 | ) 32 | 33 | ## formating, showing, printing,... 34 | setMethod("format", "dbObjectId", 35 | def = function(x, ...) { 36 | paste("(", paste(as(x, "integer"), collapse=","), ")", sep="") 37 | }, 38 | valueClass = "character" 39 | ) 40 | 41 | setMethod("show", "dbObjectId", def = function(object) print(object)) 42 | 43 | setMethod("print", "dbObjectId", 44 | def = function(x, ...){ 45 | expired <- if(isPostgresqlIdCurrent(x)) "" else "Expired " 46 | str <- paste("<", expired, class(x), ":", format(x), ">", sep="") 47 | cat(str, "\n") 48 | invisible(NULL) 49 | } 50 | ) 51 | 52 | ## verify that obj refers to a currently open/loaded database 53 | isPostgresqlIdCurrent <- function(obj) { 54 | obj <- as(obj, "integer") 55 | .Call(RS_DBI_validHandle, obj) 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /RPostgreSQL/R/zzz.R: -------------------------------------------------------------------------------- 1 | ## zzz.R 2 | ## $Id$ 3 | 4 | ## This package was developed as a part of Summer of Code program organized by Google. 5 | ## Thanks to David A. James & Saikat DebRoy, the authors of RMySQL package. 6 | ## Code from RMySQL package was reused with the permission from the authors. 7 | ## Also Thanks to my GSoC mentor Dirk Eddelbuettel for helping me in the development. 8 | 9 | .onLoad <- function(lib, pkg) { 10 | library.dynam("RPostgreSQL", pkg, lib) 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RPostgreSQL/cleanup: -------------------------------------------------------------------------------- 1 | rm -f config.log config.status 2 | rm -rf autom4te.cache 3 | rm -rf src/*.o src/*.so src/Makevars 4 | rm -rf .RData typeTest.r.Rout 5 | -------------------------------------------------------------------------------- /RPostgreSQL/configure.win: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomoakin/RPostgreSQL/e8a32401d13549f8b1ffc8bc78ca572891495008/RPostgreSQL/configure.win -------------------------------------------------------------------------------- /RPostgreSQL/inst/ANNOUNCEMENT: -------------------------------------------------------------------------------- 1 | 2 | RPostgreSQL version 0.5 3 | 4 | We are pround to announce the availability of the RPostgreSQL package on CRAN 5 | and its mirrors. This package provides an a DBI-compliant interface between 6 | PostgreSQL and R. 7 | 8 | RPostgreSQL was developed as part of the Google Summer of Code 2008 program 9 | by Sameer Kumar Prayaga . 10 | 11 | Some highlights: 12 | 13 | o Binary data store in PostgreSQL bytea datatype. 14 | 15 | Known bugs/deficiencies: 16 | 17 | o Arrays are not converted vector or other datastructure. 18 | 19 | o Active issue list is at http://code.google.com/p/rpostgresql/issues/list 20 | 21 | RPostgreSQL is hosted on Github https://github.com/tomoakin/RPostgreSQL 22 | 23 | For security issues that should not directly go to public, 24 | you may contact: 25 | 26 | Tomoaki Nishiyama 27 | Neil Tiffin 28 | Joe Conway 29 | Dirk Eddelbuettel 30 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/README: -------------------------------------------------------------------------------- 1 | About the RPostgreSQL package: 2 | 3 | Database Interface between R and PostgreSQL 4 | 5 | For details, see the Adobe PDF file "DBI.pdf" in the doc folder or see the 6 | documentation using help(PostgreSQL). Examples provided in the devTests 7 | folder illustrate some of the functionality. 8 | 9 | ============================================================================= 10 | 11 | Basic usage: 12 | 13 | ## initialize the driver to PostgreSQL 14 | drv <- dbDriver("PostgreSQL") 15 | 16 | ## create a connection to a PostgreSQL server 17 | con <- dbConnect(drv, user="userName", password="123456", 18 | dbname="gsoc", host="10.23.34.23") 19 | 20 | ## run a query, and get the result set as a dataframe 21 | dFrame <- dbGetQuery(con, "select * from someTable LIMIT 50") 22 | 23 | ## run a query, leave results in the library* 24 | ## note current implementation does not leave the result in the Server 25 | ## and there is no benefit using dbSendQuery() fetch() pair other than 26 | ## compatibility. 27 | rs <- dbSendQuery(con, "select * from someTable") 28 | 29 | ## fetch up to, say, 50 records 30 | dFrame <- fetch(rs, n = 50) 31 | 32 | ## close resultSet rs 33 | dbClearResult(rs) 34 | 35 | ## close connection con 36 | dbDisconnect(con) 37 | 38 | ## Unload the driver drv 39 | dbUnloadDriver(drv) 40 | 41 | For a more complete example, refer to the file demo.r in the devTests folder. 42 | 43 | ============================================================================= 44 | 45 | Important Information: 46 | 47 | 1. The present version of RPostgreSQL can handle only one resultset per connection. 48 | Thus dbSendQuery/fetch usually do not have speed merit over dbGetQuery. 49 | 50 | ============================================================================= 51 | 52 | Frequently Asked Questions (FAQ): 53 | 54 | 1. What is Database Interface(DBI) ? 55 | 56 | The Data Base Interface (DBI) provides a layer of abstraction between R 57 | and relational databases. All the classes in the DBI package are virtual 58 | and need to be implemented using the various DBMS libraries. The vendor 59 | has written some functions for communicating with the database in some 60 | language like C, compiled the functions and the compiled code is the 61 | library. We write a C program that calls the functions in the library, 62 | when it wants to access the database. Every database library is 63 | different. The names of the functions vary, and the order in 64 | which you call them varies, and the details of passing queries to the 65 | functions and getting the data back out will vary. To manage this, DBI 66 | was extended for individual database back-ends MySQL, SQLite, Oracle, 67 | PostgreSQL via R packages ROracle, RMySQL, RSQLite and RPostgreSQL. 68 | DBI for R-language was initially developed at Bell Labs by David James. 69 | 70 | 2. What is RPostgreSQL ? 71 | 72 | The RPostgreSQL package provides a glue between the PostgreSQL database 73 | and the DBI of R. The C programming interface called libpq was used for 74 | communicating with PostgreSQL. 75 | 76 | 3 What is libpq ? 77 | 78 | libpq is the C application programmer’s interface to PostgreSQL. libpq is 79 | a cross platform library providing set of library functions that allow 80 | client programs to pass queries to the PostgreSQL backend server and to 81 | receive the results of these queries. 82 | 83 | 4. What about Rdbi/RdbiPgSQL ? 84 | 85 | Rdbi and RdbiPgSQL are a 'fork' of the DBI interface for R. RPostgreSQL follows 86 | the DBI as do ROracle, RMySQL and RSQLite. 87 | 88 | 89 | For any queries,suggestions and comments, mail: 90 | 91 | rpostgresql-dev@googlegroups.com 92 | 93 | For security issues that should not directly go to public, 94 | you may contact: 95 | 96 | Tomoaki Nishiyama 97 | Neil Tiffin 98 | Joe Conway 99 | Dirk Eddelbuettel 100 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/THANKS: -------------------------------------------------------------------------------- 1 | 2 | Thanks to my mentor Dr. Dirk Eddelbuettel for giving the oppurtunity to 3 | participate in Google Summer of Code 2008 and guiding me with his unending 4 | patience and knowledge. 5 | 6 | Also thanks to Google corporation for their wonderful program to bring 7 | students and open source organizations together. 8 | 9 | Many thanks to David James for allowing me to reuse code whereever required 10 | from the RMySQL package. 11 | 12 | Also special thanks to Paul and Seth for giving valuable suggestions. 13 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/TODO: -------------------------------------------------------------------------------- 1 | Things yet to be completed: 2 | 3 | 1. Array and other complex structures are not converted properly: 4 | just the strings are transmitted. Datatype conversion callback 5 | table for supporting complex data types are desired. 6 | 7 | 2. Add commands for prepared statements. 8 | This is partly done. But not thoroughly tested yet. 9 | 10 | 3. More explicit encoding support. 11 | 12 | 4. 'Scale' is not calculated in dbGetInfo(result_set) 13 | Try to write an SQL query to get the value or hardcode 14 | the appropriate details in the code.For more details 15 | refer to : "RS_PostgreSQL_createDataMappings". 16 | 17 | 5. Check the working of DBI extension "dbApply". 18 | 19 | 6. Binary data transfer to store IEEE754 floating point data without loss of precision. 20 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/devTests/PostgreSQLDataTypeTest.r: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env r 2 | 3 | ## Create a database 4 | tempdb <- "tempdbase" 5 | system(paste("createdb", tempdb)) 6 | 7 | library(RPostgreSQL) 8 | drv <- dbDriver("PostgreSQL") 9 | con <- dbConnect(drv, dbname=tempdb) 10 | 11 | 12 | 13 | ## Test the numeric mapping 14 | dbSendQuery(con, "create table testnumeric (intcolumn integer, floatcolumn float);") 15 | 16 | i <- as.integer(10) 17 | j <- as.numeric(56.6) 18 | 19 | sql <- paste("insert into testnumeric ", 20 | "values (",i, "," ,j ,") ", sep="") 21 | res <- dbSendQuery(con, sql) 22 | 23 | 24 | dat <- dbReadTable(con, "testnumeric") 25 | cat("Read Numeric values\n") 26 | 27 | ## now test the types of the colums we got 28 | stopifnot( class(dat[,1]) == "integer" ) 29 | stopifnot( class(dat[,2]) == "numeric" ) 30 | cat("GOOD -- all numeric types are as expected\n") 31 | 32 | ## and test the values 33 | stopifnot( identical( dat[1,1], i)) 34 | stopifnot( identical( dat[1,2], j)) 35 | cat("GOOD -- all numeric values are as expected\n") 36 | 37 | 38 | 39 | 40 | ## Test the logical mapping 41 | dbSendQuery(con,"create table testlogical (col1 boolean, col2 boolean)") 42 | 43 | i <- as.logical(TRUE) 44 | j <- as.logical(FALSE) 45 | 46 | sql <- paste("insert into testlogical ", 47 | "values (",i, "," ,j ,") ", sep="") 48 | res <- dbSendQuery(con, sql); 49 | 50 | dat <- dbReadTable(con, "testlogical") 51 | cat("Read Logical values\n") 52 | 53 | ## now test the types of the colums we got 54 | stopifnot( class(dat[,1]) == "logical" ) 55 | stopifnot( class(dat[,2]) == "logical" ) 56 | cat("GOOD -- all logical types are as expected\n") 57 | 58 | ## and test the values 59 | stopifnot( identical( dat[1,1], i)) 60 | stopifnot( identical( dat[1,2], j)) 61 | cat("GOOD -- all logical values are as expected\n") 62 | 63 | 64 | 65 | 66 | ## Test the character mapping 67 | dbSendQuery(con,"create table testchar (code char(3),city varchar(20),country text);") 68 | 69 | i <- as.character("IN") 70 | j <- as.character("Hyderabad") 71 | k <- as.character("India") 72 | 73 | 74 | sql <- paste("insert into testchar ", 75 | "values ('",i,"' , '",j ,"' , '",k,"') ", sep="") 76 | res <- dbSendQuery(con, sql); 77 | 78 | dat <- dbReadTable(con, "testchar") 79 | cat("Read Character values\n") 80 | 81 | ## now test the types of the colums we got 82 | stopifnot( class(dat[,1]) == "character" ) 83 | stopifnot( class(dat[,2]) == "character" ) 84 | stopifnot( class(dat[,3]) == "character" ) 85 | cat("GOOD -- all character types are as expected\n") 86 | 87 | 88 | ## and test the values 89 | ##stopifnot( identical( dat[1,1], i)) 90 | stopifnot( identical( dat[1,2], j)) 91 | stopifnot( identical( dat[1,3], k)) 92 | cat("GOOD -- all character values are as expected\n") 93 | 94 | 95 | dbDisconnect(con) 96 | dbUnloadDriver(drv) 97 | 98 | system(paste("dropdb", tempdb)) 99 | 100 | cat("DONE\n") 101 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/devTests/copyTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | dbname="pgtemp" 6 | 7 | createdb ${dbname} 8 | echo "Created ${dbname}" 9 | 10 | cat </dev/null")) 28 | system("psql beancounter -c \"insert into timetest values( \'now\' )\" >/dev/null") 29 | } 30 | 31 | removeTempTable <- function() { 32 | system("psql beancounter -c \"drop table timetest\" >/dev/null") 33 | } 34 | 35 | testTimeData("date") 36 | testTimeData("timestamp with time zone") 37 | testTimeData("timestamp without time zone") 38 | testTimeData("time with time zone") 39 | testTimeData("time without time zone") 40 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/devTests/transactionManagement.r: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env r 2 | 3 | cat("Testing the working of Transaction Management\n") 4 | 5 | ## Create a database 6 | tempdb <- "tempdbase123" 7 | system(paste("createdb", tempdb)) 8 | 9 | library(RPostgreSQL) 10 | drv <- dbDriver("PostgreSQL") 11 | con <- dbConnect(drv, dbname=tempdb) 12 | 13 | ## Test the numeric mapping 14 | dbSendQuery(con, "create table book123list (intcolumn integer, floatcolumn float);") 15 | 16 | ## insert four rows into the table 17 | dbSendQuery(con, "insert into book123list values(12,13.21);") 18 | dbSendQuery(con, "insert into book123list values(50,11.21);") 19 | dbSendQuery(con, "insert into book123list values(100,200.1);") 20 | dbSendQuery(con, "insert into book123list values(5,3.56);") 21 | 22 | cat("Table book123list contains the following records\n") 23 | dbGetQuery(con, "select * from book123list") 24 | 25 | cat("Test Run 1:\n") 26 | 27 | dbBeginTransaction(con); 28 | cat("Begin Transaction\n") 29 | rs <- dbSendQuery(con, "DELETE from book123list WHERE intcolumn >= 50"); 30 | dbClearResult(rs); 31 | cat("After Deletion\n"); 32 | dbGetQuery(con, "select * from book123list") 33 | dbRollback(con) 34 | cat("After Rolling back\n") 35 | 36 | cat("Table book123list contains the following records\n") 37 | dbGetQuery(con, "select * from book123list") 38 | 39 | cat("Test Run 2:\n") 40 | 41 | dbBeginTransaction(con); 42 | cat("Begin Transaction\n") 43 | dbGetQuery(con, "select * from book123list")[1, ]; 44 | rs <- dbSendQuery(con, "DELETE from book123list WHERE intcolumn >= 50"); 45 | dbClearResult(rs); 46 | cat("After Deletion\n"); 47 | dbGetQuery(con, "select * from book123list") 48 | dbCommit(con); 49 | cat("After commiting the transaction\n") 50 | dbGetQuery(con, "select * from book123list") 51 | 52 | dbDisconnect(con) 53 | dbUnloadDriver(drv) 54 | 55 | system(paste("dropdb", tempdb)) 56 | 57 | cat("DONE\n") 58 | -------------------------------------------------------------------------------- /RPostgreSQL/inst/devTests/typeTest.r: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env r 2 | 3 | usePG <- TRUE 4 | 5 | if (usePG) { 6 | cat("Using Pg\n") 7 | tempdb <- "pgdatetime" 8 | system(paste("createdb", tempdb)) # create a temp database 9 | 10 | suppressMessages(library(RPostgreSQL)) 11 | drv <- dbDriver("PostgreSQL") 12 | con <- dbConnect(drv, dbname=tempdb) 13 | 14 | } else { 15 | cat("Using SQLite\n") 16 | tempdb <- "/tmp/tempdb.sqlite" # assumed to not exist 17 | suppressMessages(library(RSQLite)) 18 | drv <- dbDriver("SQLite") 19 | if (file.exists(tempdb)) 20 | unlink(tempdb) 21 | con <- dbConnect(drv, tempdb) 22 | } 23 | 24 | 25 | sql <- "create table foo (i integer, r real, t text)" 26 | res <- dbSendQuery(con, sql) 27 | cat("Created table\n") 28 | 29 | i <- as.integer(11) 30 | r <- as.numeric(22.22) 31 | txt <- as.character("blim blom") 32 | 33 | sql <- paste("insert into foo ", 34 | "values (", 35 | i, ",", 36 | r, ", '", 37 | txt, "') ", sep="") 38 | res <- dbSendQuery(con, sql) 39 | cat("Wrote values\n") 40 | 41 | df <- dbReadTable(con, "foo") 42 | cat("Read values\n") 43 | 44 | ## now test the types of the colums we got 45 | stopifnot( class(df[,1]) == "integer" ) 46 | stopifnot( class(df[,2]) == "numeric" ) 47 | stopifnot( class(df[,3]) == "character" ) 48 | cat("GOOD -- all types are as expected\n") 49 | 50 | ## and test the values 51 | stopifnot( identical( df[1,1], i)) 52 | stopifnot( identical( df[1,2], r)) 53 | stopifnot( identical( df[1,3], txt)) 54 | cat("GOOD -- all values are as expected\n") 55 | 56 | if (usePG) { 57 | dbDisconnect(con) 58 | dbUnloadDriver(drv) 59 | system(paste("dropdb", tempdb)) 60 | } else { 61 | dbDisconnect(con) 62 | dbUnloadDriver(drv) 63 | unlink(tempdb) 64 | } 65 | 66 | cat("DONE\n") 67 | -------------------------------------------------------------------------------- /RPostgreSQL/man/PostgreSQL.Rd: -------------------------------------------------------------------------------- 1 | % $Id: PostgreSQL.Rd,v 0.1 2008/07/23 03:07:31 psk Exp $ 2 | \name{PostgreSQL} 3 | \alias{PostgreSQL} 4 | \title{ 5 | Instantiate a PostgreSQL client from the current R or S-Plus session 6 | } 7 | \description{ 8 | This function creates and initializes a PostgreSQL client. 9 | It returns an driver object that allows you to connect 10 | to one or several PostgreSQL servers. 11 | } 12 | \usage{ 13 | PostgreSQL(max.con = 16, fetch.default.rec = 500, force.reload = FALSE) 14 | } 15 | \arguments{ 16 | \item{max.con }{ 17 | Maximum number of connections that are intended to have open at one time. 18 | There's no intrinic limit, since strictly speaking this limit applies 19 | to PostgreSQL \emph{servers}, but clients can have (at least in theory) 20 | more than this. Typically there are at most a handful of open connections, 21 | thus the internal \code{RPostgreSQL} code uses a very simple linear search 22 | algorithm to manage its connection table. 23 | } 24 | \item{fetch.default.rec}{ 25 | number of records to fetch at one time from the database. 26 | (The \code{\link[DBI]{fetch}} method uses this number as a default.) 27 | } 28 | \item{force.reload}{ 29 | should the client code be reloaded (reinitialize)? 30 | Setting this to \code{TRUE} allows you to change 31 | default settings. Notice that all connections should be closed 32 | before re-loading. 33 | } 34 | } 35 | \value{ 36 | An object \code{PostgreSQLDriver} that extends 37 | \code{dbDriver} and 38 | \code{dbObjectId}. 39 | This object is required to create connections 40 | to one or several PostgreSQL database engines. 41 | } 42 | \section{Side Effects}{ 43 | The R/S-Plus client part of the database communication is initialized, 44 | but note that connecting to the database engine needs to be done through 45 | calls to \code{\link[DBI]{dbConnect}}. 46 | } 47 | \details{ 48 | This object is a singleton, that is, on subsequent invocations 49 | it returns the same initialized object. 50 | 51 | This implementation allows you to connect 52 | to multiple host servers and run multiple connections on each server 53 | simultaneously. 54 | } 55 | \section{User authentication}{ 56 | The passed string can be empty to use all default parameters, or it can 57 | contain one or more parameter settings separated by comma. Each 58 | parameter setting is in the form parameter = "value". Spaces around the 59 | equal sign are optional. 60 | 61 | The most important parameters are \code{user}, \code{password}, 62 | \code{host}, \code{dbname}, \code{port}, \code{tty} and \code{options}. 63 | } 64 | \author{David A. James} 65 | \section{References}{ 66 | See \url{https://cran.r-project.org/package=DBI} 67 | for more details on the R/S-Plus database interface. 68 | 69 | See the documentation at the PostgreSQL Web site 70 | \url{https://www.postgresql.org} for details. 71 | } 72 | \seealso{ 73 | On database managers: 74 | 75 | \code{\link[DBI]{dbDriver}} 76 | \code{\link[DBI]{dbUnloadDriver}} 77 | 78 | On connections, SQL statements and resultSets: 79 | 80 | \code{\link[DBI]{dbConnect}} 81 | \code{\link[DBI]{dbDisconnect}} 82 | \code{\link[DBI]{dbSendQuery}} 83 | \code{\link[DBI]{dbGetQuery}} 84 | \code{\link[DBI]{fetch}} 85 | \code{\link[DBI]{dbClearResult}} 86 | 87 | On transaction management: 88 | 89 | \code{\link[DBI]{dbCommit}} 90 | \code{\link[DBI]{dbRollback}} 91 | 92 | On meta-data: 93 | 94 | \code{\link{summary}} 95 | \code{\link[DBI]{dbGetInfo}} 96 | \code{\link[DBI]{dbGetDBIVersion}} 97 | \code{\link[DBI]{dbListTables}} 98 | \code{\link[DBI]{dbListConnections}} 99 | \code{\link[DBI]{dbListResults}} 100 | \code{\link[DBI]{dbColumnInfo}} 101 | \code{\link[DBI]{dbGetException}} 102 | \code{\link[DBI]{dbGetStatement}} 103 | \code{\link[DBI]{dbHasCompleted}} 104 | \code{\link[DBI]{dbGetRowCount}} 105 | \code{\link[DBI]{dbGetRowsAffected}} 106 | } 107 | \examples{\dontrun{ 108 | # create a PostgreSQL instance and create one connection. 109 | > m <- dbDriver("PostgreSQL") 110 | 111 | 112 | > con <- dbConnect(m, user="username", password="passwd", dbname="database_name") 113 | > rs <- dbSendQuery(con, "select * sales where price < 10") 114 | > df <- fetch(rs, n = 50) 115 | > dbHasCompleted(rs) 116 | [1] FALSE 117 | > df2 <- fetch(rs, n = -1) 118 | > dbHasCompleted(rs) 119 | [1] TRUE 120 | > dbClearResult(rs) 121 | > dbListTables(con) 122 | } 123 | } 124 | \keyword{interface} 125 | \keyword{database} 126 | % vim: syntax=tex 127 | -------------------------------------------------------------------------------- /RPostgreSQL/man/PostgreSQLConnection-class.Rd: -------------------------------------------------------------------------------- 1 | % $Id: PostgreSQLConnection-class.Rd,v 0.1 2008/07/23 03:14:11 psk Exp $ 2 | \name{PostgreSQLConnection-class} 3 | \docType{class} 4 | \alias{PostgreSQLConnection-class} 5 | \title{Class PostgreSQLConnection} 6 | \description{PostgreSQLConnection class.} 7 | \section{Generators}{ 8 | The method \code{\link[DBI]{dbConnect}} is the main generator. 9 | } 10 | \section{Extends}{ 11 | Class \code{"DBIConnection"}, directly. 12 | Class \code{"PostgreSQLObject"}, directly. 13 | Class \code{"DBIObject"}, by class "DBIConnection". 14 | Class \code{"dbObjectId"}, by class "PostgreSQLObject". 15 | } 16 | \section{Methods}{ 17 | \describe{ 18 | \item{\link{coerce}}{\code{signature(from = "PostgreSQLConnection", to = "PostgreSQLResult")}: ... } 19 | \item{\link[DBI]{dbBegin}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 20 | \item{\link[DBI]{dbCallProc}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 21 | \item{\link[DBI]{dbCommit}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 22 | \item{\link[DBI]{dbConnect}}{\code{signature(drv = "PostgreSQLConnection")}: ... } 23 | \item{\link[DBI]{dbDisconnect}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 24 | \item{\link[DBI]{dbExistsTable}}{\code{signature(conn = "PostgreSQLConnection", name = "character")}: ... } 25 | \item{\link[DBI]{dbGetException}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 26 | \item{\link[DBI]{dbGetInfo}}{\code{signature(dbObj = "PostgreSQLConnection")}: ... } 27 | \item{\link[DBI]{dbGetQuery}}{\code{signature(conn = "PostgreSQLConnection", statement = "character")}: ... } 28 | \item{\link[DBI]{dbListFields}}{\code{signature(conn = "PostgreSQLConnection", name = "character")}: ... } 29 | \item{\link[DBI]{dbListResults}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 30 | \item{\link[DBI]{dbListTables}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 31 | \item{\link[DBI]{dbReadTable}}{\code{signature(conn = "PostgreSQLConnection", name = "character")}: ... } 32 | \item{\link[DBI]{dbRemoveTable}}{\code{signature(conn = "PostgreSQLConnection", name = "character")}: ... } 33 | \item{\link[DBI]{dbRollback}}{\code{signature(conn = "PostgreSQLConnection")}: ... } 34 | \item{\link[DBI]{dbSendQuery}}{\code{signature(conn = "PostgreSQLConnection", statement = "character")}: ... } 35 | \item{\link[DBI]{dbWriteTable}}{\code{signature(conn = "PostgreSQLConnection", name = "character", value = "data.frame")}: ... } 36 | \item{summary}{\code{signature(object = "PostgreSQLConnection")}: ... } 37 | } 38 | } 39 | \references{ 40 | See the Database Interface definition document 41 | \code{DBI.pdf} in the base directory of this package 42 | or \url{https://developer.r-project.org/db/}. 43 | } 44 | 45 | \seealso{ 46 | DBI base classes: 47 | 48 | \code{\link[DBI]{DBIObject-class}} 49 | \code{\link[DBI]{DBIDriver-class}} 50 | \code{\link[DBI]{DBIConnection-class}} 51 | \code{\link[DBI]{DBIResult-class}} 52 | 53 | PostgreSQL classes: 54 | 55 | \code{\link{PostgreSQLObject-class}} 56 | \code{\link{PostgreSQLDriver-class}} 57 | \code{\link{PostgreSQLConnection-class}} 58 | \code{\link{PostgreSQLResult-class}} 59 | 60 | } 61 | 62 | \examples{\dontrun{ 63 | drv <- dbDriver("PostgreSQL) 64 | con <- dbConnect(drv, dbname = "template1") 65 | } 66 | } 67 | \keyword{database} 68 | \keyword{interface} 69 | \keyword{classes} 70 | % vim: syntax=tex 71 | -------------------------------------------------------------------------------- /RPostgreSQL/man/PostgreSQLDriver-class.Rd: -------------------------------------------------------------------------------- 1 | % $Id: PostgreSQLDriver-class.Rd,v 0.1 2008/07/22 20:56:01 psk Exp $ 2 | \name{PostgreSQLDriver-class} 3 | \docType{class} 4 | \alias{PostgreSQLDriver-class} 5 | \title{Class PostgreSQLDriver} 6 | \description{ 7 | An PostgreSQL driver implementing the R/S-Plus database (DBI) API. 8 | } 9 | \section{Generators}{ 10 | The main generators are \code{\link[DBI]{dbDriver}} and 11 | \code{\link{PostgreSQL}}. 12 | } 13 | \section{Extends}{ 14 | Class \code{"DBIDriver"}, directly. 15 | Class \code{"PostgreSQLObject"}, directly. 16 | Class \code{"DBIObject"}, by class "DBIDriver". 17 | Class \code{"dbObjectId"}, by class "PostgreSQLObject". 18 | } 19 | \section{Methods}{ 20 | \describe{ 21 | \item{\link{coerce}}{\code{signature(from = "PostgreSQLObject", to = "PostgreSQLDriver")}: ... } 22 | \item{\link[DBI]{dbConnect}}{\code{signature(drv = "PostgreSQLDriver")}: ... } 23 | \item{\link[DBI]{dbGetInfo}}{\code{signature(dbObj = "PostgreSQLDriver")}: ... } 24 | \item{\link[DBI]{dbListConnections}}{\code{signature(drv = "PostgreSQLDriver")}: ... } 25 | \item{\link[DBI]{dbUnloadDriver}}{\code{signature(drv = "PostgreSQLDriver")}: ... } 26 | \item{\link{summary}}{\code{signature(object = "PostgreSQLDriver")}: ... } 27 | } 28 | } 29 | \references{ 30 | See the Database Interface definition document 31 | \code{DBI.pdf} in the base directory of this package 32 | or \url{https://developer.r-project.org/db/}. 33 | } 34 | 35 | \seealso{ 36 | DBI base classes: 37 | 38 | \code{\link[DBI]{DBIObject-class}} 39 | \code{\link[DBI]{DBIDriver-class}} 40 | \code{\link[DBI]{DBIConnection-class}} 41 | \code{\link[DBI]{DBIResult-class}} 42 | 43 | PostgreSQL classes: 44 | 45 | \code{\link{PostgreSQLObject-class}} 46 | \code{\link{PostgreSQLDriver-class}} 47 | \code{\link{PostgreSQLConnection-class}} 48 | \code{\link{PostgreSQLResult-class}} 49 | } 50 | 51 | \examples{\dontrun{ 52 | drv <- dbDriver("PostgreSQL") 53 | con <- dbConnect(drv, dbname="template1") 54 | } 55 | } 56 | \keyword{database} 57 | \keyword{interface} 58 | \keyword{classes} 59 | % vim: syntax=tex 60 | -------------------------------------------------------------------------------- /RPostgreSQL/man/PostgreSQLObject-class.Rd: -------------------------------------------------------------------------------- 1 | % $Id: PostgreSQLObject-class.Rd,v 0.1 2008/07/22 20:56:01 psk Exp $ 2 | \name{PostgreSQLObject-class} 3 | \docType{class} 4 | \alias{PostgreSQLObject-class} 5 | \title{Class PostgreSQLObject} 6 | \description{ 7 | Base class for all PostgreSQL-specific DBI classes 8 | } 9 | \section{Objects from the Class}{ 10 | A virtual Class: No objects may be created from it. 11 | } 12 | \section{Extends}{ 13 | Class \code{"DBIObject"}, directly. 14 | Class \code{"dbObjectId"}, directly. 15 | } 16 | \section{Methods}{ 17 | \describe{ 18 | \item{\link{coerce}}{\code{signature(from = "PostgreSQLObject", to = "PostgreSQLriver")}: ... } 19 | \item{\link[DBI]{dbDataType}}{\code{signature(dbObj = "PostgreSQLObject")}: ... } 20 | \item{\link[DBI]{isSQLKeyword}}{\code{signature(dbObj = "PostgreSQLObject", name = "character")}: ... } 21 | \item{\link[DBI]{make.db.names}}{\code{signature(dbObj = "PostgreSQLObject", snames = "character")}: ... } 22 | \item{\link[DBI]{SQLKeywords}}{\code{signature(dbObj = "PostgreSQLObject")}: ... } 23 | } 24 | } 25 | \references{ 26 | See the Database Interface definition document 27 | \code{DBI.pdf} in the base directory of this package 28 | or \url{https://developer.r-project.org/db/}. 29 | } 30 | 31 | \seealso{ 32 | DBI base classes: 33 | 34 | \code{\link[DBI]{DBIObject-class}} 35 | \code{\link[DBI]{DBIDriver-class}} 36 | \code{\link[DBI]{DBIConnection-class}} 37 | \code{\link[DBI]{DBIResult-class}} 38 | 39 | PostgreSQL classes: 40 | 41 | \code{\link{PostgreSQLObject-class}} 42 | \code{\link{PostgreSQLDriver-class}} 43 | \code{\link{PostgreSQLConnection-class}} 44 | \code{\link{PostgreSQLResult-class}} 45 | 46 | } 47 | 48 | \examples{\dontrun{ 49 | drv <- dbDriver("PostgreSQL") 50 | con <- dbConnect(drv, dbname = "template1") 51 | } 52 | } 53 | \keyword{database} 54 | \keyword{interface} 55 | \keyword{classes} 56 | % vim: syntax=tex 57 | -------------------------------------------------------------------------------- /RPostgreSQL/man/PostgreSQLResult-class.Rd: -------------------------------------------------------------------------------- 1 | % $Id: PostgreSQLResult-class.Rd,v 0.1 2008/07/22 20:56:01 psk Exp $ 2 | \name{PostgreSQLResult-class} 3 | \docType{class} 4 | \alias{PostgreSQLResult-class} 5 | \title{Class PostgreSQLResult} 6 | \description{ 7 | PostgreSQL's query results class. This classes encapsulates the 8 | result of an SQL statement (either \code{select} or not). 9 | } 10 | \section{Generators}{ 11 | The main generator is \code{\link[DBI]{dbSendQuery}}. 12 | } 13 | \section{Extends}{ 14 | Class \code{"DBIResult"}, directly. 15 | Class \code{"PostgreSQLObject"}, directly. 16 | Class \code{"DBIObject"}, by class "DBIResult". 17 | Class \code{"dbObjectId"}, by class "PostgreSQLObject". 18 | } 19 | \section{Methods}{ 20 | \describe{ 21 | \item{\link{coerce}}{\code{signature(from = "PostgreSQLConnection", to = "PostgreSQLResult")}: ... } 22 | \item{\link[DBI]{dbClearResult}}{\code{signature(res = "PostgreSQLResult")}: ... } 23 | \item{\link[DBI]{dbColumnInfo}}{\code{signature(res = "PostgreSQLResult")}: ... } 24 | \item{\link[DBI]{dbGetException}}{\code{signature(conn = "PostgreSQLResult")}: ... } 25 | \item{\link[DBI]{dbGetInfo}}{\code{signature(dbObj = "PostgreSQLResult")}: ... } 26 | \item{\link[DBI]{dbGetRowCount}}{\code{signature(res = "PostgreSQLResult")}: ... } 27 | \item{\link[DBI]{dbGetRowsAffected}}{\code{signature(res = "PostgreSQLResult")}: ... } 28 | \item{\link[DBI]{dbGetStatement}}{\code{signature(res = "PostgreSQLResult")}: ... } 29 | \item{\link[DBI]{dbHasCompleted}}{\code{signature(res = "PostgreSQLResult")}: ... } 30 | \item{\link[DBI]{dbListFields}}{\code{signature(conn = "PostgreSQLResult", name = "missing")}: ... } 31 | \item{\link[DBI]{fetch}}{\code{signature(res = "PostgreSQLResult", n = "numeric")}: ... } 32 | \item{\link[DBI]{fetch}}{\code{signature(res = "PostgreSQLResult", n = "missing")}: ... } 33 | \item{\link{summary}}{\code{signature(object = "PostgreSQLResult")}: ... } 34 | } 35 | } 36 | \references{ 37 | See the Database Interface definition document 38 | \code{DBI.pdf} in the base directory of this package 39 | or \url{https://developer.r-project.org/db/} 40 | } 41 | 42 | \seealso{ 43 | DBI base classes: 44 | 45 | \code{\link[DBI]{DBIObject-class}} 46 | \code{\link[DBI]{DBIDriver-class}} 47 | \code{\link[DBI]{DBIConnection-class}} 48 | \code{\link[DBI]{DBIResult-class}} 49 | 50 | PostgreSQL classes: 51 | 52 | \code{\link{PostgreSQLObject-class}} 53 | \code{\link{PostgreSQLDriver-class}} 54 | \code{\link{PostgreSQLConnection-class}} 55 | \code{\link{PostgreSQLResult-class}} 56 | 57 | } 58 | 59 | \examples{\dontrun{ 60 | drv <- dbDriver("PostgreSQL") 61 | con <- dbConnect(drv, dbname = "template1") 62 | ## rs is the result set 63 | rs <- dbSendQuery(con,"select * from sales") 64 | ## display the first three values of result set 65 | fetch(rs,n=3) 66 | } 67 | } 68 | \keyword{database} 69 | \keyword{interface} 70 | \keyword{classes} 71 | % vim: syntax=tex 72 | -------------------------------------------------------------------------------- /RPostgreSQL/man/S4R.Rd: -------------------------------------------------------------------------------- 1 | % $Id: S4R.Rd,v 0.1 2008/07/22 20:56:01 psk Exp $ 2 | \name{S4R} 3 | \alias{ErrorClass} 4 | \alias{usingR} 5 | 6 | \title{R compatibility with S version 4/Splus5+ support functions} 7 | \description{ 8 | These objects ease the task of porting functions into R 9 | from S Version 4 and S-Plus 5.0 and later. See the documentation 10 | there. May be obsolete in the future. 11 | } 12 | \usage{ 13 | usingR(major, minor) 14 | } 15 | \examples{\dontrun{ 16 | rc <- try(fetch(res, n = -1)) 17 | if(inherit(rc, ErrorClass)) 18 | stop("could not fetch the data") 19 | } 20 | } 21 | \keyword{internal} 22 | % vim:syntax=tex 23 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbApply-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbApply-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbApply-methods} 3 | \docType{methods} 4 | \alias{dbApply-methods} 5 | \alias{dbApply,PostgreSQLResult-method} 6 | \title{Apply R/S-Plus functions to remote groups of DBMS rows (experimental)} 7 | \description{ 8 | Applies R/S-Plus functions to groups of remote DBMS rows without 9 | bringing an entire result set all at once. The result set 10 | is expected to be sorted by the grouping field. 11 | } 12 | \section{Methods}{\describe{ 13 | \item{res}{a PostgreSQL result set (see \code{\link[DBI]{dbSendQuery}}).} 14 | \item{...}{any additional arguments to be passed to \code{FUN}.} 15 | } 16 | } 17 | \references{ 18 | See the Database Interface definition document 19 | \code{DBI.pdf} in the base directory of this package 20 | or 21 | \url{https://cran.r-project.org/package=DBI}. 22 | } 23 | \seealso{ 24 | \code{\link{PostgreSQL}} 25 | \code{\link{postgresqlDBApply}} 26 | \code{\link[DBI]{dbSendQuery}} 27 | \code{\link[DBI]{fetch}} 28 | } 29 | 30 | \examples{\dontrun{ 31 | ## compute quanitiles for each network agent 32 | con <- dbConnect(PostgreSQL(), user="user", password="passwd",dbname="dbname") 33 | rs <- dbSendQuery(con, 34 | "select Agent, ip_addr, DATA from pseudo_data order by Agent") 35 | out <- dbApply(rs, INDEX = "Agent", 36 | FUN = function(x, grp) quantile(x$DATA, names=FALSE)) 37 | } 38 | } 39 | \keyword{programming} 40 | \keyword{interface} 41 | \keyword{database} 42 | % vim: syntax=tex 43 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbApply.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbApply.Rd,v d0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbApply} 3 | \alias{dbApply} 4 | \title{Apply R/S-Plus functions to remote groups of DBMS rows (experimental)} 5 | \description{ 6 | Applies R/S-Plus functions to groups of remote DBMS rows without 7 | bringing an entire result set all at once. The result set 8 | is expected to be sorted by the grouping field. 9 | } 10 | %\usage{ 11 | %dbApply(res, ...) 12 | %} 13 | %\arguments{ 14 | % \item{res}{a result set (see \code{\link[DBI]{dbSendQuery}}).} 15 | % \item{...}{any additional arguments to be passed to \code{FUN}.} 16 | %} 17 | \details{ 18 | \code{dbApply} 19 | This generic is meant to handle somewhat gracefully(?) large amounts 20 | of data from the DBMS by bringing into R manageable chunks; 21 | the idea is that the data from individual groups can be handled by R, but 22 | not all the groups at the same time. 23 | 24 | Currently, only the \code{\link{PostgreSQL}} driver implements a method 25 | (see the helper function \code{\link{postgresqlDBApply}}) for this 26 | generic function. 27 | } 28 | \value{ 29 | A list with as many elements as there were groups in the 30 | result set. 31 | } 32 | 33 | \seealso{ 34 | \code{\link{PostgreSQL}} 35 | \code{\link{postgresqlDBApply}} 36 | \code{\link[DBI]{dbSendQuery}} 37 | \code{\link[DBI]{fetch}} 38 | } 39 | 40 | \examples{\dontrun{ 41 | ## compute quantiles for each network agent 42 | con <- dbConnect(PostgreSQL(), user= "user", password="passwd", dbname="sample") 43 | rs <- dbSendQuery(con, 44 | "select Agent, ip_addr, DATA from pseudo_data order by Agent") 45 | out <- dbApply(rs, INDEX = "Agent", 46 | FUN = function(x, grp) quantile(x$DATA, names=FALSE)) 47 | } 48 | } 49 | \keyword{programming}% at least one, from doc/KEYWORDS 50 | \keyword{interface}% __ONLY ONE__ keyword per line 51 | \keyword{database} 52 | % vim: syntax=tex 53 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbCallProc-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbCallProc-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbCallProc-methods} 3 | \docType{methods} 4 | \alias{dbCallProc-methods} 5 | \alias{dbCallProc,PostgreSQLConnection-method} 6 | \title{ 7 | Call an SQL stored procedure 8 | } 9 | \description{ 10 | Not yet implemented. 11 | } 12 | \section{Methods}{\describe{ 13 | \item{conn}{ 14 | a \code{PostgreSQLConnection} object. 15 | } 16 | \item{\dots }{ 17 | additional arguments are passed to the implementing method. 18 | } 19 | } 20 | } 21 | \references{ 22 | See the Database Interface definition document 23 | \code{DBI.pdf} in the base directory of this package 24 | or \url{https://cran.r-project.org/package=DBI}. 25 | } 26 | \seealso{ 27 | \code{\link{PostgreSQL}}, 28 | \code{\link[DBI]{dbConnect}}, 29 | \code{\link[DBI]{dbSendQuery}}, 30 | \code{\link[DBI]{dbGetQuery}}, 31 | \code{\link[DBI]{fetch}}, 32 | \code{\link[DBI]{dbCommit}}, 33 | \code{\link[DBI]{dbGetInfo}}, 34 | \code{\link[DBI]{dbReadTable}}. 35 | } 36 | \keyword{methods} 37 | \keyword{interface} 38 | \keyword{database} 39 | % vim: syntax=tex 40 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbCommit-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbCommit-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbCommit-methods} 3 | \docType{methods} 4 | \alias{dbBegin-method} 5 | \alias{dbCommit-method} 6 | \alias{dbRollback-method} 7 | \alias{PostgreSQLConnection-method} 8 | \alias{dbBegin,PostgreSQLConnection-method} 9 | \alias{dbCommit,PostgreSQLConnection-method} 10 | \alias{dbRollback,PostgreSQLConnection-method} 11 | \title{ 12 | DBMS Transaction Management 13 | } 14 | \description{ 15 | Transaction related commands. 16 | Start a transaction, commit or roll back the current transaction 17 | in an PostgreSQL connection. 18 | \code{dbBegin} starts a transaction. 19 | \code{dbCommit} and \code{dbRollback} commit and rollback the 20 | transaction, respectively. 21 | 22 | } 23 | \section{Methods}{\describe{ 24 | \item{conn}{a \code{PostgreSQLConnection} object, as produced by the function 25 | \code{dbConnect}.} 26 | \item{\dots }{currently unused.} 27 | } 28 | } 29 | \references{ 30 | See the Database Interface definition document 31 | \code{DBI.pdf} in the base directory of this package 32 | or 33 | \url{https://cran.r-project.org/package=DBI}. 34 | } 35 | \seealso{ 36 | \code{\link{PostgreSQL}}, 37 | \code{\link[DBI]{dbBegin}}, 38 | \code{\link[DBI]{dbConnect}}, 39 | \code{\link[DBI]{dbSendQuery}}, 40 | \code{\link[DBI]{dbGetQuery}}, 41 | \code{\link[DBI]{fetch}}, 42 | \code{\link[DBI]{dbCommit}}, 43 | \code{\link[DBI]{dbGetInfo}}, 44 | \code{\link[DBI]{dbReadTable}}. 45 | } 46 | \examples{\dontrun{ 47 | drv <- dbDriver("PostgreSQL") 48 | con <- dbConnect(drv, dbname="postgres") 49 | dbGetQuery(con, "select count(*) from sales") 50 | 51 | dbBegin(con) 52 | rs <- dbSendQuery(con, 53 | "Delete * from sales as p where p.cost>10") 54 | if(dbGetInfo(rs, what = "rowsAffected") > 250){ 55 | warning("Rolling back transaction") 56 | dbRollback(con) 57 | }else{ 58 | dbCommit(con) 59 | } 60 | 61 | dbGetQuery(con, "select count(*) from sales") 62 | dbDisconnect(con) 63 | } 64 | } 65 | 66 | \keyword{methods} 67 | \keyword{interface} 68 | \keyword{database} 69 | % vim: syntax=tex 70 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbConnect-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbConnect-methods.Rd,v 0.1 2008/07/28 20:56:01 psk Exp $ 2 | \name{dbConnect-methods} 3 | \docType{methods} 4 | \alias{dbDisconnect-methods} 5 | \alias{dbConnect-methods} 6 | \alias{dbDisconnect,PostgreSQLConnection-method} 7 | \alias{dbConnect,PostgreSQLDriver-method} 8 | \alias{dbConnect,PostgreSQLConnection-method} 9 | \alias{dbConnect,character-method} 10 | \title{ 11 | Create a connection object to an PostgreSQL DBMS 12 | } 13 | \description{ 14 | These methods are straight-forward implementations of the corresponding 15 | generic functions. 16 | } 17 | \section{Methods}{\describe{ 18 | \item{drv}{ 19 | an object of class \code{PostgreSQLDriver}, or 20 | the character string "PostgreSQL" or an \code{PostgreSQLConnection}. 21 | } 22 | \item{conn}{ 23 | an \code{PostgreSQLConnection} object as produced by \code{dbConnect}. 24 | } 25 | \item{host}{Name or the numeric IPaddress of the host to connect to. If address is specified, it should be in the standard IPv4 address format, e.g., 172.28.40.9 or if your machine supports IPv6, you can also use those addresses. The default is to connect to localhost by a UNIX domain socket. 26 | } 27 | \item{dbname}{The database name. Defaults to "", which is interpreted as PostgreSQL default. 28 | Most parameters are currently passed to PQsetdbLogin() as is. 29 | If dbname contains an = sign or has a valid connection URI prefix, 30 | it is taken as a conninfo for PQconnectdb() depending on the linked driver version. 31 | Refer to \url{https://www.postgresql.org/docs/current/libpq-connect.html} for detail. 32 | } 33 | \item{user}{PostgreSQL user name to connect as. Defaults to be the same as the operating system name of the user running the application. 34 | } 35 | \item{password}{Password to be used if the server demands password authentication. 36 | } 37 | \item{port}{Port number to connect to at the server host. 38 | } 39 | \item{tty}{Ignored (formerly, this specified where to send server debug output). 40 | } 41 | \item{options}{Command-line options to be sent to the server. 42 | } 43 | \item{forceISOdate}{logical if the communication of date (time stamp) from PostgreSQL is forced to ISO style at conection. This is an exception that is not really set by an option for PQsetdbLogin, but by issueing dbGetQuery(con, "set datestyle to ISO") after connection. 44 | } 45 | } 46 | } 47 | \section{Side Effects}{ 48 | A connection between R/S-Plus and an PostgreSQL server is 49 | established. The current implementation supports up to 50 | 100 simultaneous connections. 51 | } 52 | \references{ 53 | See the Database Interface definition document 54 | \code{DBI.pdf} in the base directory of this package 55 | or \url{https://cran.r-project.org/package=DBI}. 56 | } 57 | \seealso{ 58 | \code{\link{PostgreSQL}}, 59 | \code{\link[DBI]{dbConnect}}, 60 | \code{\link[DBI]{dbSendQuery}}, 61 | \code{\link[DBI]{dbGetQuery}}, 62 | \code{\link[DBI]{fetch}}, 63 | \code{\link[DBI]{dbCommit}}, 64 | \code{\link[DBI]{dbGetInfo}}, 65 | \code{\link[DBI]{dbReadTable}}. 66 | } 67 | \examples{\dontrun{ 68 | # create an PostgreSQL instance and create one connection. 69 | drv <- dbDriver("PostgreSQL") 70 | 71 | # open the connection using user, passsword, etc., as 72 | con <- dbConnect(drv, dbname = "postgres") 73 | 74 | df <- dbGetQuery(con, statement = paste( 75 | "SELECT itemCode, itemCost, itemProfit", 76 | "FROM sales", 77 | "SORT BY itemName")); 78 | # Run an SQL statement by creating first a resultSet object 79 | rs <- dbSendQuery(con, statement = paste( 80 | "SELECT itemCode, itemCost, itemProfit", 81 | "FROM sales", 82 | "SORT BY itemName")); 83 | 84 | # we now fetch records from the resultSet into a data.frame 85 | df <- fetch(rs, n = -1) # extract all rows 86 | dim(df) 87 | } 88 | } 89 | \keyword{methods} 90 | \keyword{interface} 91 | \keyword{database} 92 | % vim: syntax=tex 93 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbDataType-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbDataType-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbDataType-methods} 3 | \docType{methods} 4 | \alias{dbDataType-methods} 5 | \alias{dbDataType,PostgreSQLObject-method} 6 | \title{ 7 | Determine the SQL Data Type of an S object 8 | } 9 | \description{ 10 | This method is a straight-forward implementation of the corresponding 11 | generic function. 12 | } 13 | \section{Methods}{ 14 | \describe{ 15 | \item{dbObj}{ 16 | any \code{PostgreSQLObject} object, e.g., \code{PostgreSQLDriver}, 17 | \code{PostgreSQLConnection}, \code{PostgreSQLResult}. 18 | } 19 | \item{obj}{ 20 | R/S-Plus object whose SQL type we want to determine. 21 | } 22 | \item{\dots}{ 23 | any other parameters that individual methods may need. 24 | } 25 | } 26 | } 27 | \references{ 28 | See the Database Interface definition document 29 | \code{DBI.pdf} in the base directory of this package 30 | or \url{https://cran.r-project.org/package=DBI}. 31 | } 32 | \seealso{ 33 | \code{\link[DBI]{isSQLKeyword}} 34 | \code{\link[DBI]{make.db.names}} 35 | } 36 | \examples{\dontrun{ 37 | data(quakes) 38 | drv <- dbDriver("PostgreSQL") 39 | sql.type <- dbDataType(drv, quakes) 40 | } 41 | } 42 | \keyword{methods} 43 | \keyword{interface} 44 | \keyword{database} 45 | % docclass is function 46 | % Converted by Sd2Rd version 1.15.2.1. 47 | % vim: syntax=tex 48 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbDriver-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbDriver-methods.Rd,v 0.1 2008/07/28 01:09:05 psk Exp $ 2 | \name{dbDriver-methods} 3 | \docType{methods} 4 | \alias{dbDriver-methods} 5 | \alias{dbUnloadDriver-methods} 6 | \alias{dbDriver,character-method} 7 | \alias{dbUnloadDriver,PostgreSQLDriver-method} 8 | \title{ 9 | PostgreSQL implementation of the Database Interface (DBI) classes 10 | and drivers 11 | } 12 | \description{ 13 | PostgreSQL driver initialization and closing 14 | } 15 | \section{Methods}{\describe{ 16 | \item{drvName}{ 17 | character name of the driver to instantiate. 18 | } 19 | \item{drv}{ 20 | an object that inherits from \code{PostgreSQLDriver} as created by 21 | \code{dbDriver}. 22 | } 23 | \item{max.con}{optional integer requesting the maximum number of 24 | simultanous connections (may be up to 100)}. 25 | \item{fetch.default.rec}{default number of records to retrieve per fetch. 26 | Default is 500. This may be overridden in calls to \code{\link[DBI]{fetch}} 27 | with the \code{n=} argument.} 28 | \item{force.reload}{optional logical used to force re-loading or recomputing 29 | the size of the connection table. Default is \code{FALSE}.} 30 | \item{...}{currently unused.} 31 | } 32 | } 33 | \references{ 34 | See the Database Interface definition document 35 | \code{DBI.pdf} in the base directory of this package 36 | or 37 | \url{https://cran.r-project.org/package=DBI}. 38 | } 39 | \seealso{ 40 | \code{\link{PostgreSQL}}, 41 | \code{\link[DBI]{dbConnect}}, 42 | \code{\link[DBI]{dbSendQuery}}, 43 | \code{\link[DBI]{dbGetQuery}}, 44 | \code{\link[DBI]{fetch}}, 45 | \code{\link[DBI]{dbCommit}}, 46 | \code{\link[DBI]{dbGetInfo}}, 47 | \code{\link[DBI]{dbListTables}}, 48 | \code{\link[DBI]{dbReadTable}}. 49 | } 50 | \examples{\dontrun{ 51 | 52 | # create an PostgreSQL instance and set 10000 of rows per fetch. 53 | library(RPostgreSQL) 54 | drv <- dbDriver("PostgreSQL", fetch.default.records=10000) 55 | 56 | # Connecting to PostgreSQL with the specified parameters 57 | con <- dbConnect(drv,user="usrname",password="passwd",dbname="postgres") 58 | 59 | # Running the query to obtain the resultset 60 | rs <- dbSendQuery(con, "select * from cities where population > 5000") 61 | 62 | # fetch records into a dataframe. 63 | # n = 50 fetched fifty records 64 | df <- fetch(rs, n = 50) 65 | # n = -1 fetches all the remaining records available 66 | df2 <- fetch(rs, n = -1) 67 | 68 | # Clearing the result set 69 | dbClearResult(rs) 70 | 71 | #This returns a character vector (possibly of zero-length) 72 | # table names available on the con connection. 73 | dbListTables(con) 74 | } 75 | } 76 | \keyword{methods} 77 | \keyword{interface} 78 | \keyword{database} 79 | % vim: syntax=tex 80 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbGetInfo-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbGetInfo-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbGetInfo-methods} 3 | \docType{methods} 4 | \alias{dbGetInfo} 5 | \alias{dbGetDBIVersion-methods} 6 | \alias{dbGetStatement-methods} 7 | \alias{dbGetRowCount-methods} 8 | \alias{dbGetRowsAffected-methods} 9 | \alias{dbColumnInfo-methods} 10 | \alias{dbHasCompleted-methods} 11 | \alias{dbGetInfo,PostgreSQLObject-method} 12 | \alias{dbGetInfo,PostgreSQLDriver-method} % BUG: this is not needed 13 | \alias{dbGetInfo,PostgreSQLConnection-method} % BUG: this is not needed 14 | \alias{dbGetInfo,PostgreSQLResult-method} % BUG: this is not needed 15 | \alias{dbGetStatement,PostgreSQLResult-method} 16 | \alias{dbGetRowCount,PostgreSQLResult-method} 17 | \alias{dbGetRowsAffected,PostgreSQLResult-method} 18 | \alias{dbColumnInfo,PostgreSQLResult-method} 19 | \alias{dbHasCompleted,PostgreSQLResult-method} 20 | \title{ 21 | Database interface meta-data 22 | } 23 | \description{ 24 | These methods are straight-forward implementations of the corresponding 25 | generic functions. 26 | } 27 | \section{Methods}{\describe{ 28 | \item{dbObj}{ 29 | any object that implements some functionality in the R/S-Plus 30 | interface to databases (a driver, a connection or a result set). 31 | } 32 | \item{res}{ an \code{PostgreSQLResult}.} 33 | \item{\dots}{currently not being used.} 34 | } 35 | } 36 | \references{ 37 | See the Database Interface definition document 38 | \code{DBI.pdf} in the base directory of this package 39 | or \url{https://cran.r-project.org/package=DBI}. 40 | } 41 | \seealso{ 42 | \code{\link{PostgreSQL}}, 43 | \code{\link[DBI]{dbDriver}}, 44 | \code{\link[DBI]{dbConnect}}, 45 | \code{\link[DBI]{dbSendQuery}}, 46 | \code{\link[DBI]{dbGetQuery}}, 47 | \code{\link[DBI]{fetch}}, 48 | \code{\link[DBI]{dbCommit}}, 49 | \code{\link[DBI]{dbGetInfo}}, 50 | \code{\link[DBI]{dbListTables}}, 51 | \code{\link[DBI]{dbReadTable}}. 52 | } 53 | \examples{\dontrun{ 54 | drv <- dbDriver("PostgreSQL") 55 | con <- dbConnect(drv, user= "user", password="password", dbname="sample") 56 | 57 | dbListTables(con) 58 | 59 | rs <- dbSendQuery(con, query.sql) 60 | dbGetStatement(rs) 61 | dbHasCompleted(rs) 62 | 63 | info <- dbGetInfo(rs) 64 | names(dbGetInfo(drv)) 65 | 66 | # DBIConnection info 67 | names(dbGetInfo(con)) 68 | 69 | # DBIResult info 70 | names(dbGetInfo(rs)) 71 | } 72 | } 73 | \note{nullOk in \code{dbColumnInfo} was changed. Now it may be TRUE, FALSE, or NA; the column may be totally deleted in future releases;} 74 | \keyword{methods} 75 | \keyword{interface} 76 | \keyword{database} 77 | % vim: syntax=tex 78 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbListTables-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbListTables-methods.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbListTables-methods} 3 | \docType{methods} 4 | \alias{dbListTables-methods} 5 | \alias{dbListFields-methods} 6 | \alias{dbListConnections-methods} 7 | \alias{dbListResults-methods} 8 | \alias{dbListTables,PostgreSQLConnection-method} 9 | \alias{dbListFields,PostgreSQLConnection,character-method} 10 | \alias{dbListFields,PostgreSQLResult,missing-method} 11 | \alias{dbListConnections,PostgreSQLDriver-method} 12 | \alias{dbListResults,PostgreSQLConnection-method} 13 | \title{ 14 | List items from an PostgreSQL DBMS and from objects 15 | } 16 | \description{ 17 | These methods are straight-forward implementations of the corresponding 18 | generic functions. 19 | } 20 | \section{Methods}{\describe{ 21 | \item{drv}{an \code{PostgreSQLDriver}.} 22 | \item{conn}{an \code{PostgreSQLConnection}.} 23 | \item{name}{a character string with the table name.} 24 | \item{\dots}{currently not used.} 25 | } 26 | } 27 | \references{ 28 | See the Database Interface definition document 29 | \code{DBI.pdf} in the base directory of this package 30 | or 31 | \url{https://cran.r-project.org/package=DBI}. 32 | } 33 | \seealso{ 34 | \code{\link{PostgreSQL}}, 35 | \code{\link[DBI]{dbGetInfo}}, 36 | \code{\link[DBI]{dbColumnInfo}}, 37 | \code{\link[DBI]{dbDriver}}, 38 | \code{\link[DBI]{dbConnect}}, 39 | \code{\link[DBI]{dbSendQuery}} 40 | } 41 | 42 | \examples{\dontrun{ 43 | drv <- dbDriver("PostgreSQL") 44 | # after working awhile... 45 | for(con in dbListConnections(drv)){ 46 | dbGetStatement(dbListResults(con)) 47 | } 48 | } 49 | } 50 | \keyword{methods} 51 | \keyword{interface} 52 | \keyword{database} 53 | % vim: syntax=tex 54 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbObjectId-class.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbObjectId-class.Rd,v 0.1 2008/08/10 18:04:01 psk Exp $ 2 | \name{dbObjectId-class} 3 | \docType{class} 4 | \alias{dbObjectId-class} 5 | \title{Class dbObjectId} 6 | \description{ 7 | A helper (mixin) class to provide external references in 8 | an R/S-Plus portable way. 9 | } 10 | \section{Objects from the Class}{A virtual Class: No objects may be created from it.} 11 | \section{Slots}{ 12 | \describe{ 13 | \item{\code{Id}:}{Object of class \code{"integer"} 14 | this is an integer vector holding an opaque reference into a C struct 15 | (may or may not be a C pointer, may or may not have length one). 16 | } 17 | } 18 | } 19 | 20 | \section{Methods}{ 21 | \describe{ 22 | \item{\link{coerce}}{\code{signature(from = "dbObjectId", to = "integer")}: ... } 23 | \item{\link{coerce}}{\code{signature(from = "dbObjectId", to = "numeric")}: ... } 24 | \item{\link{coerce}}{\code{signature(from = "dbObjectId", to = "character")}: ... } 25 | \item{\link{format}}{\code{signature(x = "dbObjectId")}: ... } 26 | \item{\link{print}}{\code{signature(x = "dbObjectId")}: ... } 27 | \item{\link{show}}{\code{signature(object = "dbObjectId")}: ... } 28 | } 29 | } 30 | 31 | \note{A cleaner mechanism would use external references, but 32 | historically this class has existed mainly for R/S-Plus portability.} 33 | 34 | \examples{\dontrun{ 35 | pg <- dbDriver("PostgreSQL") 36 | con <- dbConnect(pg, "user", "password") 37 | is(pg, "dbObjectId") ## True 38 | is(con, "dbObjectId") ## True 39 | isPostgresqlIdCurrent(con) ## True 40 | q("yes") 41 | \$ R 42 | isPostgresqlIdCurrent(con) ## False 43 | } 44 | } 45 | \keyword{classes} 46 | \keyword{interface} 47 | \keyword{database} 48 | % vim: syntax=tex 49 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbSendQuery-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbSendQuery-methods.Rd,v 0.1 2008/07/23 02:38:31 psk Exp $ 2 | \name{dbSendQuery-methods} 3 | \docType{methods} 4 | \alias{dbSendQuery-methods} 5 | \alias{dbGetQuery-methods} 6 | \alias{dbClearResult-methods} 7 | \alias{dbGetException-methods} 8 | \alias{dbSendQuery,PostgreSQLConnection,character-method} 9 | \alias{dbGetQuery,PostgreSQLConnection,character-method} 10 | \alias{dbClearResult,PostgreSQLResult-method} 11 | \alias{dbGetException,PostgreSQLConnection-method} 12 | \alias{dbGetException,PostgreSQLResult-method} 13 | \title{ 14 | Execute a statement on a given database connection 15 | } 16 | \description{ 17 | These methods are straight-forward implementations of the corresponding 18 | generic functions. 19 | However, for complex data like array are just transferred as a string instead of the corresponding 20 | vector in R. This behavior will change in future releases, and the author is advised not to rely on it. 21 | } 22 | \section{Methods}{\describe{ 23 | \item{conn}{ 24 | an \code{PostgreSQLConnection} object. 25 | } 26 | \item{statement}{a character vector of length 1 with the SQL statement.} 27 | \item{res}{an \code{PostgreSQLResult} object.} 28 | \item{\dots }{additional parameters.} 29 | } 30 | } 31 | \references{ 32 | See the Database Interface definition document 33 | \code{DBI.pdf} in the base directory of this package 34 | or \url{https://cran.r-project.org/package=DBI}. 35 | } 36 | \seealso{ 37 | \code{\link{PostgreSQL}}, 38 | \code{\link[DBI]{dbDriver}}, 39 | \code{\link[DBI]{dbConnect}}, 40 | \code{\link[DBI]{fetch}}, 41 | \code{\link[DBI]{dbCommit}}, 42 | \code{\link[DBI]{dbGetInfo}}, 43 | \code{\link[DBI]{dbReadTable}}. 44 | } 45 | \examples{\dontrun{ 46 | drv <- dbDriver("PostgreSQL") 47 | con <- dbConnect(drv, "usr", "password", "dbname") 48 | res <- dbSendQuery(con, "SELECT * from sales") 49 | data <- fetch(res, n = -1) 50 | # alternatively, use dbGetQuery 51 | data <- dbGetQuery(con, "SELECT * from sales") 52 | } 53 | } 54 | \keyword{methods} 55 | \keyword{interface} 56 | \keyword{database} 57 | % vim: syntax=tex 58 | -------------------------------------------------------------------------------- /RPostgreSQL/man/dbSetDataMappings-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: dbSetDataMappings-methods.Rd, V 0.1 2008/07/23 02:38:31 psk Exp $ 2 | \name{dbSetDataMappings-methods} 3 | \docType{methods} 4 | \alias{dbSetDataMappings-methods} 5 | \alias{dbSetDataMappings,PostgreSQLResult,data.frame-method} 6 | \title{ 7 | Set data mappings between PostgreSQL and R/S-Plus 8 | } 9 | \description{ 10 | Not yet implemented 11 | } 12 | \section{Methods}{\describe{ 13 | \item{res}{ 14 | a \code{PostgreSQLResult} object as returned by \code{dbSendQuery}. 15 | } 16 | \item{flds}{ 17 | a data.frame with field descriptions as returned by 18 | \code{\link[DBI]{dbColumnInfo}}. 19 | } 20 | \item{\dots }{ 21 | any additional arguments are passed to the implementing method. 22 | } 23 | } 24 | } 25 | \references{ 26 | See the Database Interface definition document 27 | \code{DBI.pdf} in the base directory of this package 28 | or \url{https://cran.r-project.org/package=DBI}. 29 | } 30 | \seealso{ 31 | \code{\link{PostgreSQL}}, 32 | \code{\link[DBI]{dbSendQuery}}, 33 | \code{\link[DBI]{fetch}}, 34 | \code{\link[DBI]{dbColumnInfo}}. 35 | } 36 | \examples{\dontrun{ 37 | makeImage <- function(x) { 38 | .C("make_Image", as.integer(x), length(x)) 39 | } 40 | 41 | res <- dbSendQuery(con, statement) 42 | flds <- dbColumnInfo(res) 43 | flds[3, "Sclass"] <- makeImage 44 | 45 | dbSetDataMappings(rs, flds) 46 | 47 | im <- fetch(rs, n = -1) 48 | } 49 | } 50 | \keyword{methods} 51 | \keyword{interface} 52 | \keyword{database} 53 | % vim: syntax=tex 54 | -------------------------------------------------------------------------------- /RPostgreSQL/man/fetch-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: fetch-methods.Rd,v 0.1 2008/07/23 02:38:31 psk Exp $ 2 | \name{fetch-methods} 3 | \docType{methods} 4 | \alias{fetch-methods} 5 | \alias{fetch,PostgreSQLResult,numeric-method} 6 | \alias{fetch,PostgreSQLResult,missing-method} 7 | %\alias{fetch,PostgreSQLResult-method} 8 | \title{ 9 | Fetch records from a previously executed query 10 | } 11 | \description{ 12 | This method is a straight-forward implementation of the corresponding 13 | generic function. 14 | } 15 | \section{Methods}{\describe{ 16 | 17 | \item{res}{ 18 | an \code{PostgreSQLResult} object. 19 | } 20 | \item{n}{ 21 | maximum number of records to retrieve per fetch. 22 | Use \code{n = -1} to retrieve all pending records; 23 | use a value of \code{n = 0} for fetching the default number 24 | of rows \code{fetch.default.rec} defined in the 25 | \code{\link{PostgreSQL}} initialization invocation. 26 | } 27 | \item{\dots }{currently not used.} 28 | } 29 | } 30 | \details{ 31 | The \code{RPostgreSQL} implementations retrieves only \code{n} records, 32 | and if \code{n} is missing it only returns up to \code{fetch.default.rec} 33 | as specified in the call to \code{\link{PostgreSQL}} (500 by default). 34 | } 35 | \references{ 36 | See the Database Interface definition document 37 | \code{DBI.pdf} in the base directory of this package 38 | or \url{https://cran.r-project.org/package=DBI}. 39 | } 40 | \seealso{ 41 | \code{\link{PostgreSQL}}, 42 | \code{\link[DBI]{dbConnect}}, 43 | \code{\link[DBI]{dbSendQuery}}, 44 | \code{\link[DBI]{dbGetQuery}}, 45 | \code{\link[DBI]{dbClearResult}}, 46 | \code{\link[DBI]{dbCommit}}, 47 | \code{\link[DBI]{dbGetInfo}}, 48 | \code{\link[DBI]{dbReadTable}}. 49 | } 50 | \examples{\dontrun{ 51 | drv <- dbDriver("PostgreSQL") 52 | con <- dbConnect(drv, user = "ruser",password = "123456",dbname = "status") 53 | res <- dbSendQuery(con, statement = paste( 54 | "SELECT w.category, w.cost, p.type", 55 | "FROM items w, sales P", 56 | "WHERE w.category = p.type", 57 | "ORDER BY w.cost")) 58 | # we now fetch the first 100 records from the resultSet into a data.frame 59 | data1 <- fetch(res, n = 100) 60 | dim(data1) 61 | 62 | dbHasCompleted(res) 63 | 64 | # let's get all remaining records 65 | data2 <- fetch(res, n = -1) 66 | } 67 | } 68 | \keyword{methods} 69 | \keyword{interface} 70 | \keyword{database} 71 | % vim: syntax=tex 72 | -------------------------------------------------------------------------------- /RPostgreSQL/man/isPostgresqlIdCurrent.Rd: -------------------------------------------------------------------------------- 1 | % $Id: isPostgresqlIdCurrent.Rd,v 0.1 2008/07/23 02:38:31 psk Exp $ 2 | \name{isPostgresqlIdCurrent} 3 | \alias{isPostgresqlIdCurrent} 4 | \title{ 5 | Check whether a database handle object is valid or not 6 | } 7 | \description{ 8 | Support function that verifies that an object holding a reference 9 | to a foreign object is still valid for communicating with the RDBMS 10 | } 11 | \usage{ 12 | isPostgresqlIdCurrent(obj) 13 | } 14 | \arguments{ 15 | \item{obj}{ 16 | any \code{dbObject} (e.g., \code{dbDriver}, 17 | \code{dbConnection}, \code{dbResult}). 18 | } 19 | } 20 | \value{ 21 | a logical scalar. 22 | } 23 | \details{ 24 | \code{dbObjects} are R/S-Plus remote references to foreign objects. 25 | This introduces differences to the object's semantics such as 26 | persistence (e.g., connections may be closed unexpectedly), 27 | thus this function provides a minimal verification to ensure 28 | that the foreign object being referenced can be contacted. 29 | } 30 | \seealso{ 31 | \code{\link[DBI]{dbDriver}} 32 | \code{\link[DBI]{dbConnect}} 33 | \code{\link[DBI]{dbSendQuery}} 34 | \code{\link[DBI]{fetch}} 35 | } 36 | \examples{\dontrun{ 37 | cursor <- dbSendQuery(con, sql.statement) 38 | isIdCurrent(cursor) 39 | } 40 | } 41 | \keyword{interface} 42 | \keyword{database} 43 | % docclass is function 44 | % vim: syntax=tex 45 | -------------------------------------------------------------------------------- /RPostgreSQL/man/make.db.names-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: make.db.names-methods.Rd,v 0.1 2008/07/22 03:16:22 psk Exp $ 2 | 3 | \name{make.db.names-methods} 4 | \docType{methods} 5 | \alias{SQLKeywords-methods} 6 | \alias{isSQLKeyword-methods} 7 | \alias{make.db.names,PostgreSQLObject,character-method} 8 | \alias{SQLKeywords,PostgreSQLObject-method} 9 | \alias{SQLKeywords,missing-method} 10 | \alias{isSQLKeyword,PostgreSQLObject,character-method} 11 | \title{ 12 | Make R/S-Plus identifiers into quoted PostgreSQL identifiers 13 | } 14 | \description{ 15 | Calls postgresqlquoteId to make valid quoted identifiers. 16 | This has calling convention same as the make.db.names for compatibility. 17 | } 18 | \section{Methods}{\describe{ 19 | \item{dbObj}{ 20 | any PostgreSQL object (e.g., \code{PostgreSQLDriver}). Just ignored. 21 | } 22 | \item{snames}{ 23 | a character vector of R/S-Plus identifiers (symbols) from which 24 | we need to make SQL identifiers. 25 | } 26 | \item{name}{ 27 | a character vector of SQL identifiers we want to check against 28 | keywords from the DBMS. Ignored. 29 | } 30 | \item{unique}{ 31 | logical describing whether the resulting set of SQL names should 32 | be unique. Its default is \code{TRUE}. Following the SQL 92 33 | standard, uniqueness of SQL identifiers is determined regardless 34 | of whether letters are upper or lower case. Ignored. 35 | } 36 | \item{allow.keywords }{ 37 | logical describing whether SQL keywords should be allowed in the 38 | resulting set of SQL names. Its default is \code{TRUE}. Ignored. 39 | } 40 | \item{keywords}{ 41 | a character vector with SQL keywords, by default it is 42 | \code{.PostgreSQLKeywords} define in \code{RPostgreSQL}. This may 43 | be overriden by users. Ignored. 44 | } 45 | \item{case}{ 46 | a character string specifying whether to make the comparison 47 | as lower case, upper case, or any of the two. 48 | it defaults to \code{any}. Ignored. 49 | } 50 | \item{\dots}{currently not used.} 51 | } 52 | } 53 | \references{ 54 | The set of SQL keywords is stored in the character vector 55 | \code{.SQL92Keywords} and reflects the SQL ANSI/ISO standard as 56 | documented in "X/Open SQL and RDA", 1994, ISBN 1-872630-68-8. 57 | Users can easily override or update this vector. 58 | 59 | PostgreSQL does add some keywords to the SQL 92 standard, they are 60 | listed in the \code{.PostgreSQLKeywords} object. 61 | 62 | See the Database Interface definition document 63 | \code{DBI.pdf} in the base directory of this package 64 | or \url{https://cran.r-project.org/package=DBI}. 65 | } 66 | \seealso{ 67 | \code{\link{PostgreSQL}}, 68 | \code{\link[DBI]{dbReadTable}}, 69 | \code{\link[DBI]{dbWriteTable}}, 70 | \code{\link[DBI]{dbExistsTable}}, 71 | \code{\link[DBI]{dbRemoveTable}}, 72 | \code{\link[DBI]{dbListTables}}. 73 | } 74 | \examples{\dontrun{ 75 | # This example shows how we could export a bunch of data.frames 76 | # into tables on a remote database. 77 | 78 | } 79 | } 80 | \keyword{methods} 81 | \keyword{interface} 82 | \keyword{database} 83 | % vim: syntax=tex 84 | -------------------------------------------------------------------------------- /RPostgreSQL/man/postgresqlBuildTableDefinition.Rd: -------------------------------------------------------------------------------- 1 | %% TODO: Should we move this to the DBI package? 2 | \name{postgresqlBuildTableDefinition} 3 | \alias{postgresqlBuildTableDefinition} 4 | \title{Build the SQL CREATE TABLE definition as a string} 5 | \description{ 6 | Build the SQL CREATE TABLE definition as a string for the 7 | input data.frame 8 | } 9 | \usage{ 10 | postgresqlBuildTableDefinition(dbObj, name, obj, 11 | field.types = NULL, row.names = TRUE, ...) 12 | } 13 | \arguments{ 14 | \item{dbObj}{any DBI object (used only to dispatch according to the 15 | engine (e.g., MySQL, Oracle, PostgreSQL, SQLite) } 16 | \item{name}{name of the new SQL table} 17 | \item{obj}{an R object coerceable to data.frame for which we want 18 | to create a table} 19 | \item{field.types}{optional named list of the types for each field 20 | in \code{obj}} 21 | \item{row.names}{logical, should row.name of \code{value} be exported 22 | as a \code{row\_names} field? Default is TRUE} 23 | \item{\dots}{reserved for future use} 24 | } 25 | \details{ 26 | The output SQL statement is a simple \code{CREATE TABLE} with 27 | suitable for \code{dbGetQuery} 28 | } 29 | \value{ 30 | An SQL string 31 | } 32 | \references{ 33 | See the Database Interface definition document 34 | \code{DBI.pdf} in the base directory of this package 35 | or \url{https://cran.r-project.org/package=DBI}. 36 | } 37 | \seealso{ 38 | \code{\link{PostgreSQL}}, 39 | \code{\link[DBI]{dbConnect}}, 40 | \code{\link[DBI]{dbSendQuery}}, 41 | \code{\link[DBI]{dbGetQuery}}, 42 | \code{\link[DBI]{fetch}}, 43 | \code{\link[DBI]{dbCommit}}, 44 | \code{\link[DBI]{dbGetInfo}}, 45 | \code{\link[DBI]{dbReadTable}}. 46 | } 47 | \keyword{methods} 48 | \keyword{interface} 49 | \keyword{database} 50 | %% vim: syntax=tex 51 | -------------------------------------------------------------------------------- /RPostgreSQL/man/postgresqlDBApply.Rd: -------------------------------------------------------------------------------- 1 | % $Id: postgresqlDBApply.Rd,v 0.1 2008/07/23 03:09:11 psk Exp $ 2 | \name{postgresqlDBApply} 3 | \alias{postgresqlDBApply} 4 | \title{Apply R/S-Plus functions to remote groups of DBMS rows (experimental)} 5 | \description{ 6 | Applies R/S-Plus functions to groups of remote DBMS rows without 7 | bringing an entire result set all at once. The result set 8 | is expected to be sorted by the grouping field. 9 | } 10 | \usage{ 11 | postgresqlDBApply(res, INDEX, FUN = stop("must specify FUN"), 12 | begin = NULL, 13 | group.begin = NULL, 14 | new.record = NULL, 15 | end = NULL, 16 | batchSize = 100, maxBatch = 1e6, 17 | ..., simplify = TRUE) 18 | } 19 | \arguments{ 20 | \item{res}{a result set (see \code{\link[DBI]{dbSendQuery}}).} 21 | \item{INDEX}{a character or integer specifying the field name or 22 | field number that defines the various groups.} 23 | \item{FUN}{a function to be invoked upon identifying the last 24 | row from every group. This function will be passed 25 | a data frame holding the records of the current group, 26 | a character string with the group label, plus any 27 | other arguments passed to \code{dbApply} as \code{"..."}.} 28 | \item{begin}{a function of no arguments to be invoked just prior to 29 | retrieve the first row from the result set.} 30 | \item{end}{a function of no arguments to be invoked just after retrieving 31 | the last row from the result set.} 32 | \item{group.begin}{a function of one argument (the group label) to be 33 | invoked upon identifying a row from a new group}. 34 | \item{new.record}{a function to be invoked as each individual record 35 | is fetched. The first argument to this function is a 36 | one-row data.frame holding the new record.} 37 | \item{batchSize}{the default number of rows to bring from the remote 38 | result set. If needed, this is automatically extended 39 | to hold groups bigger than \code{batchSize}.} 40 | \item{maxBatch}{the absolute maximum of rows per group that may 41 | be extracted from the result set.} 42 | \item{...}{any additional arguments to be passed to \code{FUN}.} 43 | \item{simplify}{Not yet implemented} 44 | } 45 | \details{ 46 | \code{dbApply} 47 | This function is meant to handle somewhat gracefully(?) large amounts 48 | of data from the DBMS by bringing into R manageable chunks (about 49 | \code{batchSize} records at a time, but not more than \code{maxBatch}); 50 | the idea is that the data from individual groups can be handled by R, but 51 | not all the groups at the same time. 52 | 53 | The PostgreSQL implementation \code{postgresqlDBApply} allows us to register R 54 | functions that get invoked 55 | when certain fetching events occur. These include the ``begin'' event 56 | (no records have been yet fetched), ``begin.group'' (the record just 57 | fetched belongs to a new group), ``new record'' (every fetched record 58 | generates this event), ``group.end'' (the record just fetched was the 59 | last row of the current group), ``end'' (the very last record from the 60 | result set). Awk and perl programmers will find this paradigm very 61 | familiar (although SAP's ABAP language is closer to what we're doing). 62 | } 63 | \value{ 64 | A list with as many elements as there were groups in the 65 | result set. 66 | } 67 | \note{This is an experimental version implemented only in R (there are 68 | plans, time permitting, to implement it in S-Plus). 69 | 70 | The terminology that we're using is closer to SQL than R. In R 71 | what we're referring to ``groups'' are the individual levels of 72 | a factor (grouping field in our terminology). 73 | } 74 | 75 | \seealso{\code{\link{PostgreSQL}}, \code{\link[DBI]{dbSendQuery}}, \code{\link[DBI]{fetch}}.} 76 | 77 | \examples{\dontrun{ 78 | drv <- dbDriver(RPostgreSQL) 79 | con <- dbConnect(drv, user ="usrname", password="pword", dname="database") 80 | res <- dbSendQuery(con, 81 | "select Agent, ip_addr, DATA from pseudo_data order by Agent") 82 | out <- dbApply(res, INDEX = "Agent", 83 | FUN = function(x, grp) quantile(x$DATA, names=FALSE)) 84 | } 85 | } 86 | \keyword{programming}% at least one, from doc/KEYWORDS 87 | \keyword{interface}% __ONLY ONE__ keyword per line 88 | \keyword{database} 89 | % vim: syntax=tex 90 | -------------------------------------------------------------------------------- /RPostgreSQL/man/summary-methods.Rd: -------------------------------------------------------------------------------- 1 | % $Id: summary-methods.Rd,v 0.1 2008/08/10 15:09:01 psk $ 2 | \name{summary-methods} 3 | \docType{methods} 4 | \alias{coerce-methods} 5 | \alias{summary-methods} 6 | \alias{format-methods} 7 | \alias{show-methods} 8 | \alias{coerce,dbObjectId,integer-method} 9 | \alias{coerce,dbObjectId,numeric-method} 10 | \alias{coerce,dbObjectId,character-method} 11 | \alias{coerce,PostgreSQLObject,PostgreSQLDriver-method} 12 | \alias{coerce,PostgreSQLConnection,PostgreSQLResult-method} 13 | \alias{coerce,PostgreSQLConnection,PostgreSQLDriver-method} 14 | \alias{coerce,PostgreSQLResult,PostgreSQLConnection-method} 15 | \alias{coerce,PostgreSQLResult,PostgreSQLDriver-method} 16 | \alias{format,dbObjectId-method} 17 | \alias{print,dbObjectId-method} 18 | \alias{show,dbObjectId-method} 19 | \alias{summary,PostgreSQLObject-method} 20 | \alias{summary,PostgreSQLDriver-method} 21 | \alias{summary,PostgreSQLConnection-method} 22 | \alias{summary,PostgreSQLResult-method} 23 | \title{Summarize an PostgreSQL object} 24 | \description{ 25 | These methods are straight-forward implementations of the corresponding 26 | generic functions. 27 | } 28 | \section{Methods}{\describe{ 29 | 30 | \item{object = "DBIObject"}{ 31 | Provides relevant metadata information on \code{object}, 32 | for instance, the PostgreSQL server file, the 33 | SQL statement associated with a result set, etc. 34 | } 35 | \item{from}{object to be coerced} 36 | \item{to}{coercion class} 37 | \item{x}{object to \code{format} or \code{print} or \code{show}} 38 | } 39 | } 40 | \keyword{methods} 41 | \keyword{database} 42 | \keyword{interface} 43 | % vim: syntax=tex 44 | -------------------------------------------------------------------------------- /RPostgreSQL/src/Makevars.in: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS=@PKG_CPPFLAGS@ 2 | PKG_LIBS=@PKG_LIBS@ 3 | R_OS_TYPE=@R_OS_TYPE@ 4 | 5 | @ENABLE_LIBPQ@ 6 | -------------------------------------------------------------------------------- /RPostgreSQL/src/Makevars.win: -------------------------------------------------------------------------------- 1 | ifeq (,$(shell pkg-config --version 2>/dev/null)) 2 | PKG_LIBS = -lpq -lpgcommon -lpgport -lssl -lcrypto -lm -lz -lsecur32 -lws2_32 -lwldap32 \ 3 | -lshell32 -lcrypt32 -lgdi32 4 | else 5 | PKG_CPPFLAGS = $(shell pkg-config --cflags libpq) 6 | PKG_LIBS = $(shell pkg-config --libs libpq) 7 | endif 8 | 9 | -------------------------------------------------------------------------------- /RPostgreSQL/src/RS-PQescape.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RS-PQescape.c 3 | * 4 | * $Id$ 5 | */ 6 | 7 | #include "RS-PostgreSQL.h" 8 | 9 | /* 10 | * Adapter function to PQescapeStringConn() 11 | * This function should properly escape the string argument 12 | * appropriately depending on the encoding etc. that is specific to 13 | * connection. 14 | * Note the single quote is not attached in the return val. 15 | */ 16 | SEXP 17 | RS_PostgreSQL_escape(SEXP conHandle, SEXP preescapestring) 18 | { 19 | S_EVALUATOR PGconn * my_connection; 20 | RS_DBI_connection *con; 21 | SEXP output; 22 | size_t length; 23 | const char *statement_cstr; 24 | char *escapedstring; 25 | con = RS_DBI_getConnection(conHandle); 26 | my_connection = (PGconn *) con->drvConnection; 27 | statement_cstr = CHR_EL(preescapestring, 0); 28 | length = strlen(statement_cstr); 29 | escapedstring = R_alloc(length * 2 + 1, 1); 30 | PQescapeStringConn(my_connection, escapedstring, statement_cstr, length, NULL); 31 | PROTECT(output = allocVector(STRSXP, 1)); 32 | SET_STRING_ELT(output, 0, mkChar(escapedstring)); 33 | UNPROTECT(1); 34 | return output; 35 | } 36 | 37 | /* 38 | * Adapter function to PQescapeByteaConn() 39 | * This function should properly escape the raw argument 40 | * appropriately depending on connection. 41 | * Note the single quote is not attached in the return val. 42 | * The returned string could differ depending on the environment. 43 | * Especially standard_conforming_strings parameter 44 | * is possibly influencial. 45 | * http://www.postgresql.org/docs/9.3/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS 46 | */ 47 | SEXP 48 | RS_PostgreSQL_escape_bytea(SEXP conHandle, SEXP raw_data) 49 | { 50 | S_EVALUATOR PGconn * my_connection; 51 | RS_DBI_connection *con; 52 | SEXP output; 53 | size_t length; 54 | char *escapedstring; 55 | size_t escaped_length; 56 | con = RS_DBI_getConnection(conHandle); 57 | my_connection = (PGconn *) con->drvConnection; 58 | length = LENGTH(raw_data); 59 | escapedstring = (char *)PQescapeByteaConn(my_connection, RAW(raw_data), length, &escaped_length); 60 | /* explicit cast to make clang silent for difference in signedness*/ 61 | PROTECT(output = allocVector(STRSXP, 1)); 62 | SET_STRING_ELT(output, 0, mkChar(escapedstring)); 63 | free(escapedstring); 64 | UNPROTECT(1); 65 | return output; 66 | } 67 | 68 | static inline unsigned char 69 | hex2n(unsigned char h) 70 | { 71 | if (h >= '0' && h <= '9') return h-'0'; 72 | if (h >= 'a' && h <= 'f') return h-'a' + 10; 73 | if (h >= 'A' && h <= 'F') return h-'A' + 10; 74 | return h; 75 | } 76 | /* 77 | * Adapter function to PQunescapeBytea() 78 | * This function should properly unescape the charactor representation 79 | * of the binary data returned from PostgreSQL and return raw binary data. 80 | */ 81 | SEXP 82 | RS_PostgreSQL_unescape_bytea(SEXP escapedstring) 83 | { 84 | SEXP output; 85 | size_t raw_length; 86 | const char* strbuffer; 87 | unsigned char* rawbuffer; 88 | strbuffer = CHAR(STRING_ELT(escapedstring, 0)); 89 | if(!strbuffer) RS_DBI_errorMessage("strbuffer is NULL!", RS_DBI_ERROR); 90 | if (strbuffer[0] == '\\' && strbuffer[1] == 'x'){ 91 | /* the new hex fomat */ 92 | int i; 93 | size_t enc_length = LENGTH(STRING_ELT(escapedstring, 0)); 94 | raw_length = enc_length / 2 - 1; 95 | output = allocVector(RAWSXP, raw_length); 96 | rawbuffer = RAW(output); 97 | for(i = 0; i < raw_length; i++){ 98 | rawbuffer[i] = (hex2n(strbuffer[2+ i*2]) << 4) + hex2n(strbuffer[2+i*2+1]); 99 | } 100 | return output; 101 | }else{ /* the old escape format */ 102 | rawbuffer = PQunescapeBytea((const unsigned char*) strbuffer, &raw_length); 103 | /* explicit cast to suppress warning on signedness by clang */ 104 | if(!rawbuffer) RS_DBI_errorMessage("PQunescapeByea Failed", RS_DBI_ERROR); 105 | output = allocVector(RAWSXP, raw_length); 106 | memcpy(RAW(output), rawbuffer, raw_length); 107 | free(rawbuffer); 108 | return output; 109 | } 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /RPostgreSQL/src/RS-pgsql-getResult.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RS-pgsql-copy.c 3 | * 4 | * $Id$ 5 | */ 6 | 7 | #include "RS-PostgreSQL.h" 8 | #define COPY_IN_BUFSIZE 8192 9 | 10 | /* adapter for PQputCopyData and PQputCopyEnd 11 | which is used in conjunction with COPY table from STDIN */ 12 | 13 | /* 14 | * RS_PostgreSQL_CopyIn copies all content of the file specified with filename 15 | * to the conHandle which has opened connection previously issued the COPY 16 | * table from STDIN query the data is read from file sent to the database with 17 | * PQputCopyData in chunks of COPY_IN_BUFSIZE. 18 | * The copy ends when 0 byte could be read from the file and then the 19 | * PQputCopyEnd is called to complete the copying. 20 | */ 21 | 22 | 23 | /* 24 | * RS_PostgreSQL_getResult is the implementation of postgresqlgetResult() 25 | * 26 | * RS_PostgreSQL_getResult will be called after CopyIn 27 | * for cheching the result of CopyIn 28 | * 29 | * postgresqlCopyInDataframe(new.con, value) 30 | * rs<-postgresqlgetResult(new.con) 31 | */ 32 | 33 | s_object * 34 | RS_PostgreSQL_getResult(Con_Handle * conHandle) 35 | { 36 | S_EVALUATOR RS_DBI_connection * con; 37 | S_EVALUATOR RS_DBI_resultSet * result; 38 | PGconn *my_connection; 39 | Res_Handle *rsHandle; 40 | int res_id; 41 | 42 | PGresult *my_result; 43 | 44 | con = RS_DBI_getConnection(conHandle); 45 | my_connection = (PGconn *) con->drvConnection; 46 | 47 | if (con->num_res > 0) { 48 | res_id = con->resultSetIds[0]; 49 | rsHandle = RS_DBI_asResHandle(MGR_ID(conHandle), CON_ID(conHandle), res_id); 50 | result = RS_DBI_getResultSet(rsHandle); 51 | if (result->completed == 0) { 52 | RS_DBI_errorMessage("connection with pending rows, close resultSet before continuing", RS_DBI_ERROR); 53 | } 54 | else { 55 | RS_PostgreSQL_closeResultSet(rsHandle); 56 | } 57 | } 58 | 59 | my_result = PQgetResult(my_connection); 60 | if(my_result == NULL) 61 | return S_NULL_ENTRY; 62 | if (strcmp(PQresultErrorMessage(my_result), "") != 0) { 63 | char *errResultMsg; 64 | const char *omsg; 65 | size_t len; 66 | omsg = PQerrorMessage(my_connection); 67 | len = strlen(omsg); 68 | errResultMsg = R_alloc(len + 80, 1); /* 80 should be larger than the length of "could not ..."*/ 69 | snprintf(errResultMsg, len + 80, "could not Retrieve the result : %s", omsg); 70 | PQclear(my_result); 71 | my_result = NULL; 72 | RS_DBI_errorMessage(errResultMsg, RS_DBI_ERROR); 73 | /* Frees the storage associated with a PGresult. 74 | * void PQclear(PGresult *res); */ 75 | } 76 | PQclear(my_result); 77 | /* we now create the wrapper and copy values */ 78 | PROTECT(rsHandle = RS_DBI_allocResultSet(conHandle)); 79 | result = RS_DBI_getResultSet(rsHandle); 80 | result->drvResultSet = (void *) NULL; 81 | result->rowCount = 0; 82 | result->isSelect = 0; 83 | result->rowsAffected = 0; 84 | result->completed = 1; 85 | UNPROTECT(1); 86 | return rsHandle; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /RPostgreSQL/src/RS-pgsql-pqexec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RS-PostgreSQL.c 3 | * 4 | * $Id$ 5 | * 6 | * This package was developed as a part of Summer of Code program organized by Google. 7 | * Thanks to David A. James & Saikat DebRoy, the authors of RMySQL package. 8 | * Code from RMySQL package was reused with the permission from the authors. 9 | * Also Thanks to my GSoC mentor Dirk Eddelbuettel for helping me in the development. 10 | * 11 | * Source Processed with: 12 | * indent -br -i4 -nut --line-length120 --comment-line-length120 --leave-preprocessor-space -npcs RS-PostgreSQL.c 13 | * 14 | */ 15 | 16 | #include 17 | #include "RS-PostgreSQL.h" 18 | 19 | 20 | /* R and S DataBase Interface to PostgreSQL 21 | * 22 | * C function library which can be used to run SQL queries 23 | * from inside of S4, Splus5.x, or R. 24 | * This Driver hooks R/S and PostgreSQL and implements the 25 | * the proposed RS-DBI generic database interface. 26 | * 27 | * For details refer 28 | * On R, 29 | * "R extensions" manual 30 | * On PostgreSQL, 31 | * "PostgreSQL 8.3.1 documentation" 32 | */ 33 | 34 | 35 | /* Execute (currently) one sql statement (INSERT, DELETE, SELECT, etc.), 36 | * set coercion type mappings between the server internal data types and 37 | * S classes. Don't drag the return value. 38 | */ 39 | 40 | SEXP 41 | RS_PostgreSQL_pqexec(Con_Handle * conHandle, s_object * statement) 42 | { 43 | S_EVALUATOR RS_DBI_connection * con; 44 | SEXP retval; 45 | PGconn *my_connection; 46 | PGresult *my_result; 47 | 48 | int is_select=0; 49 | char *dyn_statement; 50 | 51 | con = RS_DBI_getConnection(conHandle); 52 | my_connection = (PGconn *) con->drvConnection; 53 | dyn_statement = RS_DBI_copyString(CHR_EL(statement, 0)); 54 | 55 | /* Here is where we actually run the query */ 56 | 57 | /* Example: PGresult *PQexec(PGconn *conn, const char *command); */ 58 | 59 | my_result = PQexec(my_connection, dyn_statement); 60 | if (my_result == NULL) { 61 | char *errMsg; 62 | const char *omsg; 63 | size_t len; 64 | omsg = PQerrorMessage(my_connection); 65 | len = strlen(omsg); 66 | free(dyn_statement); 67 | errMsg = R_alloc(len + 80, 1); /* 80 should be larger than the length of "could not ..."*/ 68 | snprintf(errMsg, len + 80, "could not run statement: %s", omsg); 69 | RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); 70 | } 71 | 72 | 73 | if (PQresultStatus(my_result) == PGRES_TUPLES_OK) { 74 | is_select = TRUE; 75 | } 76 | if (PQresultStatus(my_result) == PGRES_COMMAND_OK) { 77 | is_select = FALSE; 78 | } 79 | 80 | if (strcmp(PQresultErrorMessage(my_result), "") != 0) { 81 | free(dyn_statement); 82 | char *errResultMsg; 83 | const char *omsg; 84 | size_t len; 85 | omsg = PQerrorMessage(my_connection); 86 | len = strlen(omsg); 87 | errResultMsg = R_alloc(len + 80, 1); /* 80 should be larger than the length of "could not ..."*/ 88 | snprintf(errResultMsg, len + 80, "could not Retrieve the result : %s", omsg); 89 | PQclear(my_result); 90 | RS_DBI_errorMessage(errResultMsg, RS_DBI_ERROR); 91 | } 92 | 93 | /* Frees the storage associated with a PGresult.*/ 94 | PQclear(my_result); 95 | free(dyn_statement); 96 | PROTECT(retval = allocVector(LGLSXP, 1)); 97 | LOGICAL(retval)[0] = is_select; 98 | UNPROTECT(1); 99 | return retval; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /RPostgreSQL/src/RS-pgsql-pqexecparams.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RS-pgsql-pqexecparam.c 3 | * 4 | * $Id: RS-pgsql-pqexecparam.c $ 5 | * 6 | */ 7 | 8 | #include 9 | #include "RS-PostgreSQL.h" 10 | #include 11 | 12 | 13 | /* Execute (currently) one sql statement (INSERT, DELETE, SELECT, etc.), 14 | * set coercion type mappings between the server internal data types and 15 | * S classes. Don't drag the return value. 16 | */ 17 | 18 | /* should call with .External */ 19 | SEXP 20 | RS_PostgreSQL_pqexecparams(SEXP args) 21 | { 22 | S_EVALUATOR RS_DBI_connection * con; 23 | SEXP retval; 24 | PGconn *my_connection; 25 | PGresult *my_result; 26 | R_len_t nparams; 27 | Con_Handle * conHandle; 28 | s_object * statement; 29 | s_object * params; 30 | int is_select=0; 31 | const char *dyn_statement; 32 | const char ** pqparams; 33 | RS_DBI_resultSet *result; 34 | 35 | conHandle = CADR(args); 36 | statement = CADDR(args); 37 | params = CADDDR(args); 38 | 39 | con = RS_DBI_getConnection(conHandle); 40 | my_connection = (PGconn *) con->drvConnection; 41 | dyn_statement = CHR_EL(statement, 0); 42 | nparams = length(params); 43 | pqparams = R_Calloc(nparams, const char*); 44 | 45 | for (R_len_t i = 0; i < nparams; i++){ 46 | pqparams[i] = CHR_EL(params, i); 47 | } 48 | 49 | /* http://www.postgresql.org/docs/9.2/static/libpq-exec.html 50 | * PGresult *PQexecParams(PGconn *conn, 51 | * const char *command, 52 | * int nParams, 53 | * const Oid *paramTypes, 54 | * const char * const *paramValues, 55 | * const int *paramLengths, 56 | * const int *paramFormats, 57 | * int resultFormat); 58 | */ 59 | my_result = PQexecParams(my_connection, dyn_statement, nparams, NULL, pqparams, NULL, NULL, 0); 60 | R_Free(pqparams); 61 | if (my_result == NULL) { 62 | char *errMsg; 63 | const char *omsg; 64 | size_t len; 65 | omsg = PQerrorMessage(my_connection); 66 | len = strlen(omsg); 67 | errMsg = R_alloc(len + 80, 1); /* 80 should be larger than the length of "could not ..."*/ 68 | snprintf(errMsg, len + 80, "could not run statement: %s", omsg); 69 | RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); 70 | } 71 | 72 | 73 | if (PQresultStatus(my_result) == PGRES_TUPLES_OK) { 74 | is_select = TRUE; 75 | } 76 | if (PQresultStatus(my_result) == PGRES_COMMAND_OK) { 77 | is_select = FALSE; 78 | } 79 | 80 | if (strcmp(PQresultErrorMessage(my_result), "") != 0) { 81 | 82 | char *errResultMsg; 83 | const char *omsg; 84 | size_t len; 85 | omsg = PQerrorMessage(my_connection); 86 | len = strlen(omsg); 87 | errResultMsg = R_alloc(len + 80, 1); /* 80 should be larger than the length of "could not ..."*/ 88 | snprintf(errResultMsg, len + 80, "could not Retrieve the result : %s", omsg); 89 | /* Frees the storage associated with a PGresult. 90 | * void PQclear(PGresult *res); */ 91 | PQclear(my_result); 92 | RS_DBI_errorMessage(errResultMsg, RS_DBI_ERROR); 93 | } 94 | 95 | /* we now create the wrapper and copy values */ 96 | PROTECT(retval = RS_DBI_allocResultSet(conHandle)); 97 | result = RS_DBI_getResultSet(retval); 98 | result->statement = RS_DBI_copyString(dyn_statement); 99 | result->drvResultSet = (void *) my_result; 100 | result->rowCount = 0; 101 | result->isSelect = is_select; 102 | 103 | /* Returns the number of rows affected by the SQL command. 104 | * char *PQcmdTuples(PGresult *res); 105 | */ 106 | 107 | if (!is_select) { 108 | result->rowsAffected = atoi(PQcmdTuples(my_result)); 109 | result->completed = 1; 110 | } 111 | else { 112 | result->rowsAffected = -1; 113 | result->completed = 0; 114 | } 115 | 116 | if (is_select) { 117 | result->fields = RS_PostgreSQL_createDataMappings(retval); 118 | } 119 | UNPROTECT(1); 120 | return retval; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /RPostgreSQL/src/install-sh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomoakin/RPostgreSQL/e8a32401d13549f8b1ffc8bc78ca572891495008/RPostgreSQL/src/install-sh -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/.gitignore: -------------------------------------------------------------------------------- 1 | /exports.list 2 | /chklocale.c 3 | /crypt.c 4 | /getaddrinfo.c 5 | /getpeereid.c 6 | /inet_aton.c 7 | /inet_net_ntop.c 8 | /noblock.c 9 | /open.c 10 | /pgstrcasecmp.c 11 | /pqsignal.c 12 | /snprintf.c 13 | /strerror.c 14 | /strlcpy.c 15 | /thread.c 16 | /win32error.c 17 | /win32setlocale.c 18 | /pgsleep.c 19 | /md5.c 20 | /ip.c 21 | /encnames.c 22 | /wchar.c 23 | /libpq.rc 24 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/COPYRIGHT: -------------------------------------------------------------------------------- 1 | PostgreSQL Database Management System 2 | (formerly known as Postgres, then as Postgres95) 3 | 4 | Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group 5 | 6 | Portions Copyright (c) 1994, The Regents of the University of California 7 | 8 | Permission to use, copy, modify, and distribute this software and its 9 | documentation for any purpose, without fee, and without a written agreement 10 | is hereby granted, provided that the above copyright notice and this 11 | paragraph and the following two paragraphs appear in all copies. 12 | 13 | IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 14 | DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE 17 | POSSIBILITY OF SUCH DAMAGE. 18 | 19 | THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 20 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 | ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO 23 | PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/Makefile.port.darwin: -------------------------------------------------------------------------------- 1 | AROPT = crs 2 | 3 | DLSUFFIX = .so 4 | 5 | ifdef PGXS 6 | BE_DLLLIBS = -bundle_loader $(bindir)/postgres 7 | else 8 | BE_DLLLIBS = -bundle_loader $(top_builddir)/src/backend/postgres 9 | endif 10 | 11 | # Rule for building a shared library from a single .o file 12 | %.so: %.o 13 | $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -bundle $(BE_DLLLIBS) -o $@ $< 14 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/Makefile.win32: -------------------------------------------------------------------------------- 1 | # src/makefiles/Makefile.win32 2 | 3 | # Use replacement include files for those missing on Win32 4 | override CPPFLAGS+="-I." 5 | 6 | ifdef PGXS 7 | BE_DLLLIBS= -L$(libdir) -lpostgres 8 | else 9 | BE_DLLLIBS= -L$(top_builddir)/src/backend -lpostgres 10 | endif 11 | 12 | AROPT = crs 13 | DLSUFFIX = .dll 14 | CFLAGS_SL = 15 | 16 | ifneq (,$(findstring backend,$(subdir))) 17 | ifeq (,$(findstring conversion_procs,$(subdir))) 18 | ifeq (,$(findstring snowball,$(subdir))) 19 | ifeq (,$(findstring libpqwalreceiver,$(subdir))) 20 | override CPPFLAGS+= -DBUILDING_DLL 21 | endif 22 | endif 23 | endif 24 | endif 25 | 26 | ifneq (,$(findstring timezone,$(subdir))) 27 | override CPPFLAGS+= -DBUILDING_DLL 28 | endif 29 | 30 | ifneq (,$(findstring ecpg/ecpglib,$(subdir))) 31 | override CPPFLAGS+= -DBUILDING_DLL 32 | endif 33 | 34 | # required by Python headers 35 | ifneq (,$(findstring src/pl/plpython,$(subdir))) 36 | override CPPFLAGS+= -DUSE_DL_IMPORT 37 | endif 38 | 39 | # special win32 headers are provided here 40 | ifdef PGXS 41 | override CPPFLAGS+= -I$(includedir_server)/port/win32 42 | endif 43 | 44 | # it is better to install shared-libraries anyway? 45 | # may be overriden with make MAKE_DLL=false install 46 | ifndef MAKE_DLL 47 | MAKE_DLL = true 48 | endif 49 | 50 | 51 | # Build rules to add versioninfo resources to win32 binaries 52 | 53 | WIN32RES += win32ver.o 54 | ifeq ($(PGFILESHLIB),1) 55 | PGFTYPE = VFT_DLL 56 | else 57 | PGFTYPE = VFT_APP 58 | endif 59 | ifneq (,$(PGAPPICON)) 60 | PGICOSTR = $(subst /,\/,IDI_ICON ICON \"$(top_builddir)/src/port/$(PGAPPICON).ico\") 61 | endif 62 | 63 | win32ver.rc: $(top_srcdir)/src/port/win32ver.rc 64 | sed -e 's;FILEDESC;$(PGFILEDESC);' -e 's;VFT_APP;$(PGFTYPE);' -e 's;_ICO_;$(PGICOSTR);' -e 's;\(VERSION.*\),0 *$$;\1,'`date '+%y%j' | sed 's/^0*//'`';' $< >$@ 65 | 66 | win32ver.o: win32ver.rc 67 | $(WINDRES) -i $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(srcdir) 68 | 69 | # Rule for building a shared library from a single .o file 70 | %.dll: %.o 71 | $(DLLTOOL) --export-all --output-def $*.def $< 72 | $(DLLWRAP) -o $@ --def $*.def $< $(LDFLAGS) $(LDFLAGS_SL) $(BE_DLLLIBS) 73 | rm -f $*.def 74 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/README: -------------------------------------------------------------------------------- 1 | src/interfaces/libpq/README 2 | 3 | This directory contains the C version of Libpq, the POSTGRES frontend library. 4 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/auth.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * auth.h 4 | * Definitions for network authentication routines 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/auth.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef AUTH_H 15 | #define AUTH_H 16 | 17 | #include "libpq/libpq-be.h" 18 | 19 | extern char *pg_krb_server_keyfile; 20 | extern char *pg_krb_srvnam; 21 | extern bool pg_krb_caseins_users; 22 | extern char *pg_krb_server_hostname; 23 | extern char *pg_krb_realm; 24 | 25 | extern void ClientAuthentication(Port *port); 26 | 27 | /* Hook for plugins to get control in ClientAuthentication() */ 28 | typedef void (*ClientAuthentication_hook_type) (Port *, int); 29 | extern PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook; 30 | 31 | #endif /* AUTH_H */ 32 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/be-fsstubs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * be-fsstubs.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/be-fsstubs.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef BE_FSSTUBS_H 15 | #define BE_FSSTUBS_H 16 | 17 | #include "fmgr.h" 18 | 19 | /* 20 | * LO functions available via pg_proc entries 21 | */ 22 | extern Datum lo_import(PG_FUNCTION_ARGS); 23 | extern Datum lo_import_with_oid(PG_FUNCTION_ARGS); 24 | extern Datum lo_export(PG_FUNCTION_ARGS); 25 | 26 | extern Datum lo_creat(PG_FUNCTION_ARGS); 27 | extern Datum lo_create(PG_FUNCTION_ARGS); 28 | 29 | extern Datum lo_open(PG_FUNCTION_ARGS); 30 | extern Datum lo_close(PG_FUNCTION_ARGS); 31 | 32 | extern Datum loread(PG_FUNCTION_ARGS); 33 | extern Datum lowrite(PG_FUNCTION_ARGS); 34 | 35 | extern Datum lo_lseek(PG_FUNCTION_ARGS); 36 | extern Datum lo_tell(PG_FUNCTION_ARGS); 37 | extern Datum lo_lseek64(PG_FUNCTION_ARGS); 38 | extern Datum lo_tell64(PG_FUNCTION_ARGS); 39 | extern Datum lo_unlink(PG_FUNCTION_ARGS); 40 | extern Datum lo_truncate(PG_FUNCTION_ARGS); 41 | extern Datum lo_truncate64(PG_FUNCTION_ARGS); 42 | 43 | /* 44 | * compatibility option for access control 45 | */ 46 | extern bool lo_compat_privileges; 47 | 48 | /* 49 | * These are not fmgr-callable, but are available to C code. 50 | * Probably these should have had the underscore-free names, 51 | * but too late now... 52 | */ 53 | extern int lo_read(int fd, char *buf, int len); 54 | extern int lo_write(int fd, const char *buf, int len); 55 | 56 | /* 57 | * Cleanup LOs at xact commit/abort 58 | */ 59 | extern void AtEOXact_LargeObject(bool isCommit); 60 | extern void AtEOSubXact_LargeObject(bool isCommit, SubTransactionId mySubid, 61 | SubTransactionId parentSubid); 62 | 63 | #endif /* BE_FSSTUBS_H */ 64 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/common/fe_memutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fe_memutils.h 3 | * memory management support for frontend code 4 | * 5 | * Copyright (c) 2003-2016, PostgreSQL Global Development Group 6 | * 7 | * src/include/common/fe_memutils.h 8 | */ 9 | #ifndef FE_MEMUTILS_H 10 | #define FE_MEMUTILS_H 11 | 12 | /* 13 | * Flags for pg_malloc_extended and palloc_extended, deliberately named 14 | * the same as the backend flags. 15 | */ 16 | #define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) not 17 | * actually used for frontends */ 18 | #define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ 19 | #define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ 20 | 21 | /* 22 | * "Safe" memory allocation functions --- these exit(1) on failure 23 | * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM) 24 | */ 25 | extern char *pg_strdup(const char *in); 26 | extern void *pg_malloc(size_t size); 27 | extern void *pg_malloc0(size_t size); 28 | extern void *pg_malloc_extended(size_t size, int flags); 29 | extern void *pg_realloc(void *pointer, size_t size); 30 | extern void pg_free(void *pointer); 31 | 32 | /* Equivalent functions, deliberately named the same as backend functions */ 33 | extern char *pstrdup(const char *in); 34 | extern void *palloc(Size size); 35 | extern void *palloc0(Size size); 36 | extern void *palloc_extended(Size size, int flags); 37 | extern void *repalloc(void *pointer, Size size); 38 | extern void pfree(void *pointer); 39 | 40 | /* sprintf into a palloc'd buffer --- these are in psprintf.c */ 41 | extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2); 42 | extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0); 43 | 44 | #endif /* FE_MEMUTILS_H */ 45 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/crypt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * crypt.h 4 | * Interface to libpq/crypt.c 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/crypt.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PG_CRYPT_H 14 | #define PG_CRYPT_H 15 | 16 | #include "libpq/libpq-be.h" 17 | 18 | extern int md5_crypt_verify(const Port *port, const char *user, 19 | char *client_pass); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/fe-auth.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * fe-auth.h 4 | * 5 | * Definitions for network authentication routines 6 | * 7 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/interfaces/libpq/fe-auth.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef FE_AUTH_H 15 | #define FE_AUTH_H 16 | 17 | #include "libpq-fe.h" 18 | #include "libpq-int.h" 19 | 20 | 21 | extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn); 22 | extern char *pg_fe_getauthname(PQExpBuffer errorMessage); 23 | 24 | #endif /* FE_AUTH_H */ 25 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/hba.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * hba.h 4 | * Interface to hba.c 5 | * 6 | * 7 | * src/include/libpq/hba.h 8 | * 9 | *------------------------------------------------------------------------- 10 | */ 11 | #ifndef HBA_H 12 | #define HBA_H 13 | 14 | #include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */ 15 | #include "nodes/pg_list.h" 16 | #include "regex/regex.h" 17 | 18 | 19 | typedef enum UserAuth 20 | { 21 | uaReject, 22 | uaImplicitReject, 23 | uaKrb5, 24 | uaTrust, 25 | uaIdent, 26 | uaPassword, 27 | uaMD5, 28 | uaGSS, 29 | uaSSPI, 30 | uaPAM, 31 | uaLDAP, 32 | uaCert, 33 | uaRADIUS, 34 | uaPeer 35 | } UserAuth; 36 | 37 | typedef enum IPCompareMethod 38 | { 39 | ipCmpMask, 40 | ipCmpSameHost, 41 | ipCmpSameNet, 42 | ipCmpAll 43 | } IPCompareMethod; 44 | 45 | typedef enum ConnType 46 | { 47 | ctLocal, 48 | ctHost, 49 | ctHostSSL, 50 | ctHostNoSSL 51 | } ConnType; 52 | 53 | typedef struct HbaLine 54 | { 55 | int linenumber; 56 | char *rawline; 57 | ConnType conntype; 58 | List *databases; 59 | List *roles; 60 | struct sockaddr_storage addr; 61 | struct sockaddr_storage mask; 62 | IPCompareMethod ip_cmp_method; 63 | char *hostname; 64 | UserAuth auth_method; 65 | 66 | char *usermap; 67 | char *pamservice; 68 | bool ldaptls; 69 | char *ldapserver; 70 | int ldapport; 71 | char *ldapbinddn; 72 | char *ldapbindpasswd; 73 | char *ldapsearchattribute; 74 | char *ldapbasedn; 75 | int ldapscope; 76 | char *ldapprefix; 77 | char *ldapsuffix; 78 | bool clientcert; 79 | char *krb_server_hostname; 80 | char *krb_realm; 81 | bool include_realm; 82 | char *radiusserver; 83 | char *radiussecret; 84 | char *radiusidentifier; 85 | int radiusport; 86 | } HbaLine; 87 | 88 | typedef struct IdentLine 89 | { 90 | int linenumber; 91 | 92 | char *usermap; 93 | char *ident_user; 94 | char *pg_role; 95 | regex_t re; 96 | } IdentLine; 97 | 98 | /* kluge to avoid including libpq/libpq-be.h here */ 99 | typedef struct Port hbaPort; 100 | 101 | extern bool load_hba(void); 102 | extern bool load_ident(void); 103 | extern void hba_getauthmethod(hbaPort *port); 104 | extern int check_usermap(const char *usermap_name, 105 | const char *pg_role, const char *auth_user, 106 | bool case_sensitive); 107 | extern bool pg_isblank(const char c); 108 | 109 | #endif /* HBA_H */ 110 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/inet_aton.c: -------------------------------------------------------------------------------- 1 | /* src/port/inet_aton.c 2 | * 3 | * This inet_aton() function was taken from the GNU C library and 4 | * incorporated into Postgres for those systems which do not have this 5 | * routine in their standard C libraries. 6 | * 7 | * The function was been extracted whole from the file inet_aton.c in 8 | * Release 5.3.12 of the Linux C library, which is derived from the 9 | * GNU C library, by Bryan Henderson in October 1996. The copyright 10 | * notice from that file is below. 11 | */ 12 | 13 | /* 14 | * Copyright (c) 1983, 1990, 1993 15 | * The Regents of the University of California. All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions 19 | * are met: 20 | * 1. Redistributions of source code must retain the above copyright 21 | * notice, this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 3. Neither the name of the University nor the names of its contributors 26 | * may be used to endorse or promote products derived from this software 27 | * without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 | * SUCH DAMAGE. */ 40 | 41 | #include "c.h" 42 | 43 | #include 44 | #include 45 | 46 | /* 47 | * Check whether "cp" is a valid ascii representation 48 | * of an Internet address and convert to a binary address. 49 | * Returns 1 if the address is valid, 0 if not. 50 | * This replaces inet_addr, the return value from which 51 | * cannot distinguish between failure and a local broadcast address. 52 | */ 53 | int 54 | inet_aton(const char *cp, struct in_addr * addr) 55 | { 56 | unsigned int val; 57 | int base, 58 | n; 59 | char c; 60 | u_int parts[4]; 61 | u_int *pp = parts; 62 | 63 | for (;;) 64 | { 65 | /* 66 | * Collect number up to ``.''. Values are specified as for C: 0x=hex, 67 | * 0=octal, other=decimal. 68 | */ 69 | val = 0; 70 | base = 10; 71 | if (*cp == '0') 72 | { 73 | if (*++cp == 'x' || *cp == 'X') 74 | base = 16, cp++; 75 | else 76 | base = 8; 77 | } 78 | while ((c = *cp) != '\0') 79 | { 80 | if (isdigit((unsigned char) c)) 81 | { 82 | val = (val * base) + (c - '0'); 83 | cp++; 84 | continue; 85 | } 86 | if (base == 16 && isxdigit((unsigned char) c)) 87 | { 88 | val = (val << 4) + 89 | (c + 10 - (islower((unsigned char) c) ? 'a' : 'A')); 90 | cp++; 91 | continue; 92 | } 93 | break; 94 | } 95 | if (*cp == '.') 96 | { 97 | /* 98 | * Internet format: a.b.c.d a.b.c (with c treated as 16-bits) 99 | * a.b (with b treated as 24 bits) 100 | */ 101 | if (pp >= parts + 3 || val > 0xff) 102 | return 0; 103 | *pp++ = val, cp++; 104 | } 105 | else 106 | break; 107 | } 108 | 109 | /* 110 | * Check for trailing junk. 111 | */ 112 | while (*cp) 113 | if (!isspace((unsigned char) *cp++)) 114 | return 0; 115 | 116 | /* 117 | * Concoct the address according to the number of parts specified. 118 | */ 119 | n = pp - parts + 1; 120 | switch (n) 121 | { 122 | 123 | case 1: /* a -- 32 bits */ 124 | break; 125 | 126 | case 2: /* a.b -- 8.24 bits */ 127 | if (val > 0xffffff) 128 | return 0; 129 | val |= parts[0] << 24; 130 | break; 131 | 132 | case 3: /* a.b.c -- 8.8.16 bits */ 133 | if (val > 0xffff) 134 | return 0; 135 | val |= (parts[0] << 24) | (parts[1] << 16); 136 | break; 137 | 138 | case 4: /* a.b.c.d -- 8.8.8.8 bits */ 139 | if (val > 0xff) 140 | return 0; 141 | val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); 142 | break; 143 | } 144 | if (addr) 145 | addr->s_addr = htonl(val); 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/ip.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ip.h 4 | * Definitions for IPv6-aware network access. 5 | * 6 | * These definitions are used by both frontend and backend code. Be careful 7 | * what you include here! 8 | * 9 | * Copyright (c) 2003-2016, PostgreSQL Global Development Group 10 | * 11 | * src/include/libpq/ip.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef IP_H 16 | #define IP_H 17 | 18 | #include "getaddrinfo.h" /* pgrminclude ignore */ 19 | #include "libpq/pqcomm.h" /* pgrminclude ignore */ 20 | 21 | 22 | #ifdef HAVE_UNIX_SOCKETS 23 | #define IS_AF_UNIX(fam) ((fam) == AF_UNIX) 24 | #else 25 | #define IS_AF_UNIX(fam) (0) 26 | #endif 27 | 28 | typedef void (*PgIfAddrCallback) (struct sockaddr * addr, 29 | struct sockaddr * netmask, 30 | void *cb_data); 31 | 32 | extern int pg_getaddrinfo_all(const char *hostname, const char *servname, 33 | const struct addrinfo * hintp, 34 | struct addrinfo ** result); 35 | extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai); 36 | 37 | extern int pg_getnameinfo_all(const struct sockaddr_storage * addr, int salen, 38 | char *node, int nodelen, 39 | char *service, int servicelen, 40 | int flags); 41 | 42 | extern int pg_range_sockaddr(const struct sockaddr_storage * addr, 43 | const struct sockaddr_storage * netaddr, 44 | const struct sockaddr_storage * netmask); 45 | 46 | extern int pg_sockaddr_cidr_mask(struct sockaddr_storage * mask, 47 | char *numbits, int family); 48 | 49 | extern int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data); 50 | 51 | #endif /* IP_H */ 52 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq-dist.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 9,6,3,17128 5 | PRODUCTVERSION 9,6,3,17128 6 | FILEFLAGSMASK 0x3fL 7 | FILEFLAGS 0 8 | FILEOS VOS__WINDOWS32 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE 0x0L 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904B0" 15 | BEGIN 16 | VALUE "CompanyName", "\0" 17 | VALUE "FileDescription", "PostgreSQL Access Library\0" 18 | VALUE "FileVersion", "9.6.3\0" 19 | VALUE "InternalName", "libpq\0" 20 | VALUE "LegalCopyright", "Copyright (C) 2016\0" 21 | VALUE "LegalTrademarks", "\0" 22 | VALUE "OriginalFilename", "libpq.dll\0" 23 | VALUE "ProductName", "PostgreSQL\0" 24 | VALUE "ProductVersion", "9.6.3\0" 25 | END 26 | END 27 | BLOCK "VarFileInfo" 28 | BEGIN 29 | VALUE "Translation", 0x409, 1200 30 | END 31 | END 32 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq-events.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * libpq-events.h 4 | * This file contains definitions that are useful to applications 5 | * that invoke the libpq "events" API, but are not interesting to 6 | * ordinary users of libpq. 7 | * 8 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 9 | * Portions Copyright (c) 1994, Regents of the University of California 10 | * 11 | * src/interfaces/libpq/libpq-events.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | 16 | #ifndef LIBPQ_EVENTS_H 17 | #define LIBPQ_EVENTS_H 18 | 19 | #include "libpq-fe.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | /* Callback Event Ids */ 27 | typedef enum 28 | { 29 | PGEVT_REGISTER, 30 | PGEVT_CONNRESET, 31 | PGEVT_CONNDESTROY, 32 | PGEVT_RESULTCREATE, 33 | PGEVT_RESULTCOPY, 34 | PGEVT_RESULTDESTROY 35 | } PGEventId; 36 | 37 | typedef struct 38 | { 39 | PGconn *conn; 40 | } PGEventRegister; 41 | 42 | typedef struct 43 | { 44 | PGconn *conn; 45 | } PGEventConnReset; 46 | 47 | typedef struct 48 | { 49 | PGconn *conn; 50 | } PGEventConnDestroy; 51 | 52 | typedef struct 53 | { 54 | PGconn *conn; 55 | PGresult *result; 56 | } PGEventResultCreate; 57 | 58 | typedef struct 59 | { 60 | const PGresult *src; 61 | PGresult *dest; 62 | } PGEventResultCopy; 63 | 64 | typedef struct 65 | { 66 | PGresult *result; 67 | } PGEventResultDestroy; 68 | 69 | typedef int (*PGEventProc) (PGEventId evtId, void *evtInfo, void *passThrough); 70 | 71 | /* Registers an event proc with the given PGconn. */ 72 | extern int PQregisterEventProc(PGconn *conn, PGEventProc proc, 73 | const char *name, void *passThrough); 74 | 75 | /* Sets the PGconn instance data for the provided proc to data. */ 76 | extern int PQsetInstanceData(PGconn *conn, PGEventProc proc, void *data); 77 | 78 | /* Gets the PGconn instance data for the provided proc. */ 79 | extern void *PQinstanceData(const PGconn *conn, PGEventProc proc); 80 | 81 | /* Sets the PGresult instance data for the provided proc to data. */ 82 | extern int PQresultSetInstanceData(PGresult *result, PGEventProc proc, void *data); 83 | 84 | /* Gets the PGresult instance data for the provided proc. */ 85 | extern void *PQresultInstanceData(const PGresult *result, PGEventProc proc); 86 | 87 | /* Fires RESULTCREATE events for an application-created PGresult. */ 88 | extern int PQfireResultCreateEvents(PGconn *conn, PGresult *res); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* LIBPQ_EVENTS_H */ 95 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq-fs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * libpq-fs.h 4 | * definitions for using Inversion file system routines (ie, large objects) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/libpq-fs.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef LIBPQ_FS_H 15 | #define LIBPQ_FS_H 16 | 17 | /* 18 | * Read/write mode flags for inversion (large object) calls 19 | */ 20 | 21 | #define INV_WRITE 0x00020000 22 | #define INV_READ 0x00040000 23 | 24 | #endif /* LIBPQ_FS_H */ 25 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * libpq.h 4 | * POSTGRES LIBPQ buffer structure definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/libpq.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef LIBPQ_H 15 | #define LIBPQ_H 16 | 17 | #include 18 | #include 19 | 20 | #include "lib/stringinfo.h" 21 | #include "libpq/libpq-be.h" 22 | 23 | /* ---------------- 24 | * PQArgBlock 25 | * Information (pointer to array of this structure) required 26 | * for the PQfn() call. (This probably ought to go somewhere else...) 27 | * ---------------- 28 | */ 29 | typedef struct 30 | { 31 | int len; 32 | int isint; 33 | union 34 | { 35 | int *ptr; /* can't use void (dec compiler barfs) */ 36 | int integer; 37 | } u; 38 | } PQArgBlock; 39 | 40 | /* 41 | * External functions. 42 | */ 43 | 44 | /* 45 | * prototypes for functions in pqcomm.c 46 | */ 47 | extern int StreamServerPort(int family, char *hostName, 48 | unsigned short portNumber, char *unixSocketDir, 49 | pgsocket ListenSocket[], int MaxListen); 50 | extern int StreamConnection(pgsocket server_fd, Port *port); 51 | extern void StreamClose(pgsocket sock); 52 | extern void TouchSocketFiles(void); 53 | extern void pq_init(void); 54 | extern void pq_comm_reset(void); 55 | extern int pq_getbytes(char *s, size_t len); 56 | extern int pq_getstring(StringInfo s); 57 | extern int pq_getmessage(StringInfo s, int maxlen); 58 | extern int pq_getbyte(void); 59 | extern int pq_peekbyte(void); 60 | extern int pq_getbyte_if_available(unsigned char *c); 61 | extern int pq_putbytes(const char *s, size_t len); 62 | extern int pq_flush(void); 63 | extern int pq_flush_if_writable(void); 64 | extern bool pq_is_send_pending(void); 65 | extern int pq_putmessage(char msgtype, const char *s, size_t len); 66 | extern void pq_putmessage_noblock(char msgtype, const char *s, size_t len); 67 | extern void pq_startcopyout(void); 68 | extern void pq_endcopyout(bool errorAbort); 69 | 70 | /* 71 | * prototypes for functions in be-secure.c 72 | */ 73 | extern char *ssl_cert_file; 74 | extern char *ssl_key_file; 75 | extern char *ssl_ca_file; 76 | extern char *ssl_crl_file; 77 | 78 | extern int secure_initialize(void); 79 | extern bool secure_loaded_verify_locations(void); 80 | extern void secure_destroy(void); 81 | extern int secure_open_server(Port *port); 82 | extern void secure_close(Port *port); 83 | extern ssize_t secure_read(Port *port, void *ptr, size_t len); 84 | extern ssize_t secure_write(Port *port, void *ptr, size_t len); 85 | 86 | #endif /* LIBPQ_H */ 87 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq.pc: -------------------------------------------------------------------------------- 1 | Name: libpq 2 | Description: PostgreSQL libpq library 3 | Url: http://www.postgresql.org/ 4 | Version: 9.6.3 5 | Requires: 6 | Requires.private: 7 | Cflags: -I/usr/local/pgsql/include 8 | Libs: -L/usr/local/pgsql/lib -lpq 9 | Libs.private: 10 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 9,6,3,17172 5 | PRODUCTVERSION 9,6,3,17172 6 | FILEFLAGSMASK 0x3fL 7 | FILEFLAGS 0 8 | FILEOS VOS__WINDOWS32 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE 0x0L 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904B0" 15 | BEGIN 16 | VALUE "CompanyName", "\0" 17 | VALUE "FileDescription", "PostgreSQL Access Library\0" 18 | VALUE "FileVersion", "9.6.3\0" 19 | VALUE "InternalName", "libpq\0" 20 | VALUE "LegalCopyright", "Copyright (C) 2016\0" 21 | VALUE "LegalTrademarks", "\0" 22 | VALUE "OriginalFilename", "libpq.dll\0" 23 | VALUE "ProductName", "PostgreSQL\0" 24 | VALUE "ProductVersion", "9.6.3\0" 25 | END 26 | END 27 | BLOCK "VarFileInfo" 28 | BEGIN 29 | VALUE "Translation", 0x409, 1200 30 | END 31 | END 32 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq.rc.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | VS_VERSION_INFO VERSIONINFO 4 | FILEVERSION 9,6,3,0 5 | PRODUCTVERSION 9,6,3,0 6 | FILEFLAGSMASK 0x3fL 7 | FILEFLAGS 0 8 | FILEOS VOS__WINDOWS32 9 | FILETYPE VFT_DLL 10 | FILESUBTYPE 0x0L 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "040904B0" 15 | BEGIN 16 | VALUE "CompanyName", "\0" 17 | VALUE "FileDescription", "PostgreSQL Access Library\0" 18 | VALUE "FileVersion", "9.6.3\0" 19 | VALUE "InternalName", "libpq\0" 20 | VALUE "LegalCopyright", "Copyright (C) 2016\0" 21 | VALUE "LegalTrademarks", "\0" 22 | VALUE "OriginalFilename", "libpq.dll\0" 23 | VALUE "ProductName", "PostgreSQL\0" 24 | VALUE "ProductVersion", "9.6.3\0" 25 | END 26 | END 27 | BLOCK "VarFileInfo" 28 | BEGIN 29 | VALUE "Translation", 0x409, 1200 30 | END 31 | END 32 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/auth.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * auth.h 4 | * Definitions for network authentication routines 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/auth.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef AUTH_H 15 | #define AUTH_H 16 | 17 | #include "libpq/libpq-be.h" 18 | 19 | extern char *pg_krb_server_keyfile; 20 | extern char *pg_krb_srvnam; 21 | extern bool pg_krb_caseins_users; 22 | extern char *pg_krb_server_hostname; 23 | extern char *pg_krb_realm; 24 | 25 | extern void ClientAuthentication(Port *port); 26 | 27 | /* Hook for plugins to get control in ClientAuthentication() */ 28 | typedef void (*ClientAuthentication_hook_type) (Port *, int); 29 | extern PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook; 30 | 31 | #endif /* AUTH_H */ 32 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/be-fsstubs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * be-fsstubs.h 4 | * 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/be-fsstubs.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef BE_FSSTUBS_H 15 | #define BE_FSSTUBS_H 16 | 17 | #include "fmgr.h" 18 | 19 | /* 20 | * LO functions available via pg_proc entries 21 | */ 22 | extern Datum lo_import(PG_FUNCTION_ARGS); 23 | extern Datum lo_import_with_oid(PG_FUNCTION_ARGS); 24 | extern Datum lo_export(PG_FUNCTION_ARGS); 25 | 26 | extern Datum lo_creat(PG_FUNCTION_ARGS); 27 | extern Datum lo_create(PG_FUNCTION_ARGS); 28 | 29 | extern Datum lo_open(PG_FUNCTION_ARGS); 30 | extern Datum lo_close(PG_FUNCTION_ARGS); 31 | 32 | extern Datum loread(PG_FUNCTION_ARGS); 33 | extern Datum lowrite(PG_FUNCTION_ARGS); 34 | 35 | extern Datum lo_lseek(PG_FUNCTION_ARGS); 36 | extern Datum lo_tell(PG_FUNCTION_ARGS); 37 | extern Datum lo_lseek64(PG_FUNCTION_ARGS); 38 | extern Datum lo_tell64(PG_FUNCTION_ARGS); 39 | extern Datum lo_unlink(PG_FUNCTION_ARGS); 40 | extern Datum lo_truncate(PG_FUNCTION_ARGS); 41 | extern Datum lo_truncate64(PG_FUNCTION_ARGS); 42 | 43 | /* 44 | * compatibility option for access control 45 | */ 46 | extern bool lo_compat_privileges; 47 | 48 | /* 49 | * These are not fmgr-callable, but are available to C code. 50 | * Probably these should have had the underscore-free names, 51 | * but too late now... 52 | */ 53 | extern int lo_read(int fd, char *buf, int len); 54 | extern int lo_write(int fd, const char *buf, int len); 55 | 56 | /* 57 | * Cleanup LOs at xact commit/abort 58 | */ 59 | extern void AtEOXact_LargeObject(bool isCommit); 60 | extern void AtEOSubXact_LargeObject(bool isCommit, SubTransactionId mySubid, 61 | SubTransactionId parentSubid); 62 | 63 | #endif /* BE_FSSTUBS_H */ 64 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/crypt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * crypt.h 4 | * Interface to libpq/crypt.c 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/crypt.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PG_CRYPT_H 14 | #define PG_CRYPT_H 15 | 16 | #include "libpq/libpq-be.h" 17 | 18 | extern int md5_crypt_verify(const Port *port, const char *user, 19 | char *client_pass); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/hba.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * hba.h 4 | * Interface to hba.c 5 | * 6 | * 7 | * src/include/libpq/hba.h 8 | * 9 | *------------------------------------------------------------------------- 10 | */ 11 | #ifndef HBA_H 12 | #define HBA_H 13 | 14 | #include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */ 15 | #include "nodes/pg_list.h" 16 | #include "regex/regex.h" 17 | 18 | 19 | typedef enum UserAuth 20 | { 21 | uaReject, 22 | uaImplicitReject, 23 | uaKrb5, 24 | uaTrust, 25 | uaIdent, 26 | uaPassword, 27 | uaMD5, 28 | uaGSS, 29 | uaSSPI, 30 | uaPAM, 31 | uaLDAP, 32 | uaCert, 33 | uaRADIUS, 34 | uaPeer 35 | } UserAuth; 36 | 37 | typedef enum IPCompareMethod 38 | { 39 | ipCmpMask, 40 | ipCmpSameHost, 41 | ipCmpSameNet, 42 | ipCmpAll 43 | } IPCompareMethod; 44 | 45 | typedef enum ConnType 46 | { 47 | ctLocal, 48 | ctHost, 49 | ctHostSSL, 50 | ctHostNoSSL 51 | } ConnType; 52 | 53 | typedef struct HbaLine 54 | { 55 | int linenumber; 56 | char *rawline; 57 | ConnType conntype; 58 | List *databases; 59 | List *roles; 60 | struct sockaddr_storage addr; 61 | struct sockaddr_storage mask; 62 | IPCompareMethod ip_cmp_method; 63 | char *hostname; 64 | UserAuth auth_method; 65 | 66 | char *usermap; 67 | char *pamservice; 68 | bool ldaptls; 69 | char *ldapserver; 70 | int ldapport; 71 | char *ldapbinddn; 72 | char *ldapbindpasswd; 73 | char *ldapsearchattribute; 74 | char *ldapbasedn; 75 | int ldapscope; 76 | char *ldapprefix; 77 | char *ldapsuffix; 78 | bool clientcert; 79 | char *krb_server_hostname; 80 | char *krb_realm; 81 | bool include_realm; 82 | char *radiusserver; 83 | char *radiussecret; 84 | char *radiusidentifier; 85 | int radiusport; 86 | } HbaLine; 87 | 88 | typedef struct IdentLine 89 | { 90 | int linenumber; 91 | 92 | char *usermap; 93 | char *ident_user; 94 | char *pg_role; 95 | regex_t re; 96 | } IdentLine; 97 | 98 | /* kluge to avoid including libpq/libpq-be.h here */ 99 | typedef struct Port hbaPort; 100 | 101 | extern bool load_hba(void); 102 | extern bool load_ident(void); 103 | extern void hba_getauthmethod(hbaPort *port); 104 | extern int check_usermap(const char *usermap_name, 105 | const char *pg_role, const char *auth_user, 106 | bool case_sensitive); 107 | extern bool pg_isblank(const char c); 108 | 109 | #endif /* HBA_H */ 110 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/ip.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * ip.h 4 | * Definitions for IPv6-aware network access. 5 | * 6 | * These definitions are used by both frontend and backend code. Be careful 7 | * what you include here! 8 | * 9 | * Copyright (c) 2003-2016, PostgreSQL Global Development Group 10 | * 11 | * src/include/libpq/ip.h 12 | * 13 | *------------------------------------------------------------------------- 14 | */ 15 | #ifndef IP_H 16 | #define IP_H 17 | 18 | #include "getaddrinfo.h" /* pgrminclude ignore */ 19 | #include "libpq/pqcomm.h" /* pgrminclude ignore */ 20 | 21 | 22 | #ifdef HAVE_UNIX_SOCKETS 23 | #define IS_AF_UNIX(fam) ((fam) == AF_UNIX) 24 | #else 25 | #define IS_AF_UNIX(fam) (0) 26 | #endif 27 | 28 | typedef void (*PgIfAddrCallback) (struct sockaddr * addr, 29 | struct sockaddr * netmask, 30 | void *cb_data); 31 | 32 | extern int pg_getaddrinfo_all(const char *hostname, const char *servname, 33 | const struct addrinfo * hintp, 34 | struct addrinfo ** result); 35 | extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai); 36 | 37 | extern int pg_getnameinfo_all(const struct sockaddr_storage * addr, int salen, 38 | char *node, int nodelen, 39 | char *service, int servicelen, 40 | int flags); 41 | 42 | extern int pg_range_sockaddr(const struct sockaddr_storage * addr, 43 | const struct sockaddr_storage * netaddr, 44 | const struct sockaddr_storage * netmask); 45 | 46 | extern int pg_sockaddr_cidr_mask(struct sockaddr_storage * mask, 47 | char *numbits, int family); 48 | 49 | extern int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data); 50 | 51 | #endif /* IP_H */ 52 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/libpq-fs.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * libpq-fs.h 4 | * definitions for using Inversion file system routines (ie, large objects) 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/libpq-fs.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef LIBPQ_FS_H 15 | #define LIBPQ_FS_H 16 | 17 | /* 18 | * Read/write mode flags for inversion (large object) calls 19 | */ 20 | 21 | #define INV_WRITE 0x00020000 22 | #define INV_READ 0x00040000 23 | 24 | #endif /* LIBPQ_FS_H */ 25 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/libpq.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * libpq.h 4 | * POSTGRES LIBPQ buffer structure definitions. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * src/include/libpq/libpq.h 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | #ifndef LIBPQ_H 15 | #define LIBPQ_H 16 | 17 | #include 18 | #include 19 | 20 | #include "lib/stringinfo.h" 21 | #include "libpq/libpq-be.h" 22 | 23 | /* ---------------- 24 | * PQArgBlock 25 | * Information (pointer to array of this structure) required 26 | * for the PQfn() call. (This probably ought to go somewhere else...) 27 | * ---------------- 28 | */ 29 | typedef struct 30 | { 31 | int len; 32 | int isint; 33 | union 34 | { 35 | int *ptr; /* can't use void (dec compiler barfs) */ 36 | int integer; 37 | } u; 38 | } PQArgBlock; 39 | 40 | /* 41 | * External functions. 42 | */ 43 | 44 | /* 45 | * prototypes for functions in pqcomm.c 46 | */ 47 | extern int StreamServerPort(int family, char *hostName, 48 | unsigned short portNumber, char *unixSocketDir, 49 | pgsocket ListenSocket[], int MaxListen); 50 | extern int StreamConnection(pgsocket server_fd, Port *port); 51 | extern void StreamClose(pgsocket sock); 52 | extern void TouchSocketFiles(void); 53 | extern void pq_init(void); 54 | extern void pq_comm_reset(void); 55 | extern int pq_getbytes(char *s, size_t len); 56 | extern int pq_getstring(StringInfo s); 57 | extern int pq_getmessage(StringInfo s, int maxlen); 58 | extern int pq_getbyte(void); 59 | extern int pq_peekbyte(void); 60 | extern int pq_getbyte_if_available(unsigned char *c); 61 | extern int pq_putbytes(const char *s, size_t len); 62 | extern int pq_flush(void); 63 | extern int pq_flush_if_writable(void); 64 | extern bool pq_is_send_pending(void); 65 | extern int pq_putmessage(char msgtype, const char *s, size_t len); 66 | extern void pq_putmessage_noblock(char msgtype, const char *s, size_t len); 67 | extern void pq_startcopyout(void); 68 | extern void pq_endcopyout(bool errorAbort); 69 | 70 | /* 71 | * prototypes for functions in be-secure.c 72 | */ 73 | extern char *ssl_cert_file; 74 | extern char *ssl_key_file; 75 | extern char *ssl_ca_file; 76 | extern char *ssl_crl_file; 77 | 78 | extern int secure_initialize(void); 79 | extern bool secure_loaded_verify_locations(void); 80 | extern void secure_destroy(void); 81 | extern int secure_open_server(Port *port); 82 | extern void secure_close(Port *port); 83 | extern ssize_t secure_read(Port *port, void *ptr, size_t len); 84 | extern ssize_t secure_write(Port *port, void *ptr, size_t len); 85 | 86 | #endif /* LIBPQ_H */ 87 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/md5.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * md5.h 4 | * Interface to libpq/md5.c 5 | * 6 | * These definitions are needed by both frontend and backend code to work 7 | * with MD5-encrypted passwords. 8 | * 9 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 10 | * Portions Copyright (c) 1994, Regents of the University of California 11 | * 12 | * src/include/libpq/md5.h 13 | * 14 | *------------------------------------------------------------------------- 15 | */ 16 | #ifndef PG_MD5_H 17 | #define PG_MD5_H 18 | 19 | #define MD5_PASSWD_LEN 35 20 | 21 | #define isMD5(passwd) (strncmp(passwd, "md5", 3) == 0 && \ 22 | strlen(passwd) == MD5_PASSWD_LEN) 23 | 24 | 25 | extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum); 26 | extern bool pg_md5_binary(const void *buff, size_t len, void *outbuf); 27 | extern bool pg_md5_encrypt(const char *passwd, const char *salt, 28 | size_t salt_len, char *buf); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/pqformat.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqformat.h 4 | * Definitions for formatting and parsing frontend/backend messages 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/pqformat.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PQFORMAT_H 14 | #define PQFORMAT_H 15 | 16 | #include "lib/stringinfo.h" 17 | 18 | extern void pq_beginmessage(StringInfo buf, char msgtype); 19 | extern void pq_sendbyte(StringInfo buf, int byt); 20 | extern void pq_sendbytes(StringInfo buf, const char *data, int datalen); 21 | extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen, 22 | bool countincludesself); 23 | extern void pq_sendtext(StringInfo buf, const char *str, int slen); 24 | extern void pq_sendstring(StringInfo buf, const char *str); 25 | extern void pq_send_ascii_string(StringInfo buf, const char *str); 26 | extern void pq_sendint(StringInfo buf, int i, int b); 27 | extern void pq_sendint64(StringInfo buf, int64 i); 28 | extern void pq_sendfloat4(StringInfo buf, float4 f); 29 | extern void pq_sendfloat8(StringInfo buf, float8 f); 30 | extern void pq_endmessage(StringInfo buf); 31 | 32 | extern void pq_begintypsend(StringInfo buf); 33 | extern bytea *pq_endtypsend(StringInfo buf); 34 | 35 | extern void pq_puttextmessage(char msgtype, const char *str); 36 | extern void pq_putemptymessage(char msgtype); 37 | 38 | extern int pq_getmsgbyte(StringInfo msg); 39 | extern unsigned int pq_getmsgint(StringInfo msg, int b); 40 | extern int64 pq_getmsgint64(StringInfo msg); 41 | extern float4 pq_getmsgfloat4(StringInfo msg); 42 | extern float8 pq_getmsgfloat8(StringInfo msg); 43 | extern const char *pq_getmsgbytes(StringInfo msg, int datalen); 44 | extern void pq_copymsgbytes(StringInfo msg, char *buf, int datalen); 45 | extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes); 46 | extern const char *pq_getmsgstring(StringInfo msg); 47 | extern void pq_getmsgend(StringInfo msg); 48 | 49 | #endif /* PQFORMAT_H */ 50 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/libpq/pqsignal.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqsignal.h 4 | * Backend signal(2) support (see also src/port/pqsignal.c) 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/pqsignal.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PQSIGNAL_H 14 | #define PQSIGNAL_H 15 | 16 | #include 17 | 18 | #ifdef HAVE_SIGPROCMASK 19 | extern sigset_t UnBlockSig, 20 | BlockSig, 21 | StartupBlockSig; 22 | 23 | #define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) 24 | #else /* not HAVE_SIGPROCMASK */ 25 | extern int UnBlockSig, 26 | BlockSig, 27 | StartupBlockSig; 28 | 29 | #ifndef WIN32 30 | #define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) 31 | #else 32 | #define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) 33 | int pqsigsetmask(int mask); 34 | #endif 35 | 36 | #define sigaddset(set, signum) (*(set) |= (sigmask(signum))) 37 | #define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) 38 | #endif /* not HAVE_SIGPROCMASK */ 39 | 40 | extern void pqinitmask(void); 41 | 42 | #endif /* PQSIGNAL_H */ 43 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/md5.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * md5.h 4 | * Interface to libpq/md5.c 5 | * 6 | * These definitions are needed by both frontend and backend code to work 7 | * with MD5-encrypted passwords. 8 | * 9 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 10 | * Portions Copyright (c) 1994, Regents of the University of California 11 | * 12 | * src/include/libpq/md5.h 13 | * 14 | *------------------------------------------------------------------------- 15 | */ 16 | #ifndef PG_MD5_H 17 | #define PG_MD5_H 18 | 19 | #define MD5_PASSWD_LEN 35 20 | 21 | #define isMD5(passwd) (strncmp(passwd, "md5", 3) == 0 && \ 22 | strlen(passwd) == MD5_PASSWD_LEN) 23 | 24 | 25 | extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum); 26 | extern bool pg_md5_binary(const void *buff, size_t len, void *outbuf); 27 | extern bool pg_md5_encrypt(const char *passwd, const char *salt, 28 | size_t salt_len, char *buf); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/nls.mk: -------------------------------------------------------------------------------- 1 | # src/interfaces/libpq/nls.mk 2 | CATALOG_NAME = libpq 3 | AVAIL_LANGUAGES = cs de es fr it ja ko pl pt_BR ru tr zh_CN zh_TW 4 | GETTEXT_FILES = fe-auth.c fe-connect.c fe-exec.c fe-lobj.c fe-misc.c fe-protocol2.c fe-protocol3.c fe-secure.c fe-secure-openssl.c win32.c 5 | GETTEXT_TRIGGERS = libpq_gettext pqInternalNotice:2 6 | GETTEXT_FLAGS = libpq_gettext:1:pass-c-format pqInternalNotice:2:c-format 7 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/noblock.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * noblock.c 4 | * set a file descriptor as blocking or non-blocking 5 | * 6 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * IDENTIFICATION 10 | * src/port/noblock.c 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | #include "c.h" 16 | 17 | #include 18 | 19 | 20 | /* 21 | * Put socket into nonblock mode. 22 | * Returns true on success, false on failure. 23 | */ 24 | bool 25 | pg_set_noblock(pgsocket sock) 26 | { 27 | #if !defined(WIN32) 28 | int flags; 29 | 30 | flags = fcntl(sock, F_GETFL); 31 | if (flags < 0) 32 | return false; 33 | if (fcntl(sock, F_SETFL, (flags | O_NONBLOCK)) == -1) 34 | return false; 35 | return true; 36 | #else 37 | unsigned long ioctlsocket_ret = 1; 38 | 39 | /* Returns non-0 on failure, while fcntl() returns -1 on failure */ 40 | return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0); 41 | #endif 42 | } 43 | 44 | /* 45 | * Put socket into blocking mode. 46 | * Returns true on success, false on failure. 47 | */ 48 | bool 49 | pg_set_block(pgsocket sock) 50 | { 51 | #if !defined(WIN32) 52 | int flags; 53 | 54 | flags = fcntl(sock, F_GETFL); 55 | if (flags < 0) 56 | return false; 57 | if (fcntl(sock, F_SETFL, (flags & ~O_NONBLOCK)) == -1) 58 | return false; 59 | return true; 60 | #else 61 | unsigned long ioctlsocket_ret = 0; 62 | 63 | /* Returns non-0 on failure, while fcntl() returns -1 on failure */ 64 | return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0); 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_ext.h: -------------------------------------------------------------------------------- 1 | /* src/include/pg_config_ext.h. Generated from pg_config_ext.h.in by configure. */ 2 | /* 3 | * src/include/pg_config_ext.h.in. This is generated manually, not by 4 | * autoheader, since we want to limit which symbols get defined here. 5 | */ 6 | 7 | /* Define to the name of a signed 64-bit integer type. */ 8 | #define PG_INT64_TYPE long long int 9 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_ext.h.win32: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/pg_config_ext.h.win32. This is generated manually, not by 3 | * autoheader, since we want to limit which symbols get defined here. 4 | */ 5 | 6 | /* Define to the name of a signed 64-bit integer type. */ 7 | #define PG_INT64_TYPE long long int 8 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_os.h.darwin: -------------------------------------------------------------------------------- 1 | /* src/include/port/darwin.h */ 2 | 3 | #define __darwin__ 1 4 | 5 | #if HAVE_DECL_F_FULLFSYNC /* not present before OS X 10.3 */ 6 | #define HAVE_FSYNC_WRITETHROUGH 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_paths.h: -------------------------------------------------------------------------------- 1 | #define PGBINDIR "/usr/local/pgsql/bin" 2 | #define PGSHAREDIR "/usr/local/pgsql/share" 3 | #define SYSCONFDIR "/usr/local/pgsql/etc" 4 | #define INCLUDEDIR "/usr/local/pgsql/include" 5 | #define PKGINCLUDEDIR "/usr/local/pgsql/include" 6 | #define INCLUDEDIRSERVER "/usr/local/pgsql/include/server" 7 | #define LIBDIR "/usr/local/pgsql/lib" 8 | #define PKGLIBDIR "/usr/local/pgsql/lib" 9 | #define LOCALEDIR "/usr/local/pgsql/share/locale" 10 | #define DOCDIR "/usr/local/pgsql/share/doc/" 11 | #define HTMLDIR "/usr/local/pgsql/share/doc/" 12 | #define MANDIR "/usr/local/pgsql/share/man" 13 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_paths.h.darwin: -------------------------------------------------------------------------------- 1 | #define PGBINDIR "/usr/local/pgsql/bin" 2 | #define PGSHAREDIR "/usr/local/pgsql/share" 3 | #define SYSCONFDIR "/usr/local/pgsql/etc" 4 | #define INCLUDEDIR "/usr/local/pgsql/include" 5 | #define PKGINCLUDEDIR "/usr/local/pgsql/include" 6 | #define INCLUDEDIRSERVER "/usr/local/pgsql/include/server" 7 | #define LIBDIR "/usr/local/pgsql/lib" 8 | #define PKGLIBDIR "/usr/local/pgsql/lib" 9 | #define LOCALEDIR "/usr/local/pgsql/share/locale" 10 | #define DOCDIR "/usr/local/pgsql/share/doc/" 11 | #define HTMLDIR "/usr/local/pgsql/share/doc/" 12 | #define MANDIR "/usr/local/pgsql/share/man" 13 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_config_paths.h.win: -------------------------------------------------------------------------------- 1 | #define PGBINDIR "/usr/local/pgsql/bin" 2 | #define PGSHAREDIR "/usr/local/pgsql/share" 3 | #define SYSCONFDIR "/usr/local/pgsql/etc" 4 | #define INCLUDEDIR "/usr/local/pgsql/include" 5 | #define PKGINCLUDEDIR "/usr/local/pgsql/include" 6 | #define INCLUDEDIRSERVER "/usr/local/pgsql/include/server" 7 | #define LIBDIR "/usr/local/pgsql/lib" 8 | #define PKGLIBDIR "/usr/local/pgsql/lib" 9 | #define LOCALEDIR "/usr/local/pgsql/share/locale" 10 | #define DOCDIR "/usr/local/pgsql/share/doc/" 11 | #define HTMLDIR "/usr/local/pgsql/share/doc/" 12 | #define MANDIR "/usr/local/pgsql/share/man" 13 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pg_service.conf.sample: -------------------------------------------------------------------------------- 1 | # 2 | # Connection configuration file 3 | # 4 | # A service is a set of named connection parameters. You may specify 5 | # multiple services in this file. Each starts with a service name in 6 | # brackets. Subsequent lines have connection configuration parameters of 7 | # the pattern "param=value" or LDAP URLs starting with "ldap://" 8 | # to look up such parameters. A sample configuration for postgres is 9 | # included in this file. Lines beginning with '#' are comments. 10 | # 11 | # Copy this to your sysconf directory (typically /usr/local/pgsql/etc) and 12 | # rename it pg_service.conf. 13 | # 14 | # 15 | #[postgres] 16 | #dbname=postgres 17 | #user=postgres 18 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pgsleep.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pgsleep.c 4 | * Portable delay handling. 5 | * 6 | * 7 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 8 | * 9 | * src/port/pgsleep.c 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #include "c.h" 14 | 15 | #include 16 | #include 17 | 18 | /* 19 | * In a Windows backend, we don't use this implementation, but rather 20 | * the signal-aware version in src/backend/port/win32/signal.c. 21 | */ 22 | #if defined(FRONTEND) || !defined(WIN32) 23 | 24 | /* 25 | * pg_usleep --- delay the specified number of microseconds. 26 | * 27 | * NOTE: although the delay is specified in microseconds, the effective 28 | * resolution is only 1/HZ, or 10 milliseconds, on most Unixen. Expect 29 | * the requested delay to be rounded up to the next resolution boundary. 30 | * 31 | * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds. 32 | */ 33 | void 34 | pg_usleep(long microsec) 35 | { 36 | if (microsec > 0) 37 | { 38 | #ifndef WIN32 39 | struct timeval delay; 40 | 41 | delay.tv_sec = microsec / 1000000L; 42 | delay.tv_usec = microsec % 1000000L; 43 | (void) select(0, NULL, NULL, NULL, &delay); 44 | #else 45 | SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE); 46 | #endif 47 | } 48 | } 49 | 50 | #endif /* defined(FRONTEND) || !defined(WIN32) */ 51 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pgstrcasecmp.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pgstrcasecmp.c 4 | * Portable SQL-like case-independent comparisons and conversions. 5 | * 6 | * SQL99 specifies Unicode-aware case normalization, which we don't yet 7 | * have the infrastructure for. Instead we use tolower() to provide a 8 | * locale-aware translation. However, there are some locales where this 9 | * is not right either (eg, Turkish may do strange things with 'i' and 10 | * 'I'). Our current compromise is to use tolower() for characters with 11 | * the high bit set, and use an ASCII-only downcasing for 7-bit 12 | * characters. 13 | * 14 | * NB: this code should match downcase_truncate_identifier() in scansup.c. 15 | * 16 | * We also provide strict ASCII-only case conversion functions, which can 17 | * be used to implement C/POSIX case folding semantics no matter what the 18 | * C library thinks the locale is. 19 | * 20 | * 21 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 22 | * 23 | * src/port/pgstrcasecmp.c 24 | * 25 | *------------------------------------------------------------------------- 26 | */ 27 | #include "c.h" 28 | 29 | #include 30 | 31 | 32 | /* 33 | * Case-independent comparison of two null-terminated strings. 34 | */ 35 | int 36 | pg_strcasecmp(const char *s1, const char *s2) 37 | { 38 | for (;;) 39 | { 40 | unsigned char ch1 = (unsigned char) *s1++; 41 | unsigned char ch2 = (unsigned char) *s2++; 42 | 43 | if (ch1 != ch2) 44 | { 45 | if (ch1 >= 'A' && ch1 <= 'Z') 46 | ch1 += 'a' - 'A'; 47 | else if (IS_HIGHBIT_SET(ch1) && isupper(ch1)) 48 | ch1 = tolower(ch1); 49 | 50 | if (ch2 >= 'A' && ch2 <= 'Z') 51 | ch2 += 'a' - 'A'; 52 | else if (IS_HIGHBIT_SET(ch2) && isupper(ch2)) 53 | ch2 = tolower(ch2); 54 | 55 | if (ch1 != ch2) 56 | return (int) ch1 - (int) ch2; 57 | } 58 | if (ch1 == 0) 59 | break; 60 | } 61 | return 0; 62 | } 63 | 64 | /* 65 | * Case-independent comparison of two not-necessarily-null-terminated strings. 66 | * At most n bytes will be examined from each string. 67 | */ 68 | int 69 | pg_strncasecmp(const char *s1, const char *s2, size_t n) 70 | { 71 | while (n-- > 0) 72 | { 73 | unsigned char ch1 = (unsigned char) *s1++; 74 | unsigned char ch2 = (unsigned char) *s2++; 75 | 76 | if (ch1 != ch2) 77 | { 78 | if (ch1 >= 'A' && ch1 <= 'Z') 79 | ch1 += 'a' - 'A'; 80 | else if (IS_HIGHBIT_SET(ch1) && isupper(ch1)) 81 | ch1 = tolower(ch1); 82 | 83 | if (ch2 >= 'A' && ch2 <= 'Z') 84 | ch2 += 'a' - 'A'; 85 | else if (IS_HIGHBIT_SET(ch2) && isupper(ch2)) 86 | ch2 = tolower(ch2); 87 | 88 | if (ch1 != ch2) 89 | return (int) ch1 - (int) ch2; 90 | } 91 | if (ch1 == 0) 92 | break; 93 | } 94 | return 0; 95 | } 96 | 97 | /* 98 | * Fold a character to upper case. 99 | * 100 | * Unlike some versions of toupper(), this is safe to apply to characters 101 | * that aren't lower case letters. Note however that the whole thing is 102 | * a bit bogus for multibyte character sets. 103 | */ 104 | unsigned char 105 | pg_toupper(unsigned char ch) 106 | { 107 | if (ch >= 'a' && ch <= 'z') 108 | ch += 'A' - 'a'; 109 | else if (IS_HIGHBIT_SET(ch) && islower(ch)) 110 | ch = toupper(ch); 111 | return ch; 112 | } 113 | 114 | /* 115 | * Fold a character to lower case. 116 | * 117 | * Unlike some versions of tolower(), this is safe to apply to characters 118 | * that aren't upper case letters. Note however that the whole thing is 119 | * a bit bogus for multibyte character sets. 120 | */ 121 | unsigned char 122 | pg_tolower(unsigned char ch) 123 | { 124 | if (ch >= 'A' && ch <= 'Z') 125 | ch += 'a' - 'A'; 126 | else if (IS_HIGHBIT_SET(ch) && isupper(ch)) 127 | ch = tolower(ch); 128 | return ch; 129 | } 130 | 131 | /* 132 | * Fold a character to upper case, following C/POSIX locale rules. 133 | */ 134 | unsigned char 135 | pg_ascii_toupper(unsigned char ch) 136 | { 137 | if (ch >= 'a' && ch <= 'z') 138 | ch += 'A' - 'a'; 139 | return ch; 140 | } 141 | 142 | /* 143 | * Fold a character to lower case, following C/POSIX locale rules. 144 | */ 145 | unsigned char 146 | pg_ascii_tolower(unsigned char ch) 147 | { 148 | if (ch >= 'A' && ch <= 'Z') 149 | ch += 'a' - 'A'; 150 | return ch; 151 | } 152 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/postgres_ext.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * postgres_ext.h 4 | * 5 | * This file contains declarations of things that are visible everywhere 6 | * in PostgreSQL *and* are visible to clients of frontend interface libraries. 7 | * For example, the Oid type is part of the API of libpq and other libraries. 8 | * 9 | * Declarations which are specific to a particular interface should 10 | * go in the header file for that interface (such as libpq-fe.h). This 11 | * file is only for fundamental Postgres declarations. 12 | * 13 | * User-written C functions don't count as "external to Postgres." 14 | * Those function much as local modifications to the backend itself, and 15 | * use header files that are otherwise internal to Postgres to interface 16 | * with the backend. 17 | * 18 | * src/include/postgres_ext.h 19 | * 20 | *------------------------------------------------------------------------- 21 | */ 22 | 23 | #ifndef POSTGRES_EXT_H 24 | #define POSTGRES_EXT_H 25 | 26 | #include "pg_config_ext.h" 27 | 28 | /* 29 | * Object ID is a fundamental type in Postgres. 30 | */ 31 | typedef unsigned int Oid; 32 | 33 | #ifdef __cplusplus 34 | #define InvalidOid (Oid(0)) 35 | #else 36 | #define InvalidOid ((Oid) 0) 37 | #endif 38 | 39 | #define OID_MAX UINT_MAX 40 | /* you will need to include to use the above #define */ 41 | 42 | /* Define a signed 64-bit integer type for use in client API declarations. */ 43 | typedef PG_INT64_TYPE pg_int64; 44 | 45 | 46 | /* 47 | * Identifiers of error message fields. Kept here to keep common 48 | * between frontend and backend, and also to export them to libpq 49 | * applications. 50 | */ 51 | #define PG_DIAG_SEVERITY 'S' 52 | #define PG_DIAG_SEVERITY_NONLOCALIZED 'V' 53 | #define PG_DIAG_SQLSTATE 'C' 54 | #define PG_DIAG_MESSAGE_PRIMARY 'M' 55 | #define PG_DIAG_MESSAGE_DETAIL 'D' 56 | #define PG_DIAG_MESSAGE_HINT 'H' 57 | #define PG_DIAG_STATEMENT_POSITION 'P' 58 | #define PG_DIAG_INTERNAL_POSITION 'p' 59 | #define PG_DIAG_INTERNAL_QUERY 'q' 60 | #define PG_DIAG_CONTEXT 'W' 61 | #define PG_DIAG_SCHEMA_NAME 's' 62 | #define PG_DIAG_TABLE_NAME 't' 63 | #define PG_DIAG_COLUMN_NAME 'c' 64 | #define PG_DIAG_DATATYPE_NAME 'd' 65 | #define PG_DIAG_CONSTRAINT_NAME 'n' 66 | #define PG_DIAG_SOURCE_FILE 'F' 67 | #define PG_DIAG_SOURCE_LINE 'L' 68 | #define PG_DIAG_SOURCE_FUNCTION 'R' 69 | 70 | #endif /* POSTGRES_EXT_H */ 71 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/postgres_fe.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * postgres_fe.h 4 | * Primary include file for PostgreSQL client-side .c files 5 | * 6 | * This should be the first file included by PostgreSQL client libraries and 7 | * application programs --- but not by backend modules, which should include 8 | * postgres.h. 9 | * 10 | * 11 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 12 | * Portions Copyright (c) 1995, Regents of the University of California 13 | * 14 | * src/include/postgres_fe.h 15 | * 16 | *------------------------------------------------------------------------- 17 | */ 18 | #ifndef POSTGRES_FE_H 19 | #define POSTGRES_FE_H 20 | 21 | #ifndef FRONTEND 22 | #define FRONTEND 1 23 | #endif 24 | 25 | #include "c.h" 26 | 27 | #include "common/fe_memutils.h" 28 | 29 | #endif /* POSTGRES_FE_H */ 30 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pqformat.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqformat.h 4 | * Definitions for formatting and parsing frontend/backend messages 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/pqformat.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PQFORMAT_H 14 | #define PQFORMAT_H 15 | 16 | #include "lib/stringinfo.h" 17 | 18 | extern void pq_beginmessage(StringInfo buf, char msgtype); 19 | extern void pq_sendbyte(StringInfo buf, int byt); 20 | extern void pq_sendbytes(StringInfo buf, const char *data, int datalen); 21 | extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen, 22 | bool countincludesself); 23 | extern void pq_sendtext(StringInfo buf, const char *str, int slen); 24 | extern void pq_sendstring(StringInfo buf, const char *str); 25 | extern void pq_send_ascii_string(StringInfo buf, const char *str); 26 | extern void pq_sendint(StringInfo buf, int i, int b); 27 | extern void pq_sendint64(StringInfo buf, int64 i); 28 | extern void pq_sendfloat4(StringInfo buf, float4 f); 29 | extern void pq_sendfloat8(StringInfo buf, float8 f); 30 | extern void pq_endmessage(StringInfo buf); 31 | 32 | extern void pq_begintypsend(StringInfo buf); 33 | extern bytea *pq_endtypsend(StringInfo buf); 34 | 35 | extern void pq_puttextmessage(char msgtype, const char *str); 36 | extern void pq_putemptymessage(char msgtype); 37 | 38 | extern int pq_getmsgbyte(StringInfo msg); 39 | extern unsigned int pq_getmsgint(StringInfo msg, int b); 40 | extern int64 pq_getmsgint64(StringInfo msg); 41 | extern float4 pq_getmsgfloat4(StringInfo msg); 42 | extern float8 pq_getmsgfloat8(StringInfo msg); 43 | extern const char *pq_getmsgbytes(StringInfo msg, int datalen); 44 | extern void pq_copymsgbytes(StringInfo msg, char *buf, int datalen); 45 | extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes); 46 | extern const char *pq_getmsgstring(StringInfo msg); 47 | extern void pq_getmsgend(StringInfo msg); 48 | 49 | #endif /* PQFORMAT_H */ 50 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pqsignal.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqsignal.c 4 | * reliable BSD-style signal(2) routine stolen from RWW who stole it 5 | * from Stevens... 6 | * 7 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 8 | * Portions Copyright (c) 1994, Regents of the University of California 9 | * 10 | * 11 | * IDENTIFICATION 12 | * src/port/pqsignal.c 13 | * 14 | * We now assume that all Unix-oid systems have POSIX sigaction(2) 15 | * with support for restartable signals (SA_RESTART). We used to also 16 | * support BSD-style signal(2), but there really shouldn't be anything 17 | * out there anymore that doesn't have the POSIX API. 18 | * 19 | * Windows, of course, is resolutely in a class by itself. In the backend, 20 | * we don't use this file at all; src/backend/port/win32/signal.c provides 21 | * pqsignal() for the backend environment. Frontend programs can use 22 | * this version of pqsignal() if they wish, but beware that this does 23 | * not provide restartable signals on Windows. 24 | * 25 | * ------------------------------------------------------------------------ 26 | */ 27 | 28 | #include "c.h" 29 | 30 | #include 31 | 32 | #if !defined(WIN32) || defined(FRONTEND) 33 | 34 | /* 35 | * Set up a signal handler, with SA_RESTART, for signal "signo" 36 | * 37 | * Returns the previous handler. 38 | */ 39 | pqsigfunc 40 | pqsignal(int signo, pqsigfunc func) 41 | { 42 | #ifndef WIN32 43 | struct sigaction act, 44 | oact; 45 | 46 | act.sa_handler = func; 47 | sigemptyset(&act.sa_mask); 48 | act.sa_flags = SA_RESTART; 49 | #ifdef SA_NOCLDSTOP 50 | if (signo == SIGCHLD) 51 | act.sa_flags |= SA_NOCLDSTOP; 52 | #endif 53 | if (sigaction(signo, &act, &oact) < 0) 54 | return SIG_ERR; 55 | return oact.sa_handler; 56 | #else /* WIN32 */ 57 | return signal(signo, func); 58 | #endif 59 | } 60 | 61 | /* 62 | * Set up a signal handler, without SA_RESTART, for signal "signo" 63 | * 64 | * Returns the previous handler. 65 | * 66 | * On Windows, this would be identical to pqsignal(), so don't bother. 67 | */ 68 | #ifndef WIN32 69 | 70 | pqsigfunc 71 | pqsignal_no_restart(int signo, pqsigfunc func) 72 | { 73 | struct sigaction act, 74 | oact; 75 | 76 | act.sa_handler = func; 77 | sigemptyset(&act.sa_mask); 78 | act.sa_flags = 0; 79 | #ifdef SA_NOCLDSTOP 80 | if (signo == SIGCHLD) 81 | act.sa_flags |= SA_NOCLDSTOP; 82 | #endif 83 | if (sigaction(signo, &act, &oact) < 0) 84 | return SIG_ERR; 85 | return oact.sa_handler; 86 | } 87 | 88 | #endif /* !WIN32 */ 89 | 90 | #endif /* !defined(WIN32) || defined(FRONTEND) */ 91 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pqsignal.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pqsignal.h 4 | * Backend signal(2) support (see also src/port/pqsignal.c) 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * Portions Copyright (c) 1994, Regents of the University of California 8 | * 9 | * src/include/libpq/pqsignal.h 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | #ifndef PQSIGNAL_H 14 | #define PQSIGNAL_H 15 | 16 | #include 17 | 18 | #ifdef HAVE_SIGPROCMASK 19 | extern sigset_t UnBlockSig, 20 | BlockSig, 21 | StartupBlockSig; 22 | 23 | #define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) 24 | #else /* not HAVE_SIGPROCMASK */ 25 | extern int UnBlockSig, 26 | BlockSig, 27 | StartupBlockSig; 28 | 29 | #ifndef WIN32 30 | #define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) 31 | #else 32 | #define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) 33 | int pqsigsetmask(int mask); 34 | #endif 35 | 36 | #define sigaddset(set, signum) (*(set) |= (sigmask(signum))) 37 | #define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) 38 | #endif /* not HAVE_SIGPROCMASK */ 39 | 40 | extern void pqinitmask(void); 41 | 42 | #endif /* PQSIGNAL_H */ 43 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pthread-win32.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * pthread-win32.c 4 | * partial pthread implementation for win32 5 | * 6 | * Copyright (c) 2004-2016, PostgreSQL Global Development Group 7 | * IDENTIFICATION 8 | * src/interfaces/libpq/pthread-win32.c 9 | * 10 | *------------------------------------------------------------------------- 11 | */ 12 | 13 | #include "postgres_fe.h" 14 | 15 | #include 16 | #include "pthread-win32.h" 17 | 18 | DWORD 19 | pthread_self(void) 20 | { 21 | return GetCurrentThreadId(); 22 | } 23 | 24 | void 25 | pthread_setspecific(pthread_key_t key, void *val) 26 | { 27 | } 28 | 29 | void * 30 | pthread_getspecific(pthread_key_t key) 31 | { 32 | return NULL; 33 | } 34 | 35 | int 36 | pthread_mutex_init(pthread_mutex_t *mp, void *attr) 37 | { 38 | *mp = (CRITICAL_SECTION *) malloc(sizeof(CRITICAL_SECTION)); 39 | if (!*mp) 40 | return 1; 41 | InitializeCriticalSection(*mp); 42 | return 0; 43 | } 44 | 45 | int 46 | pthread_mutex_lock(pthread_mutex_t *mp) 47 | { 48 | if (!*mp) 49 | return 1; 50 | EnterCriticalSection(*mp); 51 | return 0; 52 | } 53 | 54 | int 55 | pthread_mutex_unlock(pthread_mutex_t *mp) 56 | { 57 | if (!*mp) 58 | return 1; 59 | LeaveCriticalSection(*mp); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/pthread-win32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/port/pthread-win32.h 3 | */ 4 | #ifndef __PTHREAD_H 5 | #define __PTHREAD_H 6 | 7 | typedef ULONG pthread_key_t; 8 | typedef CRITICAL_SECTION *pthread_mutex_t; 9 | typedef int pthread_once_t; 10 | 11 | DWORD pthread_self(void); 12 | 13 | void pthread_setspecific(pthread_key_t, void *); 14 | void *pthread_getspecific(pthread_key_t); 15 | 16 | int pthread_mutex_init(pthread_mutex_t *, void *attr); 17 | int pthread_mutex_lock(pthread_mutex_t *); 18 | 19 | /* blocking */ 20 | int pthread_mutex_unlock(pthread_mutex_t *); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/strlcpy.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * strlcpy.c 4 | * strncpy done right 5 | * 6 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 7 | * 8 | * 9 | * IDENTIFICATION 10 | * src/port/strlcpy.c 11 | * 12 | * This file was taken from OpenBSD and is used on platforms that don't 13 | * provide strlcpy(). The OpenBSD copyright terms follow. 14 | *------------------------------------------------------------------------- 15 | */ 16 | 17 | /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ 18 | 19 | /* 20 | * Copyright (c) 1998 Todd C. Miller 21 | * 22 | * Permission to use, copy, modify, and distribute this software for any 23 | * purpose with or without fee is hereby granted, provided that the above 24 | * copyright notice and this permission notice appear in all copies. 25 | * 26 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 27 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 29 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 30 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 31 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 32 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 33 | */ 34 | 35 | #include "c.h" 36 | 37 | 38 | /* 39 | * Copy src to string dst of size siz. At most siz-1 characters 40 | * will be copied. Always NUL terminates (unless siz == 0). 41 | * Returns strlen(src); if retval >= siz, truncation occurred. 42 | * Function creation history: http://www.gratisoft.us/todd/papers/strlcpy.html 43 | */ 44 | size_t 45 | strlcpy(char *dst, const char *src, size_t siz) 46 | { 47 | char *d = dst; 48 | const char *s = src; 49 | size_t n = siz; 50 | 51 | /* Copy as many bytes as will fit */ 52 | if (n != 0) 53 | { 54 | while (--n != 0) 55 | { 56 | if ((*d++ = *s++) == '\0') 57 | break; 58 | } 59 | } 60 | 61 | /* Not enough room in dst, add NUL and traverse rest of src */ 62 | if (n == 0) 63 | { 64 | if (siz != 0) 65 | *d = '\0'; /* NUL-terminate dst */ 66 | while (*s++) 67 | ; 68 | } 69 | 70 | return (s - src - 1); /* count does not include NUL */ 71 | } 72 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/system.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * system.c 4 | * Win32 system() and popen() replacements 5 | * 6 | * 7 | * Win32 needs double quotes at the beginning and end of system() 8 | * strings. If not, it gets confused with multiple quoted strings. 9 | * It also requires double-quotes around the executable name and 10 | * any files used for redirection. Filter other args through 11 | * appendShellString() to quote them. 12 | * 13 | * Generated using Win32 "CMD /?": 14 | * 15 | * 1. If all of the following conditions are met, then quote characters 16 | * on the command line are preserved: 17 | * 18 | * - no /S switch 19 | * - exactly two quote characters 20 | * - no special characters between the two quote characters, where special 21 | * is one of: &<>()@^| 22 | * - there are one or more whitespace characters between the two quote 23 | * characters 24 | * - the string between the two quote characters is the name of an 25 | * executable file. 26 | * 27 | * 2. Otherwise, old behavior is to see if the first character is a quote 28 | * character and if so, strip the leading character and remove the last 29 | * quote character on the command line, preserving any text after the last 30 | * quote character. 31 | * 32 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 33 | * 34 | * src/port/system.c 35 | * 36 | *------------------------------------------------------------------------- 37 | */ 38 | 39 | #if defined(WIN32) && !defined(__CYGWIN__) 40 | 41 | #ifndef FRONTEND 42 | #include "postgres.h" 43 | #else 44 | #include "postgres_fe.h" 45 | #endif 46 | 47 | #include 48 | #include 49 | 50 | #undef system 51 | #undef popen 52 | 53 | int 54 | pgwin32_system(const char *command) 55 | { 56 | size_t cmdlen = strlen(command); 57 | char *buf; 58 | int save_errno; 59 | int res; 60 | 61 | /* 62 | * Create a malloc'd copy of the command string, enclosed with an extra 63 | * pair of quotes 64 | */ 65 | buf = malloc(cmdlen + 2 + 1); 66 | if (buf == NULL) 67 | { 68 | errno = ENOMEM; 69 | return -1; 70 | } 71 | buf[0] = '"'; 72 | memcpy(&buf[1], command, cmdlen); 73 | buf[cmdlen + 1] = '"'; 74 | buf[cmdlen + 2] = '\0'; 75 | 76 | res = system(buf); 77 | 78 | save_errno = errno; 79 | free(buf); 80 | errno = save_errno; 81 | 82 | return res; 83 | } 84 | 85 | 86 | FILE * 87 | pgwin32_popen(const char *command, const char *type) 88 | { 89 | size_t cmdlen = strlen(command); 90 | char *buf; 91 | int save_errno; 92 | FILE *res; 93 | 94 | /* 95 | * Create a malloc'd copy of the command string, enclosed with an extra 96 | * pair of quotes 97 | */ 98 | buf = malloc(cmdlen + 2 + 1); 99 | if (buf == NULL) 100 | { 101 | errno = ENOMEM; 102 | return NULL; 103 | } 104 | buf[0] = '"'; 105 | memcpy(&buf[1], command, cmdlen); 106 | buf[cmdlen + 1] = '"'; 107 | buf[cmdlen + 2] = '\0'; 108 | 109 | res = _popen(buf, type); 110 | 111 | save_errno = errno; 112 | free(buf); 113 | errno = save_errno; 114 | 115 | return res; 116 | } 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/utils/palloc.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * palloc.h 4 | * POSTGRES memory allocator definitions. 5 | * 6 | * This file contains the basic memory allocation interface that is 7 | * needed by almost every backend module. It is included directly by 8 | * postgres.h, so the definitions here are automatically available 9 | * everywhere. Keep it lean! 10 | * 11 | * Memory allocation occurs within "contexts". Every chunk obtained from 12 | * palloc()/MemoryContextAlloc() is allocated within a specific context. 13 | * The entire contents of a context can be freed easily and quickly by 14 | * resetting or deleting the context --- this is both faster and less 15 | * prone to memory-leakage bugs than releasing chunks individually. 16 | * We organize contexts into context trees to allow fine-grain control 17 | * over chunk lifetime while preserving the certainty that we will free 18 | * everything that should be freed. See utils/mmgr/README for more info. 19 | * 20 | * 21 | * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 22 | * Portions Copyright (c) 1994, Regents of the University of California 23 | * 24 | * src/include/utils/palloc.h 25 | * 26 | *------------------------------------------------------------------------- 27 | */ 28 | #ifndef PALLOC_H 29 | #define PALLOC_H 30 | 31 | /* 32 | * Type MemoryContextData is declared in nodes/memnodes.h. Most users 33 | * of memory allocation should just treat it as an abstract type, so we 34 | * do not provide the struct contents here. 35 | */ 36 | typedef struct MemoryContextData *MemoryContext; 37 | 38 | #ifndef FRONTEND 39 | 40 | /* 41 | * CurrentMemoryContext is the default allocation context for palloc(). 42 | * We declare it here so that palloc() can be a macro. Avoid accessing it 43 | * directly! Instead, use MemoryContextSwitchTo() to change the setting. 44 | */ 45 | extern PGDLLIMPORT MemoryContext CurrentMemoryContext; 46 | 47 | /* 48 | * Fundamental memory-allocation operations (more are in utils/memutils.h) 49 | */ 50 | extern void *MemoryContextAlloc(MemoryContext context, Size size); 51 | extern void *MemoryContextAllocZero(MemoryContext context, Size size); 52 | extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size); 53 | 54 | /* 55 | * The result of palloc() is always word-aligned, so we can skip testing 56 | * alignment of the pointer when deciding which MemSet variant to use. 57 | * Note that this variant does not offer any advantage, and should not be 58 | * used, unless its "sz" argument is a compile-time constant; therefore, the 59 | * issue that it evaluates the argument multiple times isn't a problem in 60 | * practice. 61 | */ 62 | #define palloc0fast(sz) \ 63 | ( MemSetTest(0, sz) ? \ 64 | MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \ 65 | MemoryContextAllocZero(CurrentMemoryContext, sz) ) 66 | 67 | /* 68 | * MemoryContextSwitchTo can't be a macro in standard C compilers. 69 | * But we can make it an inline function if the compiler supports it. 70 | * See STATIC_IF_INLINE in c.h. 71 | */ 72 | 73 | #ifndef PG_USE_INLINE 74 | extern MemoryContext MemoryContextSwitchTo(MemoryContext context); 75 | #endif /* !PG_USE_INLINE */ 76 | #if defined(PG_USE_INLINE) || defined(MCXT_INCLUDE_DEFINITIONS) 77 | STATIC_IF_INLINE MemoryContext 78 | MemoryContextSwitchTo(MemoryContext context) 79 | { 80 | MemoryContext old = CurrentMemoryContext; 81 | 82 | CurrentMemoryContext = context; 83 | return old; 84 | } 85 | #endif /* PG_USE_INLINE || MCXT_INCLUDE_DEFINITIONS */ 86 | 87 | /* 88 | * These are like standard strdup() except the copied string is 89 | * allocated in a context, not with malloc(). 90 | */ 91 | extern char *MemoryContextStrdup(MemoryContext context, const char *string); 92 | #endif /* !FRONTEND */ 93 | 94 | extern char *pstrdup(const char *in); 95 | extern char *pnstrdup(const char *in, Size len); 96 | extern void *palloc(Size size); 97 | extern void *palloc0(Size size); 98 | extern void pfree(void *pointer); 99 | extern void *repalloc(void *pointer, Size size); 100 | 101 | #endif /* PALLOC_H */ 102 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/win32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/interfaces/libpq/win32.h 3 | */ 4 | #ifndef __win32_h_included 5 | #define __win32_h_included 6 | 7 | /* 8 | * Some compatibility functions 9 | */ 10 | #ifdef __BORLANDC__ 11 | #define _timeb timeb 12 | #define _ftime(a) ftime(a) 13 | #define _errno errno 14 | #define popen(a,b) _popen(a,b) 15 | #else 16 | /* open provided elsewhere */ 17 | #define close(a) _close(a) 18 | #define read(a,b,c) _read(a,b,c) 19 | #define write(a,b,c) _write(a,b,c) 20 | #endif 21 | 22 | #undef EAGAIN /* doesn't apply on sockets */ 23 | #undef EINTR 24 | #define EINTR WSAEINTR 25 | #ifndef EWOULDBLOCK 26 | #define EWOULDBLOCK WSAEWOULDBLOCK 27 | #endif 28 | #ifndef ECONNRESET 29 | #define ECONNRESET WSAECONNRESET 30 | #endif 31 | #ifndef EINPROGRESS 32 | #define EINPROGRESS WSAEINPROGRESS 33 | #endif 34 | 35 | /* 36 | * support for handling Windows Socket errors 37 | */ 38 | extern const char *winsock_strerror(int err, char *strerrbuf, size_t buflen); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/win32error.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | * 3 | * win32error.c 4 | * Map win32 error codes to errno values 5 | * 6 | * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group 7 | * 8 | * IDENTIFICATION 9 | * src/port/win32error.c 10 | * 11 | *------------------------------------------------------------------------- 12 | */ 13 | 14 | #ifndef FRONTEND 15 | #include "postgres.h" 16 | #else 17 | #include "postgres_fe.h" 18 | #endif 19 | 20 | static const struct 21 | { 22 | DWORD winerr; 23 | int doserr; 24 | } doserrors[] = 25 | 26 | { 27 | { 28 | ERROR_INVALID_FUNCTION, EINVAL 29 | }, 30 | { 31 | ERROR_FILE_NOT_FOUND, ENOENT 32 | }, 33 | { 34 | ERROR_PATH_NOT_FOUND, ENOENT 35 | }, 36 | { 37 | ERROR_TOO_MANY_OPEN_FILES, EMFILE 38 | }, 39 | { 40 | ERROR_ACCESS_DENIED, EACCES 41 | }, 42 | { 43 | ERROR_INVALID_HANDLE, EBADF 44 | }, 45 | { 46 | ERROR_ARENA_TRASHED, ENOMEM 47 | }, 48 | { 49 | ERROR_NOT_ENOUGH_MEMORY, ENOMEM 50 | }, 51 | { 52 | ERROR_INVALID_BLOCK, ENOMEM 53 | }, 54 | { 55 | ERROR_BAD_ENVIRONMENT, E2BIG 56 | }, 57 | { 58 | ERROR_BAD_FORMAT, ENOEXEC 59 | }, 60 | { 61 | ERROR_INVALID_ACCESS, EINVAL 62 | }, 63 | { 64 | ERROR_INVALID_DATA, EINVAL 65 | }, 66 | { 67 | ERROR_INVALID_DRIVE, ENOENT 68 | }, 69 | { 70 | ERROR_CURRENT_DIRECTORY, EACCES 71 | }, 72 | { 73 | ERROR_NOT_SAME_DEVICE, EXDEV 74 | }, 75 | { 76 | ERROR_NO_MORE_FILES, ENOENT 77 | }, 78 | { 79 | ERROR_LOCK_VIOLATION, EACCES 80 | }, 81 | { 82 | ERROR_SHARING_VIOLATION, EACCES 83 | }, 84 | { 85 | ERROR_BAD_NETPATH, ENOENT 86 | }, 87 | { 88 | ERROR_NETWORK_ACCESS_DENIED, EACCES 89 | }, 90 | { 91 | ERROR_BAD_NET_NAME, ENOENT 92 | }, 93 | { 94 | ERROR_FILE_EXISTS, EEXIST 95 | }, 96 | { 97 | ERROR_CANNOT_MAKE, EACCES 98 | }, 99 | { 100 | ERROR_FAIL_I24, EACCES 101 | }, 102 | { 103 | ERROR_INVALID_PARAMETER, EINVAL 104 | }, 105 | { 106 | ERROR_NO_PROC_SLOTS, EAGAIN 107 | }, 108 | { 109 | ERROR_DRIVE_LOCKED, EACCES 110 | }, 111 | { 112 | ERROR_BROKEN_PIPE, EPIPE 113 | }, 114 | { 115 | ERROR_DISK_FULL, ENOSPC 116 | }, 117 | { 118 | ERROR_INVALID_TARGET_HANDLE, EBADF 119 | }, 120 | { 121 | ERROR_INVALID_HANDLE, EINVAL 122 | }, 123 | { 124 | ERROR_WAIT_NO_CHILDREN, ECHILD 125 | }, 126 | { 127 | ERROR_CHILD_NOT_COMPLETE, ECHILD 128 | }, 129 | { 130 | ERROR_DIRECT_ACCESS_HANDLE, EBADF 131 | }, 132 | { 133 | ERROR_NEGATIVE_SEEK, EINVAL 134 | }, 135 | { 136 | ERROR_SEEK_ON_DEVICE, EACCES 137 | }, 138 | { 139 | ERROR_DIR_NOT_EMPTY, ENOTEMPTY 140 | }, 141 | { 142 | ERROR_NOT_LOCKED, EACCES 143 | }, 144 | { 145 | ERROR_BAD_PATHNAME, ENOENT 146 | }, 147 | { 148 | ERROR_MAX_THRDS_REACHED, EAGAIN 149 | }, 150 | { 151 | ERROR_LOCK_FAILED, EACCES 152 | }, 153 | { 154 | ERROR_ALREADY_EXISTS, EEXIST 155 | }, 156 | { 157 | ERROR_FILENAME_EXCED_RANGE, ENOENT 158 | }, 159 | { 160 | ERROR_NESTING_NOT_ALLOWED, EAGAIN 161 | }, 162 | { 163 | ERROR_NOT_ENOUGH_QUOTA, ENOMEM 164 | } 165 | }; 166 | 167 | void 168 | _dosmaperr(unsigned long e) 169 | { 170 | int i; 171 | 172 | if (e == 0) 173 | { 174 | errno = 0; 175 | return; 176 | } 177 | 178 | for (i = 0; i < lengthof(doserrors); i++) 179 | { 180 | if (doserrors[i].winerr == e) 181 | { 182 | int doserr = doserrors[i].doserr; 183 | 184 | #ifndef FRONTEND 185 | ereport(DEBUG5, 186 | (errmsg_internal("mapped win32 error code %lu to %d", 187 | e, doserr))); 188 | #elif FRONTEND_DEBUG 189 | fprintf(stderr, "mapped win32 error code %lu to %d", e, doserr); 190 | #endif 191 | errno = doserr; 192 | return; 193 | } 194 | } 195 | 196 | #ifndef FRONTEND 197 | ereport(LOG, 198 | (errmsg_internal("unrecognized win32 error code: %lu", 199 | e))); 200 | #else 201 | fprintf(stderr, "unrecognized win32 error code: %lu", e); 202 | #endif 203 | 204 | errno = EINVAL; 205 | return; 206 | } 207 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/arpa/inet.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/arpa/inet.h */ 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/netdb.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/netdb.h */ 2 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/netinet/in.h: -------------------------------------------------------------------------------- 1 | /* src/include/port/win32/netinet/in.h */ 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/pwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/pwd.h 3 | */ 4 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/sys/socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/socket.h 3 | */ 4 | #ifndef WIN32_SYS_SOCKET_H 5 | #define WIN32_SYS_SOCKET_H 6 | 7 | /* 8 | * Unfortunately, of VC++ also defines ERROR. 9 | * To avoid the conflict, we include here and undefine ERROR 10 | * immediately. 11 | * 12 | * Note: Don't include directly. It causes compile errors. 13 | */ 14 | #include 15 | #include 16 | #include 17 | 18 | #undef ERROR 19 | #undef small 20 | 21 | /* Restore old ERROR value */ 22 | #ifdef PGERROR 23 | #define ERROR PGERROR 24 | #endif 25 | 26 | /* 27 | * we can't use the windows gai_strerror{AW} functions because 28 | * they are defined inline in the MS header files. So we'll use our 29 | * own 30 | */ 31 | #undef gai_strerror 32 | 33 | #endif /* WIN32_SYS_SOCKET_H */ 34 | -------------------------------------------------------------------------------- /RPostgreSQL/src/libpq/wininclude/sys/wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * src/include/port/win32/sys/wait.h 3 | */ 4 | -------------------------------------------------------------------------------- /build_check_with_vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## either define the variables here (and get a diff to SVN) 4 | ## 5 | ## export POSTGRES_USER="someuser" 6 | ## export POSTGRES_PASSWD="..." 7 | ## export POSTGRES_HOST="somehost" 8 | ## export POSTGRES_DATABASE="testing124" 9 | ## export POSTGRES_PORT="5432" 10 | ## 11 | ## or write them to a local file that can get sourced here 12 | ## 13 | if [ -f ~/.RPostgreSQL_Test_Vars ] 14 | then 15 | . ~/.RPostgreSQL_Test_Vars 16 | fi 17 | 18 | echo " " 19 | echo "-------------- write version info ----------------------" 20 | 21 | if [ -x /usr/bin/sw_vers ] 22 | then 23 | sw_vers 24 | elif [ -x /usr/bin/lsb_release ] 25 | then 26 | lsb_release -a 27 | fi 28 | echo "" 29 | svn_version=$(svnversion -n) 30 | echo "RPostgreSQL svn version: $svn_version" 31 | echo "" 32 | psql --version | head -n 1 33 | echo "" 34 | Rscript -e 'sessionInfo(); capabilities()' | sed -n -e '1,2p' 35 | echo "" 36 | Rscript -e 'packageDescription("RPostgreSQL", fields = c("Package", "Version", "Packaged", "Built"))' | sed -n -e '1,4p' 37 | 38 | R CMD build RPostgreSQL 39 | R CMD check --as-cran RPostgreSQL_*.tar.gz 40 | 41 | echo "Done" 42 | exit 0 43 | -------------------------------------------------------------------------------- /check_with_vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## either define the variables here (and get a diff to SVN) 4 | ## 5 | ## export POSTGRES_USER="someuser" 6 | ## export POSTGRES_PASSWD="..." 7 | ## export POSTGRES_HOST="somehost" 8 | ## export POSTGRES_DATABASE="testing124" 9 | ## export POSTGRES_PORT="5432" 10 | ## 11 | ## or write them to a local file that can get sourced here 12 | ## 13 | if [ -f ~/.RPostgreSQL_Test_Vars ] 14 | then 15 | . ~/.RPostgreSQL_Test_Vars 16 | fi 17 | 18 | echo " " 19 | echo "-------------- write version info ----------------------" 20 | 21 | if [ -x /usr/bin/sw_vers ] 22 | then 23 | sw_vers 24 | elif [ -x /usr/bin/lsb_release ] 25 | then 26 | lsb_release -a 27 | fi 28 | echo "" 29 | svn_version=$(svnversion -n) 30 | echo "RPostgreSQL svn version: $svn_version" 31 | echo "" 32 | psql --version | head -n 1 33 | echo "" 34 | Rscript -e 'sessionInfo(); capabilities()' | sed -n -e '1,2p' 35 | echo "" 36 | Rscript -e 'packageDescription("RPostgreSQL", fields = c("Package", "Version", "Packaged", "Built"))' | sed -n -e '1,4p' 37 | 38 | 39 | #R CMD check RPostgreSQL 40 | 41 | for f in exttests/*.R 42 | do 43 | echo "" 44 | echo "==== Running $f" 45 | R -d "valgrind --tool=memcheck --leak-check=full" --slave < $f 46 | done 47 | for f in RPostgreSQL/tests/*.R 48 | do 49 | echo "" 50 | echo "==== Running $f" 51 | if $skip_valgrind 52 | then R --slave < $f 53 | else R -d "valgrind --tool=memcheck --leak-check=full" --slave < $f 54 | fi 55 | done 56 | 57 | echo "Done" 58 | exit 0 59 | -------------------------------------------------------------------------------- /exttests/bytea.R: -------------------------------------------------------------------------------- 1 | ## Test of bytea conversion with insert and retrieve to the db. 2 | ## 3 | 4 | if ((Sys.getenv("POSTGRES_USER") != "") & 5 | (Sys.getenv("POSTGRES_HOST") != "") & 6 | (Sys.getenv("POSTGRES_DATABASE") != "")) { 7 | 8 | ## try to load our module and abort if this fails 9 | stopifnot(require(RPostgreSQL)) 10 | 11 | ## load the PostgresSQL driver 12 | drv <- dbDriver("PostgreSQL") 13 | 14 | ## connect to the default db 15 | con <- dbConnect(drv, 16 | user=Sys.getenv("POSTGRES_USER"), 17 | password=Sys.getenv("POSTGRES_PASSWD"), 18 | host=Sys.getenv("POSTGRES_HOST"), 19 | dbname=Sys.getenv("POSTGRES_DATABASE"), 20 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 21 | 22 | if (dbExistsTable(con, "byteatable")) 23 | dbRemoveTable(con, "byteatable") 24 | 25 | sample.object <- list("one", "two"); 26 | ser <- serialize(sample.object, NULL, ascii=F); 27 | 28 | ## Test the store/recovery of binary data 29 | dbGetQuery(con, "CREATE TABLE byteatable (name text, val bytea)") 30 | dbGetQuery(con, "set standard_conforming_strings to 'on'") 31 | cat("Note the encoded string could differ depending on the server.\n") 32 | cat("Show encoded string when standard_conforming_strings is on.\n") 33 | print(postgresqlEscapeBytea(con, ser)) 34 | iq <- sprintf("INSERT INTO byteatable values('%s', '%s');", "name1", postgresqlEscapeBytea(con, ser)) 35 | dbGetQuery(con, iq) 36 | rows<-dbGetQuery(con, "SELECT * from byteatable") 37 | ser2<-postgresqlUnescapeBytea(rows[[2]]) 38 | if (identical(ser, ser2)) { 39 | cat("PASS: Identical data was recovered\n") 40 | }else{ 41 | cat("FAIL: The recovered data is not identical\n") 42 | ser 43 | ser2 44 | } 45 | dbGetQuery(con, "set standard_conforming_strings to 'off'") 46 | dbGetQuery(con, "set escape_string_warning to 'off'") 47 | cat("Show encoded string when standard_conforming_strings is off.\n") 48 | print(postgresqlEscapeBytea(con, ser)) 49 | iq <- sprintf("INSERT INTO byteatable values('%s', '%s');", "name2", postgresqlEscapeBytea(con, ser)) 50 | dbGetQuery(con, iq) 51 | rows<-dbGetQuery(con, "SELECT * from byteatable where name = 'name2'") 52 | ser3<-postgresqlUnescapeBytea(rows[[2]]) 53 | if (identical(ser, ser3)) { 54 | cat("PASS: Identical data was recovered\n") 55 | }else{ 56 | cat("FAIL: The recovered data is not identical\n") 57 | ser 58 | ser2 59 | } 60 | dbRemoveTable(con, "byteatable") 61 | dbDisconnect(con) 62 | dbUnloadDriver(drv) 63 | cat("DONE\n") 64 | }else{ 65 | cat("Skip because envirinmental variables are not set to tell the connection params.\n") 66 | } 67 | -------------------------------------------------------------------------------- /exttests/bytea.Rout.save: -------------------------------------------------------------------------------- 1 | 2 | R version 3.0.0 (2013-04-03) -- "Masked Marvel" 3 | Copyright (C) 2013 The R Foundation for Statistical Computing 4 | Platform: x86_64-unknown-linux-gnu (64-bit) 5 | 6 | R is free software and comes with ABSOLUTELY NO WARRANTY. 7 | You are welcome to redistribute it under certain conditions. 8 | Type 'license()' or 'licence()' for distribution details. 9 | 10 | R is a collaborative project with many contributors. 11 | Type 'contributors()' for more information and 12 | 'citation()' on how to cite R or R packages in publications. 13 | 14 | Type 'demo()' for some demos, 'help()' for on-line help, or 15 | 'help.start()' for an HTML browser interface to help. 16 | Type 'q()' to quit R. 17 | 18 | > ## Test of bytea conversion with insert and retrieve to the db. 19 | > ## 20 | > 21 | > if ((Sys.getenv("POSTGRES_USER") != "") & 22 | + (Sys.getenv("POSTGRES_HOST") != "") & 23 | + (Sys.getenv("POSTGRES_DATABASE") != "")) { 24 | + 25 | + ## try to load our module and abort if this fails 26 | + stopifnot(require(RPostgreSQL)) 27 | + 28 | + ## load the PostgresSQL driver 29 | + drv <- dbDriver("PostgreSQL") 30 | + 31 | + ## connect to the default db 32 | + con <- dbConnect(drv, 33 | + user=Sys.getenv("POSTGRES_USER"), 34 | + password=Sys.getenv("POSTGRES_PASSWD"), 35 | + host=Sys.getenv("POSTGRES_HOST"), 36 | + dbname=Sys.getenv("POSTGRES_DATABASE"), 37 | + port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 38 | + 39 | + if (dbExistsTable(con, "byteatable")) 40 | + dbRemoveTable(con, "byteatable") 41 | + 42 | + sample.object <- list("one", "two"); 43 | + ser <- serialize(sample.object, NULL, ascii=F); 44 | + 45 | + ## Test the store/recovery of binary data 46 | + dbGetQuery(con, "CREATE TABLE byteatable (name text, val bytea)") 47 | + dbGetQuery(con, "set standard_conforming_strings to 'on'") 48 | + cat("Note the encoded string could differ depending on the server.\n") 49 | + cat("Show encoded string when standard_conforming_strings is on.\n") 50 | + print(postgresqlEscapeBytea(con, ser)) 51 | + iq <- sprintf("INSERT INTO byteatable values('%s', '%s');", "name1", postgresqlEscapeBytea(con, ser)) 52 | + dbGetQuery(con, iq) 53 | + rows<-dbGetQuery(con, "SELECT * from byteatable") 54 | + ser2<-postgresqlUnescapeBytea(rows[[2]]) 55 | + if (identical(ser, ser2)) { 56 | + cat("PASS: Identical data was recovered\n") 57 | + }else{ 58 | + cat("FAIL: The recovered data is not identical\n") 59 | + ser 60 | + ser2 61 | + } 62 | + dbGetQuery(con, "set standard_conforming_strings to 'off'") 63 | + dbGetQuery(con, "set escape_string_warning to 'off'") 64 | + cat("Show encoded string when standard_conforming_strings is off.\n") 65 | + print(postgresqlEscapeBytea(con, ser)) 66 | + iq <- sprintf("INSERT INTO byteatable values('%s', '%s');", "name2", postgresqlEscapeBytea(con, ser)) 67 | + dbGetQuery(con, iq) 68 | + rows<-dbGetQuery(con, "SELECT * from byteatable where name = 'name2'") 69 | + ser3<-postgresqlUnescapeBytea(rows[[2]]) 70 | + if (identical(ser, ser3)) { 71 | + cat("PASS: Identical data was recovered\n") 72 | + }else{ 73 | + cat("FAIL: The recovered data is not identical\n") 74 | + ser 75 | + ser2 76 | + } 77 | + dbRemoveTable(con, "byteatable") 78 | + dbDisconnect(con) 79 | + dbUnloadDriver(drv) 80 | + cat("DONE\n") 81 | + }else{ 82 | + cat("Skip because envirinmental variables are not set to tell the connection params.\n") 83 | + } 84 | Loading required package: RPostgreSQL 85 | Loading required package: DBI 86 | Note the encoded string could differ depending on the server. 87 | Show encoded string when standard_conforming_strings is on. 88 | [1] "X\\012\\000\\000\\000\\002\\000\\003\\000\\000\\000\\002\\003\\000\\000\\000\\000\\023\\000\\000\\000\\002\\000\\000\\000\\020\\000\\000\\000\\001\\000\\004\\000\\011\\000\\000\\000\\003one\\000\\000\\000\\020\\000\\000\\000\\001\\000\\004\\000\\011\\000\\000\\000\\003two" 89 | PASS: Identical data was recovered 90 | Show encoded string when standard_conforming_strings is off. 91 | [1] "X\\\\012\\\\000\\\\000\\\\000\\\\002\\\\000\\\\003\\\\000\\\\000\\\\000\\\\002\\\\003\\\\000\\\\000\\\\000\\\\000\\\\023\\\\000\\\\000\\\\000\\\\002\\\\000\\\\000\\\\000\\\\020\\\\000\\\\000\\\\000\\\\001\\\\000\\\\004\\\\000\\\\011\\\\000\\\\000\\\\000\\\\003one\\\\000\\\\000\\\\000\\\\020\\\\000\\\\000\\\\000\\\\001\\\\000\\\\004\\\\000\\\\011\\\\000\\\\000\\\\000\\\\003two" 92 | PASS: Identical data was recovered 93 | DONE 94 | > 95 | > proc.time() 96 | user system elapsed 97 | 0.420 0.041 0.522 98 | -------------------------------------------------------------------------------- /exttests/connectWithNull.R: -------------------------------------------------------------------------------- 1 | ## connectWithNull test 2 | ## 3 | ## test for the 'Issue 2' on the Google Code issue log 4 | ## reported in April 2009, still open ? 5 | ## 6 | ## Assumes that 7 | ## a) PostgreSQL is running, and 8 | ## b) the current user can connect 9 | ## both of which are not viable for release but suitable while we test 10 | ## 11 | ## Dirk Eddelbuettel, 03 Oct 2009 12 | 13 | ## only run this if this env.var is set correctly 14 | if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 15 | 16 | ## try to load our module and abort if this fails 17 | stopifnot(require(RPostgreSQL)) 18 | stopifnot(require(datasets)) 19 | 20 | ## load the PostgresSQL driver 21 | drv <- dbDriver("PostgreSQL") 22 | 23 | ## connect to the default db -- replacing any of these with NULL 24 | ## should be treated as the default value. 25 | ## Thus, success or failure depends on the environment. 26 | ## Importantly, Segmentation fault should not happen. 27 | con <- dbConnect(drv, 28 | user=Sys.getenv("POSTGRES_USER"), 29 | password=Sys.getenv("POSTGRES_PASSWD"), 30 | host=Sys.getenv("POSTGRES_HOST"), 31 | dbname=Sys.getenv("POSTGRES_DATABASE"), 32 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 33 | 34 | ## do we get here? 35 | cat("Normal connection\n") 36 | cat("Note connection handle will change every time\n") 37 | print(con) 38 | ## and disconnect 39 | dbDisconnect(con) 40 | 41 | cat("connection with user=NULL\n") 42 | try({ 43 | con <- dbConnect(drv, 44 | user=NULL, 45 | password=Sys.getenv("POSTGRES_PASSWD"), 46 | host=Sys.getenv("POSTGRES_HOST"), 47 | dbname=Sys.getenv("POSTGRES_DATABASE"), 48 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 49 | print(con) 50 | dbDisconnect(con) 51 | }) 52 | try({ 53 | cat("connection with password=NULL\n") 54 | con <- dbConnect(drv, 55 | user=Sys.getenv("POSTGRES_USER"), 56 | password=NULL, 57 | host=Sys.getenv("POSTGRES_HOST"), 58 | dbname=Sys.getenv("POSTGRES_DATABASE"), 59 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 60 | print(con) 61 | dbDisconnect(con) 62 | }) 63 | try({ 64 | cat("connection with host=NULL\n") 65 | con <- dbConnect(drv, 66 | user=Sys.getenv("POSTGRES_USER"), 67 | password=Sys.getenv("POSTGRES_PASSWD"), 68 | host=NULL, 69 | dbname=Sys.getenv("POSTGRES_DATABASE"), 70 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 71 | print(con) 72 | dbDisconnect(con) 73 | }) 74 | try({ 75 | cat("connection with dbname=NULL\n") 76 | con <- dbConnect(drv, 77 | user=Sys.getenv("POSTGRES_USER"), 78 | password=Sys.getenv("POSTGRES_PASSWD"), 79 | host=Sys.getenv("POSTGRES_HOST"), 80 | dbname=NULL, 81 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 82 | print(con) 83 | dbDisconnect(con) 84 | }) 85 | try({ 86 | cat("connection with port=NULL\n") 87 | con <- dbConnect(drv, 88 | user=Sys.getenv("POSTGRES_USER"), 89 | password=Sys.getenv("POSTGRES_PASSWD"), 90 | host=Sys.getenv("POSTGRES_HOST"), 91 | dbname=Sys.getenv("POSTGRES_DATABASE"), 92 | port=NULL) 93 | print(con) 94 | ## and disconnect 95 | dbDisconnect(con) 96 | }) 97 | cat("PASS: reached to the end of the test code without segmentation fault\n") 98 | }else{ 99 | cat("Skip.\n") 100 | } 101 | -------------------------------------------------------------------------------- /exttests/datetimeTests.R: -------------------------------------------------------------------------------- 1 | 2 | ## Test of date and datetime types, based on earlier version in inst/devTests 3 | ## 4 | ## Dirk Eddelbuettel, 21 Oct 2008 5 | 6 | dbTypeTests <- function(con, dateclass="timestamp without time zone") { 7 | cat("\n\n**** Trying with ", dateclass, "\n") 8 | 9 | if (dbExistsTable(con, "tempostgrestable")) 10 | dbRemoveTable(con, "tempostgrestable") 11 | 12 | dbGetQuery(con, paste("create table tempostgrestable (tt ", dateclass, ", zz integer);", sep="")) 13 | dbGetQuery(con, "insert into tempostgrestable values('2008-07-01 14:15:16.123', 1);") 14 | 15 | now <- ISOdatetime(2000,1,2,3,4,5.678) 16 | dbGetQuery(con, paste("insert into tempostgrestable values('", format(now), "', 2);", sep="")) 17 | dbGetQuery(con, paste("insert into tempostgrestable values('infinity', 3);", sep="")) 18 | dbGetQuery(con, paste("insert into tempostgrestable values('-infinity', 4);", sep="")) 19 | dbGetQuery(con, paste("insert into tempostgrestable values(NULL, 5);", sep="")) 20 | 21 | res <- dbReadTable(con, "tempostgrestable") 22 | print(res) 23 | 24 | res <- dbSendQuery(con, "select tt from tempostgrestable;") 25 | data <- fetch(res, n=-1) 26 | print(dbColumnInfo(res)) 27 | 28 | times <- data[,1] 29 | print(times) 30 | print(class(times[1])) 31 | 32 | print(diff(times)) 33 | 34 | dbRemoveTable(con, "tempostgrestable") 35 | invisible(NULL) 36 | } 37 | 38 | ## only run this if this env.var is set correctly 39 | if ((Sys.getenv("POSTGRES_USER") != "") & 40 | (Sys.getenv("POSTGRES_HOST") != "") & 41 | (Sys.getenv("POSTGRES_DATABASE") != "")) { 42 | 43 | ## try to load our module and abort if this fails 44 | stopifnot(require(RPostgreSQL)) 45 | 46 | ## Force a timezone to make the tests comparable at different locations 47 | Sys.setenv("PGDATESTYLE"="German") 48 | Sys.setenv("TZ"="UTC") 49 | 50 | ## load the PostgresSQL driver 51 | drv <- dbDriver("PostgreSQL") 52 | ## can't print result as it contains process id which changes print(summary(drv)) 53 | 54 | ## connect to the default db 55 | con <- dbConnect(drv, 56 | user=Sys.getenv("POSTGRES_USER"), 57 | password=Sys.getenv("POSTGRES_PASSWD"), 58 | host=Sys.getenv("POSTGRES_HOST"), 59 | dbname=Sys.getenv("POSTGRES_DATABASE"), 60 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 61 | 62 | dbTypeTests(con, "timestamp") 63 | # dbTypeTests(con, "timestamp with time zone") 64 | # output differs depending on the compute environment 65 | dbTypeTests(con, "date") 66 | 67 | dbDisconnect(con) 68 | } 69 | 70 | -------------------------------------------------------------------------------- /exttests/dbColumnInfo.R: -------------------------------------------------------------------------------- 1 | ## dbColumnInfo test 2 | ## This test confirms that dbColumnInfo() will not cause segfault under gctorture() 3 | ## Initial report was sporadic segfault (Issue 42) 4 | ## and it was found reproducile under gctorture() 5 | ## 6 | ## Assumes that 7 | ## a) PostgreSQL is running, and 8 | ## b) the current user can connect 9 | ## both of which are not viable for release but suitable while we test 10 | ## 11 | ## Dirk Eddelbuettel, 10 Sep 2009 12 | 13 | ## only run this if this env.var is set correctly 14 | if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 15 | 16 | ## try to load our module and abort if this fails 17 | stopifnot(require(RPostgreSQL)) 18 | 19 | ## load the PostgresSQL driver 20 | drv <- dbDriver("PostgreSQL") 21 | 22 | ## connect to the default db 23 | con <- dbConnect(drv, 24 | user=Sys.getenv("POSTGRES_USER"), 25 | password=Sys.getenv("POSTGRES_PASSWD"), 26 | host=Sys.getenv("POSTGRES_HOST"), 27 | dbname=Sys.getenv("POSTGRES_DATABASE"), 28 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 29 | 30 | 31 | # create a table 32 | res <- dbGetQuery(con, "CREATE TABLE aa (pk integer primary key, v1 float not null, v2 float)" ) 33 | 34 | ## run a simple query and show the query result 35 | res <- dbGetQuery(con, "INSERT INTO aa VALUES(3, 2, NULL)" ) 36 | res <- dbSendQuery(con, "select pk, v1, v2, v1+v2 from aa") 37 | cat("This would take a while due to gctorture()\n") 38 | cat("dbColumnInfo\n") 39 | gctorture() 40 | print(dbColumnInfo(res)) 41 | print(dbColumnInfo(res)) 42 | cat("SELECT result\n") 43 | df <- fetch(res, n=-1) 44 | print(df) 45 | 46 | ## cleanup 47 | cat("Removing \"AA\"\n") 48 | dbRemoveTable(con, "aa") 49 | ## and disconnect 50 | dbDisconnect(con) 51 | }else{ 52 | cat("Skip.\n") 53 | } 54 | -------------------------------------------------------------------------------- /exttests/dbWriteTableFailTest.R: -------------------------------------------------------------------------------- 1 | 2 | ## dbWriteTable test 3 | ## 4 | ## Assumes that 5 | ## a) PostgreSQL is running, and 6 | ## b) the current user can connect 7 | ## both of which are not viable for release but suitable while we test 8 | ## 9 | ## Dirk Eddelbuettel, 10 Sep 2009 10 | 11 | ## only run this if this env.var is set correctly 12 | if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 13 | 14 | ## try to load our module and abort if this fails 15 | stopifnot(require(RPostgreSQL)) 16 | stopifnot(require(datasets)) 17 | 18 | ## load the PostgresSQL driver 19 | drv <- dbDriver("PostgreSQL") 20 | 21 | ## connect to the default db 22 | con <- dbConnect(drv, 23 | user=Sys.getenv("POSTGRES_USER"), 24 | password=Sys.getenv("POSTGRES_PASSWD"), 25 | host=Sys.getenv("POSTGRES_HOST"), 26 | dbname=Sys.getenv("POSTGRES_DATABASE"), 27 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 28 | 29 | 30 | if (dbExistsTable(con, "rockdata")) { 31 | print("Removing rockdata\n") 32 | dbRemoveTable(con, "rockdata") 33 | } 34 | cat("create incompatible table rockdata\n") 35 | dbGetQuery(con, "CREATE TABLE rockdata (a int, b varchar(5))") 36 | 37 | cat("write table to rockdata with append=TRUE\n") 38 | try({res <-dbWriteTable(con, 'rockdata', rock, append=TRUE, overwrite=FALSE) 39 | print(res) 40 | if(res == FALSE){ 41 | cat("PASS as the return value is false\n") 42 | }else{ 43 | cat("FAIL as the return value is true\n") 44 | } 45 | }) 46 | 47 | cat("write table to rockdata\n") 48 | try({res <- dbWriteTable(con, 'rockdata', rock) 49 | if(res == FALSE){ 50 | print(res) 51 | cat("PASS as the return value is false\n") 52 | }else{ 53 | cat("FAIL as the return value is true\n") 54 | } 55 | }) 56 | 57 | ## run a simple query and show the query result 58 | res <- dbGetQuery(con, "select * from rockdata limit 10") 59 | print(res) 60 | 61 | 62 | ## cleanup 63 | if (dbExistsTable(con, "rockdata")) { 64 | print("Removing rockdata\n") 65 | dbRemoveTable(con, "rockdata") 66 | } 67 | 68 | ## and disconnect 69 | dbDisconnect(con) 70 | } 71 | -------------------------------------------------------------------------------- /exttests/dbWriteTableFailTest.Rout.save: -------------------------------------------------------------------------------- 1 | 2 | R version 3.3.1 (2016-06-21) -- "Bug in Your Hair" 3 | Copyright (C) 2016 The R Foundation for Statistical Computing 4 | Platform: x86_64-pc-linux-gnu (64-bit) 5 | 6 | R is free software and comes with ABSOLUTELY NO WARRANTY. 7 | You are welcome to redistribute it under certain conditions. 8 | Type 'license()' or 'licence()' for distribution details. 9 | 10 | R is a collaborative project with many contributors. 11 | Type 'contributors()' for more information and 12 | 'citation()' on how to cite R or R packages in publications. 13 | 14 | Type 'demo()' for some demos, 'help()' for on-line help, or 15 | 'help.start()' for an HTML browser interface to help. 16 | Type 'q()' to quit R. 17 | 18 | > 19 | > ## dbWriteTable test 20 | > ## 21 | > ## Assumes that 22 | > ## a) PostgreSQL is running, and 23 | > ## b) the current user can connect 24 | > ## both of which are not viable for release but suitable while we test 25 | > ## 26 | > ## Dirk Eddelbuettel, 10 Sep 2009 27 | > 28 | > ## only run this if this env.var is set correctly 29 | > if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 30 | + 31 | + ## try to load our module and abort if this fails 32 | + stopifnot(require(RPostgreSQL)) 33 | + stopifnot(require(datasets)) 34 | + 35 | + ## load the PostgresSQL driver 36 | + drv <- dbDriver("PostgreSQL") 37 | + 38 | + ## connect to the default db 39 | + con <- dbConnect(drv, 40 | + user=Sys.getenv("POSTGRES_USER"), 41 | + password=Sys.getenv("POSTGRES_PASSWD"), 42 | + host=Sys.getenv("POSTGRES_HOST"), 43 | + dbname=Sys.getenv("POSTGRES_DATABASE"), 44 | + port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 45 | + 46 | + 47 | + if (dbExistsTable(con, "rockdata")) { 48 | + print("Removing rockdata\n") 49 | + dbRemoveTable(con, "rockdata") 50 | + } 51 | + cat("create incompatible table rockdata\n") 52 | + dbGetQuery(con, "CREATE TABLE rockdata (a int, b varchar(5))") 53 | + 54 | + cat("write table to rockdata with append=TRUE\n") 55 | + try({res <-dbWriteTable(con, 'rockdata', rock, append=TRUE, overwrite=FALSE) 56 | + print(res) 57 | + if(res == FALSE){ 58 | + cat("PASS as the return value is false\n") 59 | + }else{ 60 | + cat("FAIL as the return value is true\n") 61 | + } 62 | + }) 63 | + 64 | + cat("write table to rockdata\n") 65 | + try({res <- dbWriteTable(con, 'rockdata', rock) 66 | + if(res == FALSE){ 67 | + print(res) 68 | + cat("PASS as the return value is false\n") 69 | + }else{ 70 | + cat("FAIL as the return value is true\n") 71 | + } 72 | + }) 73 | + 74 | + ## run a simple query and show the query result 75 | + res <- dbGetQuery(con, "select * from rockdata limit 10") 76 | + print(res) 77 | + 78 | + 79 | + ## cleanup 80 | + if (dbExistsTable(con, "rockdata")) { 81 | + print("Removing rockdata\n") 82 | + dbRemoveTable(con, "rockdata") 83 | + } 84 | + 85 | + ## and disconnect 86 | + dbDisconnect(con) 87 | + } 88 | Loading required package: RPostgreSQL 89 | Loading required package: DBI 90 | create incompatible table rockdata 91 | write table to rockdata with append=TRUE 92 | Error in postgresqlpqExec(new.con, sql4) : 93 | RS-DBI driver: (could not Retrieve the result : ERROR: column "row.names" of relation "rockdata" does not exist 94 | ) 95 | write table to rockdata 96 | [1] FALSE 97 | PASS as the return value is false 98 | [1] a b 99 | <0 rows> (or 0-length row.names) 100 | [1] "Removing rockdata\n" 101 | [1] TRUE 102 | Warning message: 103 | In postgresqlWriteTable(conn, name, value, ...) : 104 | table rockdata exists in database: aborting assignTable 105 | > 106 | > proc.time() 107 | user system elapsed 108 | 0.455 0.040 0.499 109 | -------------------------------------------------------------------------------- /exttests/selectWhereZero.R: -------------------------------------------------------------------------------- 1 | 2 | ## selectWhereZero test 3 | ## 4 | ## test for the 'Issue 1' on the Google Code issue log 5 | ## this was reported in June and fixed by Joe Conway (svr committ r100) 6 | ## 7 | ## Assumes that 8 | ## a) PostgreSQL is running, and 9 | ## b) the current user can connect 10 | ## both of which are not viable for release but suitable while we test 11 | ## 12 | ## Dirk Eddelbuettel, 03 Oct 2009 13 | 14 | ## only run this if this env.var is set correctly 15 | if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 16 | 17 | ## try to load our module and abort if this fails 18 | stopifnot(require(RPostgreSQL)) 19 | stopifnot(require(datasets)) 20 | 21 | ## load the PostgresSQL driver 22 | drv <- dbDriver("PostgreSQL") 23 | 24 | ## connect to the default db 25 | con <- dbConnect(drv, 26 | user=Sys.getenv("POSTGRES_USER"), 27 | password=Sys.getenv("POSTGRES_PASSWD"), 28 | host=Sys.getenv("POSTGRES_HOST"), 29 | dbname=Sys.getenv("POSTGRES_DATABASE"), 30 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 31 | 32 | 33 | if (dbExistsTable(con, "tmpirisdata")) { 34 | print("Removing tmpirisdata\n") 35 | dbRemoveTable(con, "tmpirisdata") 36 | } 37 | 38 | dbWriteTable(con, "tmpirisdata", iris) 39 | 40 | ## run a simple query and show the query result 41 | res <- dbGetQuery(con, "select * from tmpirisdata where \"Species\"=0") 42 | print(res) 43 | 44 | ## cleanup 45 | if (dbExistsTable(con, "tmpirisdata")) { 46 | print("Removing tmpirisdata\n") 47 | dbRemoveTable(con, "tmpirisdata") 48 | } 49 | 50 | ## and disconnect 51 | dbDisconnect(con) 52 | cat("PASS: reached to the end of the test code without segmentation fault\n") 53 | } 54 | -------------------------------------------------------------------------------- /exttests/selectWhereZero.Rout.save: -------------------------------------------------------------------------------- 1 | 2 | R version 3.3.1 (2016-06-21) -- "Bug in Your Hair" 3 | Copyright (C) 2016 The R Foundation for Statistical Computing 4 | Platform: x86_64-pc-linux-gnu (64-bit) 5 | 6 | R is free software and comes with ABSOLUTELY NO WARRANTY. 7 | You are welcome to redistribute it under certain conditions. 8 | Type 'license()' or 'licence()' for distribution details. 9 | 10 | R is a collaborative project with many contributors. 11 | Type 'contributors()' for more information and 12 | 'citation()' on how to cite R or R packages in publications. 13 | 14 | Type 'demo()' for some demos, 'help()' for on-line help, or 15 | 'help.start()' for an HTML browser interface to help. 16 | Type 'q()' to quit R. 17 | 18 | > 19 | > ## selectWhereZero test 20 | > ## 21 | > ## test for the 'Issue 1' on the Google Code issue log 22 | > ## this was reported in June and fixed by Joe Conway (svr committ r100) 23 | > ## 24 | > ## Assumes that 25 | > ## a) PostgreSQL is running, and 26 | > ## b) the current user can connect 27 | > ## both of which are not viable for release but suitable while we test 28 | > ## 29 | > ## Dirk Eddelbuettel, 03 Oct 2009 30 | > 31 | > ## only run this if this env.var is set correctly 32 | > if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 33 | + 34 | + ## try to load our module and abort if this fails 35 | + stopifnot(require(RPostgreSQL)) 36 | + stopifnot(require(datasets)) 37 | + 38 | + ## load the PostgresSQL driver 39 | + drv <- dbDriver("PostgreSQL") 40 | + 41 | + ## connect to the default db 42 | + con <- dbConnect(drv, 43 | + user=Sys.getenv("POSTGRES_USER"), 44 | + password=Sys.getenv("POSTGRES_PASSWD"), 45 | + host=Sys.getenv("POSTGRES_HOST"), 46 | + dbname=Sys.getenv("POSTGRES_DATABASE"), 47 | + port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 48 | + 49 | + 50 | + if (dbExistsTable(con, "tmpirisdata")) { 51 | + print("Removing tmpirisdata\n") 52 | + dbRemoveTable(con, "tmpirisdata") 53 | + } 54 | + 55 | + dbWriteTable(con, "tmpirisdata", iris) 56 | + 57 | + ## run a simple query and show the query result 58 | + res <- dbGetQuery(con, "select * from tmpirisdata where \"Species\"=0") 59 | + print(res) 60 | + 61 | + ## cleanup 62 | + if (dbExistsTable(con, "tmpirisdata")) { 63 | + print("Removing tmpirisdata\n") 64 | + dbRemoveTable(con, "tmpirisdata") 65 | + } 66 | + 67 | + ## and disconnect 68 | + dbDisconnect(con) 69 | + cat("PASS: reached to the end of the test code without segmentation fault\n") 70 | + } 71 | Loading required package: RPostgreSQL 72 | Loading required package: DBI 73 | Error in postgresqlExecStatement(conn, statement, ...) : 74 | RS-DBI driver: (could not Retrieve the result : ERROR: operator does not exist: text = integer 75 | LINE 1: select * from tmpirisdata where "Species"=0 76 | ^ 77 | HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 78 | ) 79 | NULL 80 | [1] "Removing tmpirisdata\n" 81 | PASS: reached to the end of the test code without segmentation fault 82 | Warning message: 83 | In postgresqlQuickSQL(conn, statement, ...) : 84 | Could not create execute: select * from tmpirisdata where "Species"=0 85 | > 86 | > proc.time() 87 | user system elapsed 88 | 0.468 0.041 0.546 89 | -------------------------------------------------------------------------------- /exttests/unknowntype.R: -------------------------------------------------------------------------------- 1 | ## unknowntype test 2 | ## 3 | ## test for 4 | ## Issue 5 comment #12 5 | ## on the Google Code issue log 6 | ## 7 | ## Assumes that 8 | ## a) PostgreSQL is running, and 9 | ## b) the current user can connect 10 | ## both of which are not viable for release but suitable while we test 11 | ## 12 | ## Dirk Eddelbuettel, 03 Oct 2009 13 | 14 | ## only run this if this env.var is set correctly 15 | if (Sys.getenv("POSTGRES_USER") != "" & Sys.getenv("POSTGRES_HOST") != "" & Sys.getenv("POSTGRES_DATABASE") != "") { 16 | 17 | ## try to load our module and abort if this fails 18 | stopifnot(require(RPostgreSQL)) 19 | 20 | ## load the PostgresSQL driver 21 | drv <- dbDriver("PostgreSQL") 22 | 23 | ## connect to the default db 24 | con <- dbConnect(drv, 25 | user=Sys.getenv("POSTGRES_USER"), 26 | password=Sys.getenv("POSTGRES_PASSWD"), 27 | host=Sys.getenv("POSTGRES_HOST"), 28 | dbname=Sys.getenv("POSTGRES_DATABASE"), 29 | port=ifelse((p<-Sys.getenv("POSTGRES_PORT"))!="", p, 5432)) 30 | 31 | 32 | if (dbExistsTable(con, "tmpirisdata")) { 33 | print("Removing tmpirisdata\n") 34 | dbRemoveTable(con, "tmpirisdata") 35 | } 36 | 37 | 38 | ## run a simple query and show the query result 39 | res <- dbGetQuery(con, "create table tmpirisdata (ra REAL[])") 40 | res <- dbSendQuery(con, "select ra from tmpirisdata") 41 | cat("Note connection handle will change every time\n") 42 | print(res) 43 | type <- dbColumnInfo(res) 44 | print(type) 45 | data <- fetch(res, -1) 46 | print(data) 47 | 48 | ## cleanup 49 | if (dbExistsTable(con, "tmpirisdata")) { 50 | print("Removing tmpirisdata\n") 51 | dbRemoveTable(con, "tmpirisdata") 52 | } 53 | 54 | ## and disconnect 55 | dbDisconnect(con) 56 | cat("PASS: reached to the end of the test code without segmentation fault\n") 57 | }else{ 58 | cat("Skip.\n") 59 | } 60 | --------------------------------------------------------------------------------