Source: php-horde-db
Version: 2.4.1-8
Severity: grave
Tags: patch
Hi,
php-horde-db's primaryKey() method for PostgreSQL relies on undefined
ordering when reading the columns of a multi-column primary key. So
far this worked, but on PG17 (already in testing, but not the default
version yet), this breaks:
209s 1) Horde_Db_Adapter_Pdo_PgsqlTest::testPrimaryKey
209s Failed asserting that two strings are equal.
209s --- Expected
209s +++ Actual
209s @@ @@
209s -'foo,bar'
209s +'bar,foo'
https://ci.debian.net/packages/p/php-horde-db/testing/armel/51827881/
The attached patch makes it use a properly ordered catalog query.
I intend to NMU this since it's holding up the transition of PG17 as
the default PG version.
Thanks,
Christoph
--- a/Horde_Db-2.4.1/lib/Horde/Db/Adapter/Postgresql/Schema.php
+++ b/Horde_Db-2.4.1/lib/Horde/Db/Adapter/Postgresql/Schema.php
@@ -271,15 +271,18 @@ class Horde_Db_Adapter_Postgresql_Schema
public function primaryKey($tableName, $name = null)
{
$sql = '
- SELECT column_name
- FROM information_schema.constraint_column_usage
- WHERE table_name = ?
- AND constraint_name = (SELECT constraint_name
- FROM
information_schema.table_constraints
- WHERE table_name = ?
- AND constraint_type = ?)';
+ SELECT a.attname
+ FROM
+ pg_index i,
+ unnest(indkey) WITH ORDINALITY u (attnum, pos)
+ JOIN pg_attribute a ON u.attnum = a.attnum
+ WHERE
+ i.indisprimary
+ AND i.indrelid = ?::regclass
+ AND a.attrelid = i.indrelid
+ ORDER BY u.pos';
$pk = $this->selectValues($sql,
- array($tableName, $tableName, 'PRIMARY KEY'),
+ array($tableName),
$name);
return $this->makeIndex($tableName, 'PRIMARY', true, true, $pk);