Skip to content

Make PostgreSQL ready for Gramps 6.0 #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: maintenance/gramps60
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions PostgreSQL/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does postgresql have this convention:

Suggested change
"WHERE table_name = %s AND column_name = %s",
"WHERE table_name = ? AND column_name = ?",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what psycopg2 uses - it's like that in the rest of the addon as well.

(table, column)
)
return self.fetchone()[0] != 0

def close(self):
self.__connection.close()

Expand Down