Пример #1
0
 /**
  * Returns an array of the fields in given table name.
  *
  * @param string $tableName Name of database table to inspect
  * @return array Fields in table. Keys are name and type
  */
 function &describe(&$model)
 {
     $fields = parent::describe($model);
     $table = $this->fullTableName($model, false);
     $this->_sequenceMap[$table] = array();
     if ($fields === null) {
         $cols = $this->fetchAll("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,\n\t\t\t\t\tcolumn_default AS default, ordinal_position AS position, character_maximum_length AS char_length,\n\t\t\t\t\tcharacter_octet_length AS oct_length FROM information_schema.columns\n\t\t\t\tWHERE table_name = " . $this->value($table) . " AND table_schema = " . $this->value($this->config['schema']) . "  ORDER BY position", false);
         foreach ($cols as $column) {
             $colKey = array_keys($column);
             if (isset($column[$colKey[0]]) && !isset($column[0])) {
                 $column[0] = $column[$colKey[0]];
             }
             if (isset($column[0])) {
                 $c = $column[0];
                 if (!empty($c['char_length'])) {
                     $length = intval($c['char_length']);
                 } elseif (!empty($c['oct_length'])) {
                     if ($c['type'] == 'character varying') {
                         $length = null;
                         $c['type'] = 'text';
                         // >>> CUSTOMIZE ADD 2011/08/22 ryuring
                     } elseif ($c['type'] == 'text') {
                         $length = null;
                         // <<<
                     } else {
                         $length = intval($c['oct_length']);
                     }
                 } else {
                     $length = $this->length($c['type']);
                 }
                 $fields[$c['name']] = array('type' => $this->column($c['type']), 'null' => $c['null'] == 'NO' ? false : true, 'default' => preg_replace("/^'(.*)'\$/", "\$1", preg_replace('/::.*/', '', $c['default'])), 'length' => $length);
                 // >>> CUSTOMIZE ADD 2011/08/22 ryuring
                 if (!$fields[$c['name']]['length'] && $fields[$c['name']]['type'] == 'integer') {
                     $fields[$c['name']]['length'] = 8;
                 }
                 // <<<
                 if ($c['name'] == $model->primaryKey) {
                     $fields[$c['name']]['key'] = 'primary';
                     if ($fields[$c['name']]['type'] !== 'string') {
                         // >>> CUSTOMIZE MODIFY 2011/08/22 ryuring
                         //$fields[$c['name']]['length'] = 11;
                         // ---
                         $fields[$c['name']]['length'] = 8;
                         // <<<
                     }
                 }
                 if ($fields[$c['name']]['default'] == 'NULL' || preg_match('/nextval\\([\'"]?([\\w.]+)/', $c['default'], $seq)) {
                     $fields[$c['name']]['default'] = null;
                     if (!empty($seq) && isset($seq[1])) {
                         $this->_sequenceMap[$table][$c['name']] = $seq[1];
                     }
                 }
                 // >>> CUSTOMIZE ADD 2011/08/22 ryuring
                 if ($fields[$c['name']]['default'] === 'true' && $fields[$c['name']]['type'] == 'boolean') {
                     $fields[$c['name']]['default'] = 1;
                 } elseif ($fields[$c['name']]['default'] === 'false' && $fields[$c['name']]['type'] == 'boolean') {
                     $fields[$c['name']]['default'] = 0;
                 }
                 // <<<
             }
         }
         $this->__cacheDescription($table, $fields);
     }
     if (isset($model->sequence)) {
         $this->_sequenceMap[$table][$model->primaryKey] = $model->sequence;
     }
     return $fields;
 }
Пример #2
0
 function logQuery($sql)
 {
     $return = parent::logQuery($sql);
     $this->log("<" . $this->took . ">" . $sql, LOG_DEBUG);
     return $return;
 }