Changeset 5030

Show
Ignore:
Timestamp:
10/02/08 05:46:18 (3 months ago)
Author:
jwage
Message:

[1.1] fixes #753 Allowed ability to set global values for columns and identifier columns

Location:
branches/1.1
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine.php

    r5027 r5030  
    177177    const ATTR_DEFAULT_SEQUENCE     = 133; 
    178178 
    179     const ATTR_FETCHMODE                = 118; 
    180     const ATTR_NAME_PREFIX              = 121; 
    181     const ATTR_CREATE_TABLES            = 122; 
    182     const ATTR_COLL_LIMIT               = 123; 
    183  
    184     const ATTR_CACHE                    = 150; 
    185     const ATTR_RESULT_CACHE             = 150; 
    186     const ATTR_CACHE_LIFESPAN           = 151; 
    187     const ATTR_RESULT_CACHE_LIFESPAN    = 151; 
    188     const ATTR_LOAD_REFERENCES          = 153; 
    189     const ATTR_RECORD_LISTENER          = 154; 
    190     const ATTR_THROW_EXCEPTIONS         = 155; 
    191     const ATTR_DEFAULT_PARAM_NAMESPACE  = 156; 
    192     const ATTR_QUERY_CACHE              = 157; 
    193     const ATTR_QUERY_CACHE_LIFESPAN     = 158; 
    194     const ATTR_AUTOLOAD_TABLE_CLASSES   = 160; 
    195     const ATTR_MODEL_LOADING            = 161; 
    196     const ATTR_RECURSIVE_MERGE_FIXTURES = 162; 
    197     const ATTR_USE_DQL_CALLBACKS        = 164; 
    198     const ATTR_AUTO_ACCESSOR_OVERRIDE   = 165; 
    199     const ATTR_AUTO_FREE_QUERY_OBJECTS  = 166; 
    200     const ATTR_DEFAULT_TABLE_CHARSET    = 167; 
    201     const ATTR_DEFAULT_TABLE_COLLATE    = 168; 
     179    const ATTR_FETCHMODE                    = 118; 
     180    const ATTR_NAME_PREFIX                  = 121; 
     181    const ATTR_CREATE_TABLES                = 122; 
     182    const ATTR_COLL_LIMIT                   = 123; 
     183                                         
     184    const ATTR_CACHE                        = 150; 
     185    const ATTR_RESULT_CACHE                 = 150; 
     186    const ATTR_CACHE_LIFESPAN               = 151; 
     187    const ATTR_RESULT_CACHE_LIFESPAN        = 151; 
     188    const ATTR_LOAD_REFERENCES              = 153; 
     189    const ATTR_RECORD_LISTENER              = 154; 
     190    const ATTR_THROW_EXCEPTIONS             = 155; 
     191    const ATTR_DEFAULT_PARAM_NAMESPACE      = 156; 
     192    const ATTR_QUERY_CACHE                  = 157; 
     193    const ATTR_QUERY_CACHE_LIFESPAN         = 158; 
     194    const ATTR_AUTOLOAD_TABLE_CLASSES       = 160; 
     195    const ATTR_MODEL_LOADING                = 161; 
     196    const ATTR_RECURSIVE_MERGE_FIXTURES     = 162; 
     197    const ATTR_USE_DQL_CALLBACKS            = 164; 
     198    const ATTR_AUTO_ACCESSOR_OVERRIDE       = 165; 
     199    const ATTR_AUTO_FREE_QUERY_OBJECTS      = 166; 
     200    const ATTR_DEFAULT_TABLE_CHARSET        = 167; 
     201    const ATTR_DEFAULT_TABLE_COLLATE        = 168; 
     202    const ATTR_DEFAULT_IDENTIFIER_OPTIONS   = 169; 
     203    const ATTR_DEFAULT_COLUMN_OPTIONS       = 170; 
    202204 
    203205    /** 
  • branches/1.1/lib/Doctrine/Configurable.php

    r5027 r5030  
    186186            case Doctrine::ATTR_DEFAULT_TABLE_CHARSET; 
    187187            case Doctrine::ATTR_DEFAULT_TABLE_COLLATE; 
     188            case Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS; 
     189            case Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS; 
    188190 
    189191                break; 
  • branches/1.1/lib/Doctrine/Manager.php

    r5018 r5030  
    8383            $init = true; 
    8484            $attributes = array( 
    85                         Doctrine::ATTR_CACHE                    => null, 
    86                         Doctrine::ATTR_RESULT_CACHE             => null, 
    87                         Doctrine::ATTR_QUERY_CACHE              => null, 
    88                         Doctrine::ATTR_LOAD_REFERENCES          => true, 
    89                         Doctrine::ATTR_LISTENER                 => new Doctrine_EventListener(), 
    90                         Doctrine::ATTR_RECORD_LISTENER          => new Doctrine_Record_Listener(), 
    91                         Doctrine::ATTR_THROW_EXCEPTIONS         => true, 
    92                         Doctrine::ATTR_VALIDATE                 => Doctrine::VALIDATE_NONE, 
    93                         Doctrine::ATTR_QUERY_LIMIT              => Doctrine::LIMIT_RECORDS, 
    94                         Doctrine::ATTR_IDXNAME_FORMAT           => "%s_idx", 
    95                         Doctrine::ATTR_SEQNAME_FORMAT           => "%s_seq", 
    96                         Doctrine::ATTR_TBLNAME_FORMAT           => "%s", 
    97                         Doctrine::ATTR_QUOTE_IDENTIFIER         => false, 
    98                         Doctrine::ATTR_SEQCOL_NAME              => 'id', 
    99                         Doctrine::ATTR_PORTABILITY              => Doctrine::PORTABILITY_NONE, 
    100                         Doctrine::ATTR_EXPORT                   => Doctrine::EXPORT_ALL, 
    101                         Doctrine::ATTR_DECIMAL_PLACES           => 2, 
    102                         Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE  => 'doctrine', 
    103                         Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES   => false, 
    104                         Doctrine::ATTR_USE_DQL_CALLBACKS        => false, 
    105                         Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE   => false, 
    106                         Doctrine::ATTR_AUTO_FREE_QUERY_OBJECTS  => false, 
     85                        Doctrine::ATTR_CACHE                        => null, 
     86                        Doctrine::ATTR_RESULT_CACHE                 => null, 
     87                        Doctrine::ATTR_QUERY_CACHE                  => null, 
     88                        Doctrine::ATTR_LOAD_REFERENCES              => true, 
     89                        Doctrine::ATTR_LISTENER                     => new Doctrine_EventListener(), 
     90                        Doctrine::ATTR_RECORD_LISTENER              => new Doctrine_Record_Listener(), 
     91                        Doctrine::ATTR_THROW_EXCEPTIONS             => true, 
     92                        Doctrine::ATTR_VALIDATE                     => Doctrine::VALIDATE_NONE, 
     93                        Doctrine::ATTR_QUERY_LIMIT                  => Doctrine::LIMIT_RECORDS, 
     94                        Doctrine::ATTR_IDXNAME_FORMAT               => "%s_idx", 
     95                        Doctrine::ATTR_SEQNAME_FORMAT               => "%s_seq", 
     96                        Doctrine::ATTR_TBLNAME_FORMAT               => "%s", 
     97                        Doctrine::ATTR_QUOTE_IDENTIFIER             => false, 
     98                        Doctrine::ATTR_SEQCOL_NAME                  => 'id', 
     99                        Doctrine::ATTR_PORTABILITY                  => Doctrine::PORTABILITY_NONE, 
     100                        Doctrine::ATTR_EXPORT                       => Doctrine::EXPORT_ALL, 
     101                        Doctrine::ATTR_DECIMAL_PLACES               => 2, 
     102                        Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE      => 'doctrine', 
     103                        Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES       => false, 
     104                        Doctrine::ATTR_USE_DQL_CALLBACKS            => false, 
     105                        Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE       => false, 
     106                        Doctrine::ATTR_AUTO_FREE_QUERY_OBJECTS      => false, 
     107                        Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS   => array(), 
     108                        Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS       => array() 
    107109                        );  
    108110            foreach ($attributes as $attribute => $value) { 
  • branches/1.1/lib/Doctrine/Record/Abstract.php

    r4957 r5030  
    225225     * @return void 
    226226     */ 
    227     public function hasColumn($name, $type, $length = 2147483647, $options = "") 
     227    public function hasColumn($name, $type = null, $length = null, $options = array()) 
    228228    { 
    229229        $this->_table->setColumn($name, $type, $length, $options); 
  • branches/1.1/lib/Doctrine/Table.php

    r5027 r5030  
    411411                    } 
    412412                } else { 
    413                     $definition = array('type' => 'integer', 
    414                                         'length' => 20, 
    415                                         'autoincrement' => true, 
    416                                         'primary' => true); 
    417                     $this->setColumn('id', $definition['type'], $definition['length'], $definition, true); 
    418                     $this->_identifier = 'id'; 
     413                    $identifierOptions = $this->getAttribute(Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS); 
     414                    $name = (isset($identifierOptions['name']) && $identifierOptions['name']) ? $identifierOptions['name']:'id'; 
     415                    $name = sprintf($name, $this->getTableName()); 
     416 
     417                    $definition = array('type' => (isset($identifierOptions['type']) && $identifierOptions['type']) ? $identifierOptions['type']:'integer', 
     418                                        'length' => (isset($identifierOptions['length']) && $identifierOptions['length']) ? $identifierOptions['length']:20, 
     419                                        'autoincrement' => isset($identifierOptions['autoincrement']) ? $identifierOptions['autoincrement']:true, 
     420                                        'primary' => isset($identifierOptions['primary']) ? $identifierOptions['primary']:true); 
     421 
     422                    unset($identifierOptions['name'], $identifierOptions['type'], $identifierOptions['length']); 
     423                    foreach ($identifierOptions as $key => $value) { 
     424                        if ( ! isset($definition[$key]) || ! $definition[$key]) { 
     425                            $definition[$key] = $value; 
     426                        } 
     427                    } 
     428 
     429                    $this->setColumn($name, $definition['type'], $definition['length'], $definition, true); 
     430                    $this->_identifier = $name; 
    419431                    $this->_identifierType = Doctrine::IDENTIFIER_AUTOINC; 
    420432                } 
     
    983995     * @return void 
    984996     */ 
    985     public function setColumn($name, $type, $length = null, $options = array(), $prepend = false) 
     997    public function setColumn($name, $type = null, $length = null, $options = array(), $prepend = false) 
    986998    { 
    987999        if (is_string($options)) { 
     
    10281040            $this->_columnNames[$fieldName] = $name; 
    10291041            $this->_fieldNames[$name] = $fieldName; 
     1042        } 
     1043 
     1044        $defaultOptions = $this->getAttribute(Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS); 
     1045 
     1046        if (isset($defaultOptions['length']) && $defaultOptions['length'] && $length == null) { 
     1047            $length = $defaultOptions['length']; 
    10301048        } 
    10311049 
     
    10541072                    // YYYY-MM-DDTHH:MM:SS+00:00 ISO 8601 
    10551073                    $length = 25; 
    1056                 break; 
    10571074            } 
    10581075        } 
     
    10601077        $options['type'] = $type; 
    10611078        $options['length'] = $length; 
     1079 
     1080        foreach ($defaultOptions as $key => $value) { 
     1081            if ( ! isset($options[$key]) || ! $options[$key]) { 
     1082                $options[$key] = $value; 
     1083            } 
     1084        } 
    10621085 
    10631086        if ($prepend) { 
  • branches/1.1/tests/run.php

    r5029 r5030  
    5454$tickets->addTestCase(new Doctrine_Ticket_741_TestCase()); 
    5555$tickets->addTestCase(new Doctrine_Ticket_749_TestCase()); 
     56$tickets->addTestCase(new Doctrine_Ticket_753_TestCase()); 
    5657$tickets->addTestCase(new Doctrine_Ticket_786_TestCase()); 
    5758$tickets->addTestCase(new Doctrine_Ticket_832_TestCase()); 
     
    148149$tickets->addTestCase(new Doctrine_Ticket_1465_TestCase()); 
    149150$tickets->addTestCase(new Doctrine_Ticket_1480_TestCase()); 
    150 $tickets->addTestCase(new Doctrine_Ticket_1483_TestCase()); 
    151151$tickets->addTestCase(new Doctrine_Ticket_1507_TestCase()); 
    152152$test->addTestCase($tickets); 
  • branches/1.1/UPGRADE_TO_1_1

    r5027 r5030  
    4343    $user->synchronizeWithArray($userArray); 
    4444    $user->save(); 
     45 
     46[r5027](http://trac.doctrine-project.org/changeset/5039) - Added support for setting default charset and collate for tables. 
     47 
     48Set globally on a Doctrine_Manager instance. 
     49 
     50    $manager->setCollate('utf8_unicode_ci'); 
     51    $manager->setCharset('utf8'); 
     52 
     53The same can be set on the Doctrine_Connection and Doctrine_Record levels. 
     54 
     55    $connection->setCollate('utf8_unicode_ci'); 
     56    $connection->setCharset('utf8'); 
     57 
     58    public function setTableDefinition() 
     59    { 
     60      $this->setCollate('utf8_unicode_ci'); 
     61      $this->setCharset('utf8'); 
     62    } 
     63 
     64[r5030](http://trac.doctrine-project.org/changeset/5039) - Added support for setting default options for columns and auto added identifier columns. 
     65 
     66The following is now possible on Doctrine_Manager, Doctrine_Connection and Doctrine_Record. 
     67 
     68    $manager->setAttribute(Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS, array('type' => 'string', 'length' => 255, 'notnull' => true)); 
     69 
     70You can also customize the values that make up the auto added identifier column as well. 
     71 
     72    $manager->setAttribute(Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS, array('name' => '%s_id', 'type' => 'string', 'length' => 16)); // %s in the name is replaced with the table name.