Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0b4

Bug #12311 can't createTable() with infos from tableInfo(), if I have TIMESTAMP columns
Submitted: 2007-10-23 14:39 UTC
From: cwiedmann Assigned:
Status: Open Package: MDB2_Driver_mysqli (version 1.4.1)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 37 + 43 = ?

 
 [2007-10-23 14:39 UTC] cwiedmann (Carsten Wiedmann)
Description: ------------ Hello, in addition to Bug #10488, I think there is another problem: If you have a TIMESTAMP column in MySQL you can't recreate this column with the manager module as it was, with the information from the reverse module. Because a DEFAULT CURRENT_TIMESTAMP is illegal for a DATETIME column in MySQL, which the manager create instead of a TIMESTAMP. And yes: it's really a difference between a DATETIME and a TIMESTAMP. And if there was a TIMESTAMP, I want to have a TIMESTAMP ;-) In the constructor I told MDB2 that I want use MySQL, and so I should be able to use all basic features from this DB (without using e.g. custom types). Another thing I'm missing: If I create the original column with an additional "ON UPDATE CURRENT_TIMESTAMP", I don't get this info from the reverse module tableInfo(). (For this I can make a patch.) BTW: On this manual page [1] you can read, that MDB is creating a TIMESTAMP in MySQL, and not a DATETIME. Regards, Carsten [1] http://pear.php.net/manual/en/package.database.mdb2.datatypes.php#AEN38081 Test script: --------------- <?php header('Content-Type: text/plain'); require_once 'MDB2.php'; function printError($error) { die($error->getDebugInfo()); } PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'printError'); $dsn = 'mysqli://root@localhost/test'; $dbTable = 'mdb2test'; $mdb2 = MDB2::connect($dsn); $mdb2->loadModule('Manager'); $mdb2->loadModule('Reverse', null, true); echo 'Created table with e.g. phpMyAdmin:'.PHP_EOL; $sql = <<<SQL DROP TABLE IF EXISTS $dbTable SQL; $mdb2->exec($sql); /* Use this for a negative test */ $sql = <<<SQL CREATE TABLE $dbTable ( updatetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); SQL; /* Use this for a positive test */ //$sql = <<<SQL //CREATE TABLE $dbTable ( // updatetime DATETIME // DEFAULT NULL //); //SQL; echo $sql.PHP_EOL.PHP_EOL; $mdb2->exec($sql); echo 'Get tableInfo() from the original table:'.PHP_EOL; $oldDefinition = $mdb2->tableInfo($dbTable); var_dump($oldDefinition); echo PHP_EOL; echo 'dropTable()'.PHP_EOL.PHP_EOL; $mdb2->dropTable($dbTable); echo 'Show MDB2 FieldDeclaration:'.PHP_EOL; $definition = array (); foreach ($oldDefinition as $value) { $definition[$value['name']] = array( 'type' => $value['mdb2type'], 'notnull' => $value['notnull'], 'default' => $value['default'], ); } echo "CREATE TABLE $dbTable (".PHP_EOL; echo " ".$mdb2->getFieldDeclarationList($definition).PHP_EOL; echo ")".PHP_EOL.PHP_EOL; echo 'createTable()'.PHP_EOL.PHP_EOL; $mdb2->createTable($dbTable, $definition); echo 'Get tableInfo() from the new table:'.PHP_EOL; $newDefinition = $mdb2->tableInfo($dbTable); var_dump($newDefinition); echo PHP_EOL; echo 'Are old and new tableInfo() the same?'.PHP_EOL; var_dump($oldDefinition == $newDefinition); echo PHP_EOL; ?> Expected result: ---------------- No error message and the arrays $old_definition and $new_definition should be equal. Actual result: -------------- Created table with e.g. phpMyAdmin: CREATE TABLE mdb2test ( updatetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); Get tableInfo() from the original table: array(1) { [0]=> array(8) { ["notnull"]=> bool(true) ["nativetype"]=> string(9) "timestamp" ["default"]=> string(17) "CURRENT_TIMESTAMP" ["type"]=> string(9) "timestamp" ["mdb2type"]=> string(9) "timestamp" ["name"]=> string(10) "updatetime" ["table"]=> string(8) "mdb2test" ["flags"]=> string(35) " not_null default_CURRENT_TIMESTAMP" } } dropTable() Show MDB2 FieldDeclaration: CREATE TABLE mdb2test ( updatetime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ) createTable() _doQuery: [Error message: Could not execute statement] [Last executed query: CREATE TABLE mdb2test (updatetime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL)] [Native code: 1067] [Native message: Fehlerhafter Vorgabewert (DEFAULT) für 'updatetime']

Comments