PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_Table » Bug #7287

create is triggered while in 'alter' mode

Details

Submitted2006-04-04 09:08 UTC
Fromvdb at mail dot ru
Assignedwiesemann
StatusClosed
PackageDB_Table
PHP Version4.4.0
OSlinux
Roadmaps(Not assigned)

Comments

[2006-04-04 09:08 UTC] vdb at mail dot ru

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.

[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')"
);
}
}