From 201a5b6e061b52fee73eac3b8f4fdfb98ffa3fbe Mon Sep 17 00:00:00 2001 From: Alfredo Ramos Date: Wed, 10 Jun 2020 04:41:00 -0500 Subject: [PATCH] [ticket/16525] Remove usage of pg_constraint.consrc for PostgreSQL 12 The column pg_constraint.consrc has been deprecated for a long time, and it was finally removed in PostgreSQL 12.0 PHPBB3-16525 --- phpBB/phpbb/db/extractor/postgres_extractor.php | 14 +++++++------- phpBB/phpbb/db/tools/postgres.php | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/phpBB/phpbb/db/extractor/postgres_extractor.php b/phpBB/phpbb/db/extractor/postgres_extractor.php index 0219d2ac8d..5c569abfdf 100644 --- a/phpBB/phpbb/db/extractor/postgres_extractor.php +++ b/phpBB/phpbb/db/extractor/postgres_extractor.php @@ -208,16 +208,16 @@ class postgres_extractor extends base_extractor } // Generate constraint clauses for CHECK constraints - $sql_checks = "SELECT conname as index_name, consrc - FROM pg_constraint, pg_class bc - WHERE conrelid = bc.oid + $sql_checks = "SELECT pc.conname AS index_name, pg_get_constraintdef(pc.oid) + FROM pg_constraint pc, pg_class bc + WHERE pc.conrelid = bc.oid AND bc.relname = '" . $this->db->sql_escape($table_name) . "' AND NOT EXISTS ( SELECT * - FROM pg_constraint as c, pg_inherits as i - WHERE i.inhrelid = pg_constraint.conrelid - AND c.conname = pg_constraint.conname - AND c.consrc = pg_constraint.consrc + FROM pg_constraint AS c, pg_inherits AS i + WHERE i.inhrelid = pc.conrelid + AND c.conname = pc.conname + AND pg_get_constraintdef(c.oid) = pg_get_constraintdef(pc.oid) AND c.conrelid = i.inhparent )"; $result = $this->db->sql_query($sql_checks); diff --git a/phpBB/phpbb/db/tools/postgres.php b/phpBB/phpbb/db/tools/postgres.php index 077d6e06f9..7cb024d4f6 100644 --- a/phpBB/phpbb/db/tools/postgres.php +++ b/phpBB/phpbb/db/tools/postgres.php @@ -141,7 +141,7 @@ class postgres extends tools $primary_key_gen = isset($prepared_column['primary_key_set']) && $prepared_column['primary_key_set']; } - // create sequence DDL based off of the existance of auto incrementing columns + // create sequence DDL based off of the existence of auto incrementing columns if (!$create_sequence && isset($prepared_column['auto_increment']) && $prepared_column['auto_increment']) { $create_sequence = $column_name; @@ -559,16 +559,16 @@ class postgres extends tools // we don't want to double up on constraints if we change different number data types if (isset($column_data['constraint'])) { - $constraint_sql = "SELECT consrc as constraint_data - FROM pg_constraint, pg_class bc + $constraint_sql = "SELECT pg_get_constraintdef(pc.oid) AS constraint_data + FROM pg_constraint pc, pg_class bc WHERE conrelid = bc.oid - AND bc.relname = '{$table_name}' + AND bc.relname = '" . $this->db->sql_escape($table_name) . "' AND NOT EXISTS ( SELECT * - FROM pg_constraint as c, pg_inherits as i - WHERE i.inhrelid = pg_constraint.conrelid - AND c.conname = pg_constraint.conname - AND c.consrc = pg_constraint.consrc + FROM pg_constraint AS c, pg_inherits AS i + WHERE i.inhrelid = pc.conrelid + AND c.conname = pc.conname + AND pg_get_constraintdef(c.oid) = pg_get_constraintdef(pc.oid) AND c.conrelid = i.inhparent )";