From 6a1b455978cd86f03dc3bc2eb0e30ced07da8cdb Mon Sep 17 00:00:00 2001 From: David Straub Date: Wed, 5 Feb 2025 21:39:38 +0100 Subject: [PATCH] Make PostgreSQL ready for Gramps 6.0 --- PostgreSQL/postgresql.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PostgreSQL/postgresql.py b/PostgreSQL/postgresql.py index 76c9c006b..1fd537b56 100644 --- a/PostgreSQL/postgresql.py +++ b/PostgreSQL/postgresql.py @@ -190,6 +190,23 @@ def table_exists(self, table): "WHERE table_name=%s;", [table]) return self.fetchone()[0] != 0 + def column_exists(self, table, column): + """ + Test whether the specified SQL column exists in the specified table. + :param table: table name to check. + :type table: str + :param column: column name to check. + :type column: str + :returns: True if the column exists, False otherwise. + :rtype: bool + """ + self.__cursor.execute( + "SELECT COUNT(*) FROM information_schema.columns " + "WHERE table_name = %s AND column_name = %s", + (table, column) + ) + return self.fetchone()[0] != 0 + def close(self): self.__connection.close()