Changeset 9947

Show
Ignore:
Timestamp:
11/17/08 03:39:00 (2 months ago)
Author:
afz
Message:

Update MDB2_Schema to 0.8.3(changed some part by myself)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.8/jaws/html/libraries/pear/MDB2/Schema.php

    r8054 r9947  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    46 // $Id: Schema.php,v 1.123 2008/03/24 19:12:32 ifeghali Exp $ 
     46// $Id: Schema.php,v 1.127 2008/11/17 00:11:13 ifeghali Exp $ 
    4747// 
    4848 
     
    421421            'create' => true, 
    422422            'overwrite' => false, 
    423             'charset' => '', 
     423            'charset' => 'utf8', 
    424424            'description' => '', 
    425425            'comments' => '', 
     
    12821282 
    12831283            $dbOptions = array(); 
    1284             if (isset($database_definition['charset'])) { 
     1284            if (array_key_exists('charset', $database_definition) 
     1285                && !empty($database_definition['charset'])) { 
    12851286                $dbOptions['charset'] = $database_definition['charset']; 
    12861287            } 
     
    14031404                foreach ($previous_definition['tables'] as $table_name => $table) { 
    14041405                    if (empty($defined_tables[$table_name])) { 
    1405                         $changes['remove'][$table_name] = true; 
     1406                        $changes['tables']['remove'][$table_name] = true; 
    14061407                    } 
    14071408                } 
     
    14311432                foreach ($previous_definition['sequences'] as $sequence_name => $sequence) { 
    14321433                    if (empty($defined_sequences[$sequence_name])) { 
    1433                         $changes['remove'][$sequence_name] = true; 
     1434                        $changes['sequences']['remove'][$sequence_name] = true; 
    14341435                    } 
    14351436                } 
     
    14831484                    } 
    14841485                    if (!empty($change)) { 
     1486                        if (array_key_exists('default', $change) 
     1487                            && $change['default'] 
     1488                            && !array_key_exists('default', $field)) { 
     1489                                $field['default'] = NULL; 
     1490                        } 
    14851491                        $change['definition'] = $field; 
    14861492                        $changes['change'][$field_name] = $change; 
     
    18641870            foreach ($changes['change'] as $index_name => $index) { 
    18651871                if (!empty($index['primary']) || !empty($index['unique'])) { 
     1872                    $this->db->expectError(MDB2_ERROR_NOT_FOUND); 
     1873                    $result = $this->db->manager->dropIndex($table_name, $index_name); 
     1874                    $this->db->popExpect(); 
     1875                    if (PEAR::isError($result) && !MDB2::isError($result, MDB2_ERROR_NOT_FOUND)) { 
     1876                        return $result; 
     1877                    } 
    18661878                    $this->db->expectError(MDB2_ERROR_NOT_FOUND); 
    18671879                    $result = $this->db->manager->dropConstraint($table_name, $index_name, !empty($index['primary'])); 
  • branches/0.8/jaws/html/libraries/pear/MDB2/Schema/Validate.php

    r7547 r9947  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    46 // $Id: Validate.php,v 1.38 2008/02/06 23:13:51 ifeghali Exp $ 
     46// $Id: Validate.php,v 1.40 2008/11/15 23:53:47 ifeghali Exp $ 
    4747// 
    4848 
     
    204204        foreach ($table['fields'] as $field_name => $field) { 
    205205            if (!empty($field['autoincrement'])) { 
    206                 if ($primary) { 
     206                if ($autoinc) { 
    207207                    return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, 
    208208                        'there was already an autoincrement field in "'.$table_name.'" before "'.$field_name.'"'); 
    209209                } 
    210                 $autoinc = $primary = true; 
     210                $autoinc = $field_name; 
    211211            } 
    212212        } 
     
    227227                     * a primary key index. 
    228228                     */ 
    229                     if ($autoinc && count($index['fields']) == '1') { 
     229                    if (count($index['fields']) == '1' 
     230                        && array_key_exists($autoinc, $index['fields'])) { 
    230231                        $skip_index = true; 
    231                     } elseif ($primary) { 
     232                    } elseif ($autoinc || $primary) { 
    232233                        return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE, 
    233234                            'there was already an primary index or autoincrement field in "'.$table_name.'" before "'.$name.'"'); 
     
    873874        case 'timestamp': 
    874875            if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $field_value) 
     876                && strcasecmp($field_value, 'now()') != 0 
    875877                && $field_value !== 'CURRENT_TIMESTAMP' 
    876878            ) {