From f2d6fd8670ba382cba7d1c27e148c4d3487d4e2c Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Fri, 19 Jun 2015 12:46:09 -0700 Subject: [PATCH] support postgresql in addition to sqlite --- trunk/R/db.R | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/trunk/R/db.R b/trunk/R/db.R index 2dc6892..d604e7f 100644 --- a/trunk/R/db.R +++ b/trunk/R/db.R @@ -1,9 +1,22 @@ db_start <- function() { - drv <- dbDriver('SQLite') - if (is.null(drv)) stop("db_start: Could not access driver for SQLite.\n") - con <- dbConnect(drv, dbname=file.path(cache_root,'cran2deb.db')) - if (is.null(con)) stop("db_start: Could open connection to file 'cran2deb.db' in directory",cache_root,".\n") + pg.service <- Sys.getenv('CRAN2DEB_PG') + if (!is.null(pg.service) && + any(grepl(".",pg.service))) { + drv <- dbDriver("PostgreSQL") + if (is.null(drv)) { + stop("db_start: Could not access driver for postgresql.") + } + con <- dbConnect(drv,service=pg.service) + if (is.null(con)) { + stop("db_start: Could open connection to service ",pg.service) + } + } else { + drv <- dbDriver('SQLite') + if (is.null(drv)) stop("db_start: Could not access driver for SQLite.\n") + con <- dbConnect(drv, dbname=file.path(cache_root,'cran2deb.db')) + if (is.null(con)) stop("db_start: Could open connection to file 'cran2deb.db' in directory",cache_root,".\n") + } if (!dbExistsTable(con,'sysreq_override')) { dbGetQuery(con,paste('CREATE TABLE sysreq_override (' ,' depend_alias TEXT NOT NULL' -- 2.39.2