From 60536f1e62f623370b06a39fcb98c3b133243dd9 Mon Sep 17 00:00:00 2001 From: "ondrej.zara" Date: Mon, 15 Mar 2010 09:23:45 +0000 Subject: [PATCH] #75, thanks to geompse --HG-- extra : convert_revision : svn%3Ab267cdba-c1da-11dd-874b-8bacd04a0a74/trunk%4083 --- backend/php-postgresql/index.php | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/backend/php-postgresql/index.php b/backend/php-postgresql/index.php index 95f28c8..ceacd24 100644 --- a/backend/php-postgresql/index.php +++ b/backend/php-postgresql/index.php @@ -148,6 +148,50 @@ $keyname1 = $keyname; } if ($keyname1 != "") { $xml .= ''; } + + // index + $qstr = 'SELECT pcx."relname" as "INDEX_NAME", pa."attname" as + "COLUMN_NAME", * FROM "pg_index" pi LEFT JOIN "pg_class" pcx ON pi."indexrelid" = + pcx."oid" LEFT JOIN "pg_class" pci ON pi."indrelid" = pci."oid" LEFT JOIN1 + "pg_attribute" pa ON pa."attrelid" = pci."oid" AND pa."attnum" = ANY(pi."indkey") + WHERE pci."relname" = \''.$table.'\' order by pa."attnum"'; + $result2 = pg_query($conn, $qstr); + $idx = array(); + while ($row2 = pg_fetch_array($result2)) { + $name = $row2["INDEX_NAME"]; + if (array_key_exists($name, $idx)) { + $obj = $idx[$name]; + } else { + $t = "INDEX"; + if ($row2['indisunique'] == 't') { + $t = "UNIQUE"; + break; + } + if ($row2['indisprimary'] == 't') { + $t = "PRIMARY"; + break; + } + + $obj = array( + "columns" => array(), + "type" => $t + ); + } + + $obj["columns"][] = $row2["COLUMN_NAME"]; + $idx[$name] = $obj; + } + + foreach ($idx as $name=>$obj) { + $xmlkey = ''; + for ($i=0;$i'; + } + $xmlkey .= ''; + $xml .= $xmlkey; + } + $xml .= ""; }