From: Jim W. <ji...@ke...> - 2003-12-14 18:49:33
|
Brian Ghidinelli wrote before I joined the list: > 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; > } You can pull off the same thing with a simpler query on just the pg_indexes table. Note that the index names end with "_pkey" if they are primary for the table. You are right about this function not working with multicolumn indexes, depending on what you mean by "not working" that is. If the purpose is to establish next ID values _prior_ to inserting the rows, this is will as you said work with those single column indices. The only sensible solution to this problem I can think of is to build a core application table of autoincremented primary keys that is queried in this routine. Actually the routine should be renamed to something else like sqlgetAIkey or something similar, since it isn't ever going to do what it says. I'm wondering where you are at with this project of getting running in postgres. It seems that I've got something working now here, still going through the different modules to check functionality. My changes are based on the 0.9.3-1 release and the backport fixes that were posted on this list week before last (the phpws-0.9.3-1.supplemental.zip file). If there is interest, I could easily supply a diff -u file for anyone who wants it. Also, I'm kind of wondering where this project actually is in terms of moving toward multiple database support. There seems to be some work in the 094 cvs, but much, and reading some of the archives it appears that the developers may be more concerned with other issues. Is there much interest in this moving forward? Best regards, Jim |