<?xml version="1.0"?>
<?xml-stylesheet 
 href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/7287/bug">
    <title>PEAR Bug #7287</title>
    <link>http://pear.php.net/bugs/7287</link>
    <description>[Closed] create is triggered while in 'alter' mode</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bugs/7287"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/7287/2006-04-07+16%3A09%3A36#2006-04-07+16%3A09%3A36"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/7287/2006-04-07+14%3A19%3A16#2006-04-07+14%3A19%3A16"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/7287/2006-04-07+12%3A55%3A55#2006-04-07+12%3A55%3A55"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/7287/2006-04-04+17%3A19%3A29#2006-04-04+17%3A19%3A29"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/7287">
      <title>vdb@... [2006-04-04 05:08:06]</title>
      <link>http://pear.php.net/bugs/7287</link>
      <description><![CDATA[<pre>DB_Table Bug
Reported by vdb@...
2006-04-04T09:08:06-00:00
PHP: 4.4.0 OS: linux Package Version: CVS

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'      =&gt; 1,                                                                                  
                    'name' =&gt; 'name',                                                                           
                );                                                                                                      
             $res = $this-&gt;insert($cols);                                                                             
             if (PEAR::isError($res))                                                                                
             {                                                                                                       
                   return PEAR::throwError($res-&gt;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.</pre>]]></description>
      <content:encoded><![CDATA[<pre>DB_Table Bug
Reported by vdb@...
2006-04-04T09:08:06-00:00
PHP: 4.4.0 OS: linux Package Version: CVS

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'      =&gt; 1,                                                                                  
                    'name' =&gt; 'name',                                                                           
                );                                                                                                      
             $res = $this-&gt;insert($cols);                                                                             
             if (PEAR::isError($res))                                                                                
             {                                                                                                       
                   return PEAR::throwError($res-&gt;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.</pre>]]></content:encoded>
      <dc:date>2006-04-04T09:08:06-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/7287/2006-04-07+16%3A09%3A36#2006-04-07+16%3A09%3A36">
      <title>wiesemann [2006-04-07 20:09]</title>
      <link>http://pear.php.net/bugs/7287#1144440576</link>
      <description><![CDATA[<pre>Hi,

thanks for paying attention, those error weren't intended. ;-)

A new release will follow soon.</pre>]]></description>
      <content:encoded><![CDATA[<pre>Hi,

thanks for paying attention, those error weren't intended. ;-)

A new release will follow soon.</pre>]]></content:encoded>
      <dc:date>2006-04-07T20:09:36-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/7287/2006-04-07+14%3A19%3A16#2006-04-07+14%3A19%3A16">
      <title>vdb@... [2006-04-07 18:19]</title>
      <link>http://pear.php.net/bugs/7287#1144433956</link>
      <description><![CDATA[<pre>Tank you, Mark. Though I've found a few copy&amp;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-&gt;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-&gt;throwError(
                     DB_TABLE_ERR_CREATE_PHPTYPE,
-                    &quot;('$flag', '$phptype')&quot;
+                    &quot;('$create', '$phptype')&quot;
                 );
             }
 
             include_once 'DB/Table/Manager.php';
 
-            switch ($flag) {
+            switch ($create) {
 
                 case 'alter':
                     $result = $this-&gt;alter();
@@ -775,7 +775,7 @@
 
                 case 'drop':
                 case 'safe':
-                    $result = $this-&gt;create($flag);
+                    $result = $this-&gt;create($create);
                     break;
 
                 case 'verify':
@@ -863,7 +863,7 @@
                 // unknown creation mode
                 return $this-&gt;throwError(
                     DB_TABLE_ERR_CREATE_FLAG,
-                    &quot;('$flag')&quot;
+                    &quot;('$mode')&quot;
                 );
         }
     }</pre>]]></description>
      <content:encoded><![CDATA[<pre>Tank you, Mark. Though I've found a few copy&amp;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-&gt;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-&gt;throwError(
                     DB_TABLE_ERR_CREATE_PHPTYPE,
-                    &quot;('$flag', '$phptype')&quot;
+                    &quot;('$create', '$phptype')&quot;
                 );
             }
 
             include_once 'DB/Table/Manager.php';
 
-            switch ($flag) {
+            switch ($create) {
 
                 case 'alter':
                     $result = $this-&gt;alter();
@@ -775,7 +775,7 @@
 
                 case 'drop':
                 case 'safe':
-                    $result = $this-&gt;create($flag);
+                    $result = $this-&gt;create($create);
                     break;
 
                 case 'verify':
@@ -863,7 +863,7 @@
                 // unknown creation mode
                 return $this-&gt;throwError(
                     DB_TABLE_ERR_CREATE_FLAG,
-                    &quot;('$flag')&quot;
+                    &quot;('$mode')&quot;
                 );
         }
     }</pre>]]></content:encoded>
      <dc:date>2006-04-07T18:19:16-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/7287/2006-04-07+12%3A55%3A55#2006-04-07+12%3A55%3A55">
      <title>wiesemann [2006-04-07 16:55]</title>
      <link>http://pear.php.net/bugs/7287#1144428955</link>
      <description><![CDATA[<pre>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</pre>]]></description>
      <content:encoded><![CDATA[<pre>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</pre>]]></content:encoded>
      <dc:date>2006-04-07T16:55:55-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/7287/2006-04-04+17%3A19%3A29#2006-04-04+17%3A19%3A29">
      <title>wiesemann [2006-04-04 21:19]</title>
      <link>http://pear.php.net/bugs/7287#1144185569</link>
      <description><![CDATA[<pre>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 ...</pre>]]></description>
      <content:encoded><![CDATA[<pre>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 ...</pre>]]></content:encoded>
      <dc:date>2006-04-04T21:19:29-00:00</dc:date>
    </item>
</rdf:RDF>