From c8d23df75551096e33b0b9baccbfa9352423c374 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Tue, 12 Jan 2010 23:30:58 -0500 Subject: [PATCH] Implementation for primaryKey() that works with composite primary keys. --- framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php index 78c6f6d90..083acdebe 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php +++ b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Schema.php @@ -213,8 +213,13 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema */ public function primaryKey($tableName, $name = null) { - list($defaultPk, ) = $this->pkAndSequenceFor($tableName); - return $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array($defaultPk))); + $sql = 'SELECT column_name + FROM information_schema.constraint_column_usage + WHERE table_name = ' . $this->quoteString($tableName) . + ' AND constraint_name = ' . $this->quoteString($tableName . '_pkey'); + $pk = $this->selectValues($sql, $name); + + return $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, $pk)); } /** @@ -652,6 +657,7 @@ class Horde_Db_Adapter_Postgresql_Schema extends Horde_Db_Adapter_Base_Schema */ public function columnDefinitions($tableName, $name = null) { + /*@TODO See if we can get this from information_schema instead */ return $this->selectAll(' SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d -- 2.11.0