예제 #1
0
 function MetaForeignKeys($table, $owner = FALSE, $upper = FALSE, $asociative = FALSE)
 {
     global $ADODB_FETCH_MODE;
     if ($this->uCaseTables) {
         $table = strtoupper($table);
     }
     $schema = '';
     $this->_findschema($table, $schema);
     $savem = $ADODB_FETCH_MODE;
     $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     $qid = @db2_foreign_keys($this->_connectionID, '', $schema, $table);
     if (!$qid) {
         $ADODB_FETCH_MODE = $savem;
         return false;
     }
     $rs = new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     /*
     $rs->fields indices
     0 PKTABLE_CAT
     1 PKTABLE_SCHEM
     2 PKTABLE_NAME
     3 PKCOLUMN_NAME
     4 FKTABLE_CAT
     5 FKTABLE_SCHEM
     6 FKTABLE_NAME
     7 FKCOLUMN_NAME
     */
     if (!$rs) {
         return false;
     }
     $foreign_keys = array();
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             if (!is_array($foreign_keys[$rs->fields[5] . '.' . $rs->fields[6]])) {
                 $foreign_keys[$rs->fields[5] . '.' . $rs->fields[6]] = array();
             }
             $foreign_keys[$rs->fields[5] . '.' . $rs->fields[6]][$rs->fields[7]] = $rs->fields[3];
         }
         $rs->MoveNext();
     }
     $rs->Close();
     return $foreign_key;
 }
예제 #2
0
 function MetaColumns($table)
 {
     global $ADODB_FETCH_MODE;
     $false = false;
     if ($this->uCaseTables) {
         $table = strtoupper($table);
     }
     $schema = '';
     $this->_findschema($table, $schema);
     $savem = $ADODB_FETCH_MODE;
     $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     $colname = "%";
     $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname);
     if (empty($qid)) {
         return $false;
     }
     $rs = new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $false;
     }
     $rs->_fetch();
     $retarr = array();
     /*
     $rs->fields indices
     0 TABLE_QUALIFIER
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 DATA_TYPE
     5 TYPE_NAME
     6 PRECISION
     7 LENGTH
     8 SCALE
     9 RADIX
     10 NULLABLE
     11 REMARKS
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $fld = new ADOFieldObject();
             $fld->name = $rs->fields[3];
             $fld->type = $this->DB2Types($rs->fields[4]);
             // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
             // access uses precision to store length for char/varchar
             if ($fld->type == 'C' or $fld->type == 'X') {
                 if ($rs->fields[4] <= -95) {
                     // UNICODE
                     $fld->max_length = $rs->fields[7] / 2;
                 } else {
                     $fld->max_length = $rs->fields[7];
                 }
             } else {
                 $fld->max_length = $rs->fields[7];
             }
             $fld->not_null = !empty($rs->fields[10]);
             $fld->scale = $rs->fields[8];
             $fld->primary_key = false;
             $retarr[strtoupper($fld->name)] = $fld;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
     if (empty($retarr)) {
         $retarr = false;
     }
     $qid = db2_primary_keys($this->_connectionID, "", $schema, $table);
     if (empty($qid)) {
         return $false;
     }
     $rs = new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $retarr;
     }
     $rs->_fetch();
     /*
     $rs->fields indices
     0 TABLE_CAT
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 KEY_SEQ
     5 PK_NAME
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $retarr[strtoupper($rs->fields[3])]->primary_key = true;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
     if (empty($retarr)) {
         $retarr = false;
     }
     return $retarr;
 }