From 8c589aaf0a4857c54ce36fbb49e5e95990dc6d09 Mon Sep 17 00:00:00 2001 From: "Gregory R. Warnes" Date: Mon, 7 Aug 2023 12:44:50 -0400 Subject: [PATCH 1/4] Resolve #129 by adding additional WHERE clause for `not attisdropped` to filter out dropped columns. --- RPostgreSQL/R/PostgreSQL.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RPostgreSQL/R/PostgreSQL.R b/RPostgreSQL/R/PostgreSQL.R index 8db97c9..3d52522 100644 --- a/RPostgreSQL/R/PostgreSQL.R +++ b/RPostgreSQL/R/PostgreSQL.R @@ -234,6 +234,7 @@ setMethod("dbListFields", flds <- dbGetQuery(conn, paste("select a.attname from pg_attribute a, pg_class c, pg_tables t, pg_namespace nsp", " where a.attrelid = c.oid and c.relname = tablename and c.relnamespace = nsp.oid and a.attnum > 0 and ", + "and not a.attisdropped ", "nspname = current_schema() and schemaname = nspname and ", "tablename = '", postgresqlEscapeStrings(conn, name), "'", sep=""))[,1] } @@ -242,6 +243,7 @@ setMethod("dbListFields", flds <- dbGetQuery(conn, paste("select a.attname from pg_attribute a, pg_class c, pg_tables t, pg_namespace nsp", " where a.attrelid = c.oid and c.relname = t.tablename and c.relnamespace = nsp.oid and a.attnum > 0 and ", + "and not a.attisdropped ", "nspname = schemaname ", "and schemaname = '", postgresqlEscapeStrings(conn, name[1]), "' ", "and tablename = '", postgresqlEscapeStrings(conn, name[2]), "'", sep=""))[,1] From 145005098d90f09021c6ac85220aab6dbd7ba2fb Mon Sep 17 00:00:00 2001 From: "Gregory R. Warnes" Date: Mon, 7 Aug 2023 13:09:12 -0400 Subject: [PATCH 2/4] Conjunction was in the wrong place. --- RPostgreSQL/R/PostgreSQL.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RPostgreSQL/R/PostgreSQL.R b/RPostgreSQL/R/PostgreSQL.R index 3d52522..4b9a4e1 100644 --- a/RPostgreSQL/R/PostgreSQL.R +++ b/RPostgreSQL/R/PostgreSQL.R @@ -234,7 +234,7 @@ setMethod("dbListFields", flds <- dbGetQuery(conn, paste("select a.attname from pg_attribute a, pg_class c, pg_tables t, pg_namespace nsp", " where a.attrelid = c.oid and c.relname = tablename and c.relnamespace = nsp.oid and a.attnum > 0 and ", - "and not a.attisdropped ", + "not a.attisdropped and ", "nspname = current_schema() and schemaname = nspname and ", "tablename = '", postgresqlEscapeStrings(conn, name), "'", sep=""))[,1] } @@ -243,7 +243,7 @@ setMethod("dbListFields", flds <- dbGetQuery(conn, paste("select a.attname from pg_attribute a, pg_class c, pg_tables t, pg_namespace nsp", " where a.attrelid = c.oid and c.relname = t.tablename and c.relnamespace = nsp.oid and a.attnum > 0 and ", - "and not a.attisdropped ", + "not a.attisdropped and ", "nspname = schemaname ", "and schemaname = '", postgresqlEscapeStrings(conn, name[1]), "' ", "and tablename = '", postgresqlEscapeStrings(conn, name[2]), "'", sep=""))[,1] From 4cb8f4d657f3bfe629e1919c0ae8bd3fa1f537c9 Mon Sep 17 00:00:00 2001 From: "Gregory R. Warnes" Date: Wed, 3 Jan 2024 15:42:13 -0500 Subject: [PATCH 3/4] Update PostgreSQL.R Add method definition for `dbIsValid` --- RPostgreSQL/R/PostgreSQL.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RPostgreSQL/R/PostgreSQL.R b/RPostgreSQL/R/PostgreSQL.R index 4b9a4e1..8b255e5 100644 --- a/RPostgreSQL/R/PostgreSQL.R +++ b/RPostgreSQL/R/PostgreSQL.R @@ -73,6 +73,11 @@ setMethod("dbConnect", "character", valueClass = "PostgreSQLConnection" ) +setMethod("dbIsValid", "PostgreSQLConnection", + def = function(dbObj, ... ) isPostgresqlIdCurrent(dbObj, ... ), + valueClass = "logical" +) + ## clone a connection setMethod("dbConnect", "PostgreSQLConnection", def = function(drv, ...) postgresqlCloneConnection(drv, ...), From 2ba0b63c69431558ee1b87cc70c7b48516d2b115 Mon Sep 17 00:00:00 2001 From: "Gregory R. Warnes" Date: Thu, 4 Jan 2024 11:23:58 -0500 Subject: [PATCH 4/4] - Add NULL test to `isPosgresqlIdCurrent`. - Add .gitignore files. --- .gitignore | 4 ++++ RPostgreSQL/.gitignore | 3 +++ RPostgreSQL/R/dbObjectId.R | 1 + RPostgreSQL/src/.gitignore | 3 +++ 4 files changed, 11 insertions(+) create mode 100644 .gitignore create mode 100644 RPostgreSQL/.gitignore create mode 100644 RPostgreSQL/src/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/RPostgreSQL/.gitignore b/RPostgreSQL/.gitignore new file mode 100644 index 0000000..2f5308e --- /dev/null +++ b/RPostgreSQL/.gitignore @@ -0,0 +1,3 @@ +*.log +*.status +*.dSYM diff --git a/RPostgreSQL/R/dbObjectId.R b/RPostgreSQL/R/dbObjectId.R index abf51eb..d8e285e 100644 --- a/RPostgreSQL/R/dbObjectId.R +++ b/RPostgreSQL/R/dbObjectId.R @@ -51,6 +51,7 @@ setMethod("print", "dbObjectId", ## verify that obj refers to a currently open/loaded database isPostgresqlIdCurrent <- function(obj) { + if(is.null(obj)) return(FALSE) obj <- as(obj, "integer") .Call(RS_DBI_validHandle, obj) } diff --git a/RPostgreSQL/src/.gitignore b/RPostgreSQL/src/.gitignore new file mode 100644 index 0000000..aad4fde --- /dev/null +++ b/RPostgreSQL/src/.gitignore @@ -0,0 +1,3 @@ +*.so +*.o +Makevars