コード例 #1
0
ファイル: writer.php プロジェクト: mdb-webdev/livehelperchat
 /**
  * Adds a "alter table" query to remote the index $indexName from the table $tableName to the internal list of queries.
  *
  * @param string           $tableName
  * @param string           $indexName
  */
 protected function generateDropIndexSql($tableName, $indexName)
 {
     if ($indexName == 'primary') {
         $constraintName = ezcDbSchemaOracleHelper::generateSuffixedIdentName(array($tableName), "pkey");
         $this->queries[] = "ALTER TABLE \"{$tableName}\" DROP CONSTRAINT \"{$constraintName}\"";
     } else {
         $this->queries[] = "DROP INDEX \"{$indexName}\"";
     }
 }
コード例 #2
0
ファイル: reader.php プロジェクト: Adeelgill/livehelperchat
 /**
  * Fetch fields definition for the table $tableName
  *
  * This method loops over all the fields in the table $tableName and
  * returns an array with the field specification. The key in the returned
  * array is the name of the field.
  *
  * @param string $tableName
  * @return array(string=>ezcDbSchemaField)
  */
 protected function fetchTableFields($tableName)
 {
     $fields = array();
     // will detect autoincrement field by presence of sequence tableName_fieldPos_seq
     $sequencesQuery = $this->db->query("SELECT * FROM user_sequences");
     $sequencesQuery->setFetchMode(PDO::FETCH_ASSOC);
     $sequences = array();
     foreach ($sequencesQuery as $seq) {
         $sequences[] = $seq['sequence_name'];
     }
     // fetching fields info from Oracle
     $resultArray = $this->db->query("SELECT   a.column_name AS field, " . "         a.column_id AS field_pos, " . "         DECODE (a.nullable, 'N', 1, 'Y', 0) AS notnull, " . "         a.data_type AS type, " . "         a.data_length AS length, " . "         a.data_precision AS precision, " . "         a.data_scale AS scale, " . "         a.data_default AS default_val " . "FROM     user_tab_columns a " . "WHERE    a.table_name = '{$tableName}' " . "ORDER BY a.column_id");
     $resultArray->setFetchMode(PDO::FETCH_ASSOC);
     foreach ($resultArray as $row) {
         $fieldLength = $row['length'];
         $fieldPrecision = null;
         $fieldType = self::convertToGenericType($row['type'], $fieldLength, $fieldPrecision);
         if (in_array($fieldType, array('clob', 'blob', 'date', 'float', 'timestamp'))) {
             $fieldLength = false;
         } else {
             if ($fieldType == 'integer') {
                 if ($row['precision'] != '') {
                     $fieldType = 'decimal';
                     $fieldLength = $row['precision'];
                 } else {
                     if ($fieldLength == 22) {
                         $fieldLength = false;
                     }
                 }
             }
         }
         $fieldNotNull = $row['notnull'];
         $fieldDefault = null;
         if ($row['default_val'] != '') {
             $row['default_val'] = rtrim($row['default_val']);
             if ($fieldType == 'boolean') {
                 $row['default_val'] == '1' ? $fieldDefault = 'true' : ($fieldDefault = 'false');
             } else {
                 if ($fieldType == 'text') {
                     $fieldDefault = substr($row['default_val'], 1, -1);
                     // avoid quotes for text
                 } else {
                     $fieldDefault = $row['default_val'];
                     // have a number value
                 }
             }
         }
         $fieldAutoIncrement = false;
         // new sequence naming included
         if (in_array(ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName($tableName, $row['field_pos'], 'seq'), $sequences) || in_array(ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName($tableName, $row['field'], 'seq'), $sequences)) {
             $fieldAutoIncrement = true;
         }
         // FIXME: unsigned needs to be implemented
         $fieldUnsigned = false;
         $fields[$row['field']] = ezcDbSchema::createNewField($fieldType, $fieldLength, $fieldNotNull, $fieldDefault, $fieldAutoIncrement, $fieldUnsigned);
     }
     return $fields;
 }