示例#1
0
文件: Oracle.php 项目: rtsantos/mais
 /**
  * Returns the column descriptions for a table.
  *
  * The return value is an associative array keyed by the column name,
  * as returned by the RDBMS.
  *
  * The value of each array element is an associative array
  * with the following keys:
  *
  * SCHEMA_NAME      => string; name of schema
  * TABLE_NAME       => string;
  * COLUMN_NAME      => string; column name
  * COLUMN_POSITION  => number; ordinal position of column in table
  * DATA_TYPE        => string; SQL datatype name of column
  * DEFAULT          => string; default expression of column, null if none
  * NULLABLE         => boolean; true if column can have nulls
  * LENGTH           => number; length of CHAR/VARCHAR
  * SCALE            => number; scale of NUMERIC/DECIMAL
  * PRECISION        => number; precision of NUMERIC/DECIMAL
  * UNSIGNED         => boolean; unsigned property of an integer type
  * PRIMARY          => boolean; true if column is part of the primary key
  * PRIMARY_POSITION => integer; position of column in primary key
  * IDENTITY         => integer; true if column is auto-generated with unique values
  *
  * @todo Discover integer unsigned property.
  *
  * @param string $tableName
  * @param string $schemaName OPTIONAL
  * @return array
  */
 public function describeTable($tableName, $schemaName = null)
 {
     $desc = parent::describeTable($tableName, $schemaName);
     $tableName = strtoupper($tableName);
     $schemaName = strtoupper($schemaName);
     $sql = "SELECT distinct uccfk.TABLE_NAME\n                  FROM all_cons_columns uccfk\n                     , all_constraints  uc\n                     , all_cons_columns uccpk\n                 WHERE uccfk.constraint_name = uc.constraint_name\n                   AND uccfk.owner = uc.owner\n                   AND uc.r_constraint_name = uccpk.constraint_name\n                   AND uc.r_owner = uccpk.owner\n                   AND uc.constraint_type = 'R'\n                   AND uccpk.table_name = :table_name ";
     $bind = array('table_name' => $tableName);
     if ($schemaName != null) {
         $bind += array('schema_name' => strtoupper($schemaName));
         $sql .= " AND uccpk.owner = :schema_name ";
     }
     $dependentTables = $this->fetchAll($sql, $bind);
     $sql = "SELECT uccfk.column_name\n                      ,uccpk.table_name table_name_reference\n                      ,uccpk.owner schema_name_reference\n                      ,uccpk.column_name column_name_reference\n                  FROM all_cons_columns uccfk\n                      ,all_constraints  uc\n                      ,all_cons_columns uccpk\n                 WHERE uccfk.constraint_name = uc.constraint_name\n                   AND uccfk.owner = uc.owner\n                   AND uc.r_constraint_name = uccpk.constraint_name\n                   AND uc.r_owner = uccpk.owner\n                   AND uc.constraint_type = 'R'\n                   AND uccfk.table_name = :table_name ";
     $bind = array('table_name' => $tableName);
     if ($schemaName != null) {
         $bind += array('schema_name' => strtoupper($schemaName));
         $sql .= " AND uccfk.owner = :schema_name ";
     }
     $referenceMap = $this->fetchAll($sql, $bind);
     $desc[$this->foldCase('reference_map')] = $referenceMap;
     $desc[$this->foldCase('dependent_tables')] = $dependentTables;
     return $desc;
 }