--- usr/share/pear/DB/oci8.php 2004-12-17 10:25:42.000000000 +0100 +++ tmp/kde-luca/kompare0I3qWa.tmp 2005-04-14 16:33:34.232597488 +0200 @@ -842,6 +842,72 @@ } @OCIFreeStatement($stmt); + + + /* + * Read info about foreign keys + */ + if ($this->options['fetch_fk_info']) { + $q_fields = "select UC.constraint_name, ucc.table_name,Ucc.column_name + from USER_CONSTRAINTS UC ,USER_CONS_COLUMNS UCC + WHERE UC.owner=UCC.owner + AND UC.r_constraint_name=UCC.constraint_name + AND UC.constraint_type ='R' + AND UC.table_name = '$result'"; + + $this->last_query = $q_fields; + + if (!$stmt = @OCIParse($this->connection, $q_fields)) { + return $this->oci8RaiseError(DB_ERROR_NEED_MORE_DATA); + } + if (!@OCIExecute($stmt, OCI_DEFAULT)) { + return $this->oci8RaiseError($stmt); + } + $fk_array = array(); + while (@OCIFetch($stmt)) { + $fk_name = $case_func(@OCIResult($stmt, 1)); + $fk_table = @OCIResult($stmt, 2); + $fk_col = @OCIResult($stmt, 3); + + if (array_key_exists($fk_name ,$fk_array)) + { + // constraint on multiple cols over destination table + $fk_res = $fk_array[$fk_name]; + $fk_res['fk_dest_column'] .= ", ".$fk_col; + } else { + + $fk_res = array(); + $fk_res['fk_dest_table'] = $fk_table; + $fk_res['fk_dest_column'] = $fk_col; + } + + // query1 + $q_fields = "SELECT COLUMN_NAME FROM USER_CONS_COLUMNS + WHERE CONSTRAINT_NAME = '".$fk_name."'"; + + $this->last_query = $q_fields; + + if (!$stmt1 = @OCIParse($this->connection, $q_fields)) { + return $this->oci8RaiseError(DB_ERROR_NEED_MORE_DATA); + } + if (!@OCIExecute($stmt1, OCI_DEFAULT)) { + return $this->oci8RaiseError($stmt1); + } + while (@OCIFetch($stmt1)) { + $fk_source_col[] = @OCIResult($stmt1, 1); + } + $fk_res['fk_source_cols'] = implode (',', $fk_source_col); + unset($fk_source_col); + + @OCIFreeStatement($stmt1); + + $fk_array[$fk_name] = $fk_res; + } + + @OCIFreeStatement($stmt); + $res['foreign_keys'] = $fk_array; + } + } else { if (isset($result->result)) { /*