#5696: PostgreSQL incorrect timestamp definition in CREATE TABLE when using
CakeTestFixture::$import
------------------------------------------------+---------------------------
    Reporter:  klevo                            |         Owner:  AD7six  
        Type:  Bug                              |        Status:  reopened
    Priority:  High                             |     Milestone:  1.2.x.x 
   Component:  PostgreSQL                       |       Version:  RC3     
    Severity:  Normal                           |    Resolution:          
    Keywords:  postgres timestamp create table  |   Php_version:  PHP 5   
Cake_version:  1.2.0.7692 RC3                   |  
------------------------------------------------+---------------------------
Changes (by siwa):

  * status:  closed => reopened
  * resolution:  fixed =>

Comment:

 == Problem ==

 The createSchema method create incorrect CREATE TABLE SQL at
 CakeTestFixture::create method.

 There is same problem at a column of type date.

 I confirmed at CakePHP 1.2.x.x_01.03.2009 and PostgreSQL 8.3.5

 == Test Case ==

 Append after testCakeSchema method in
 cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php
 {{{
         function testCakeSchema2() {
                 $db1 =& ConnectionManager::getDataSource('test_suite');
                 $db1->cacheSources = false;
                 $db1->reconnect(array('persistent' => false));

                 $db1->query('CREATE TABLE ' .
 $db1->fullTableName('datatypes') . ' (
                         id serial NOT NULL,
                         "varchar" character varying(40) NOT NULL,
                         "timestamp" timestamp without time zone,
                         date date,
                         CONSTRAINT test_suite_data_types_pkey PRIMARY KEY
 (id)
                 )');
                 $model =& ClassRegistry::init('datatypes');
                 $schema = new CakeSchema(array('connection' =>
 'test_suite'));
                 $fields = $model->schema(true);
                 $schema->_build(array($db1->fullTableName('datatypes') =>
 $fields));
                 $result = $db1->createSchema($schema);
                 $this->assertNoPattern('/timestamp DEFAULT/', $result);
                 $this->assertPattern('/timestamp\s*,/', $result);
                 $this->assertNoPattern('/date DEFAULT/', $result);
                 $this->assertPattern('/date\s*,/', $result);

                 $db1->query('DROP TABLE ' .
 $db1->fullTableName('datatypes'));
                 $db1->query($result);
                 $fields = $model->schema(true);
                 $schema->_build(array($db1->fullTableName('datatypes') =>
 $fields));
                 $result2 = $db1->createSchema($schema);
                 debug($result2);
                 $this->assertEqual($result, $result2);

                 $db1->query('DROP TABLE ' .
 $db1->fullTableName('datatypes'));
         }
 }}}

 == Possible fix ==
 In dbo_postgres.php, line 781-788

 From
 {{{
                 if (strpos($out, 'timestamp DEFAULT')) {
                         if (isset($column['null']) && $column['null']) {
                                 $out = str_replace('DEFAULT NULL', '',
 $out);
                         } else {
                                 $out = str_replace('DEFAULT NOT NULL', '',
 $out);
                         }
                 }
 }}}

 to
 {{{
                 if (strpos($out, 'timestamp DEFAULT') || strpos($out,
 'date DEFAULT')) {
                         if (isset($column['null']) && $column['null']) {
                                 $out = str_replace('DEFAULT NULL', '',
 $out);
                                 $out = str_replace('DEFAULT \'\'', '',
 $out);
                         } else {
                                 $out = str_replace('DEFAULT NOT NULL', '',
 $out);
                         }
                 }
 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5696#comment:3>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to