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

Bug #7287 create is triggered while in 'alter' mode
Submitted: 2006-04-04 09:08 UTC
From: vdb at mail dot ru Assigned: wiesemann
Status: Closed Package: DB_Table (version CVS)
PHP Version: 4.4.0 OS: linux
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 : 12 + 45 = ?

 
 [2006-04-04 09:08 UTC] vdb at mail dot ru (vdb)
Description: ------------ Somehow create() is triggered while in 'alter' mode causing data inserts, defined inside create() each time class instance is created. This is unexpected behaviour. I think only 'drop' mode should call create(). Test script: --------------- class my_table extends DB_Table { function create($flag) { // call the parent create() first $result = parent::create($flag); // was the table created? if (PEAR::isError($result) || ! $result) { // table not created return $result; } else { // table created successfully; insert some rows... $cols = array( 'id' => 1, 'name' => 'name', ); $res = $this->insert($cols); if (PEAR::isError($res)) { return PEAR::throwError($res->getMessage()); } return $res; } } // class my_table Expected result: ---------------- I think only 'drop' mode should call create(). Actual result: -------------- Unwanted data inserts in 'alter' creation mode.

Comments

 [2006-04-04 21:19 UTC] wiesemann (Mark Wiesemann)
Thanks for the hint, I wasn't aware that adding the new 'alter' mode to create() could break BC (backwards compatibility). That means: The call of create() was intentional. In create() there is a distinction between the different values of $flag. I will change that so that your code will work as you expect it, i.e. create() will be called only on 'safe' and 'drop' creation modes. That might take some days ...
 [2006-04-07 16:55 UTC] wiesemann (Mark Wiesemann)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/DB_Table
 [2006-04-07 18:19 UTC] vdb at mail dot ru
Tank you, Mark. Though I've found a few copy&past errors. Suggested patch: --- Table.php.new 2006-04-07 20:48:22.000000000 +0400 +++ Table.php 2006-04-07 21:56:00.000000000 +0400 @@ -754,20 +754,20 @@ // check whether the chosen mode is supported list($phptype,) = DB_Table::getPHPTypeAndDBSyntax($this->db); - $mode_supported = DB_Table::modeSupported($flag, $phptype); + $mode_supported = DB_Table::modeSupported($create, $phptype); if (PEAR::isError($mode_supported)) { return $mode_supported; } if (!$mode_supported) { return $this->throwError( DB_TABLE_ERR_CREATE_PHPTYPE, - "('$flag', '$phptype')" + "('$create', '$phptype')" ); } include_once 'DB/Table/Manager.php'; - switch ($flag) { + switch ($create) { case 'alter': $result = $this->alter(); @@ -775,7 +775,7 @@ case 'drop': case 'safe': - $result = $this->create($flag); + $result = $this->create($create); break; case 'verify': @@ -863,7 +863,7 @@ // unknown creation mode return $this->throwError( DB_TABLE_ERR_CREATE_FLAG, - "('$flag')" + "('$mode')" ); } }
 [2006-04-07 20:09 UTC] wiesemann (Mark Wiesemann)
Hi, thanks for paying attention, those error weren't intended. ;-) A new release will follow soon.