From: Brian G. <br...@vf...> - 2003-11-06 17:36:50
|
David Macbanay writes: > Now I get a error from line 484 where it performs a "show index" query. I rewrote this too, but I don't know how well it will fare on multi-column indexes. It works fine for the default case of a single primary key though: function sqlGetIndex($tableName){ $tablename = $this->tbl_prefix . $tableName; $sql = "SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid) as column FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c.oid = (SELECT c.oid FROM pg_catalog.pg_class c WHERE c.relname ~ '^" . $tablename . "$') AND c.oid = i.indrelid AND i.indexrelid = c2.oid ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname"; // echo $sql; if ($tableInfo = $this->getAllAssoc($sql)) { if (strlen($tableInfo[0]["column"]) > 0) { $start = strpos($tableInfo[0]["column"], "(") + 1; $end = strpos($tableInfo[0]["column"], "("); return substr($tableInfo[0]["column"], $start, $end-$start); } } return NULL; } |