Home » Database » DB_Table » Bug #2842
autodrop sequencing table - w/ patch
Details
| Request #2842 | autodrop sequencing table - w/ patch |
|---|---|
| Submitted | 2004-11-28 01:23 UTC |
| From | seangirard at yahoo dot com |
| Assigned | wiesemann |
| Status | Suspended |
| Package | DB_Table |
| PHP Version | 4.3.8 |
| OS | win/linux |
| Roadmaps | (Not assigned) |
Comments
[2004-11-28 01:23 UTC] seangirard at yahoo dot com
Description:
------------
Paul,
Following up on the wiki, I would like to see a call DB_Table::create() clean up the sequencing table associated with the object. I think you know already what I'm getting at.
Below I put a patch to Table.php that might say it more succinctly. Note that patch below requires adding
var $seq = null; // or something else
to the class you are working with.
As you pointed out, going down this road pretty much requires storing the sequence suffix in the schema (or else doing some ugly string matching maybe).
So as a consequence, for example, I added the following to my 'example' class:
function nextId()
{
return parent::nextId($this->seq);
}
Anyway, the code below would essentially replace the line of Table.php where create() returns the DB_Table_Manager::create() value. Hope it helps.
-sean
Reproduce code:
---------------
// originally returned here; trap value so we can return it later
$create = DB_Table_Manager::create(
$this->db, $this->table, $this->col, $this->idx, $flag
);
// build sequencing table name
if (is_null($this->seq)) { // note we have a new class member: $seq
$seq_name = "_{$this->table}_id";
} else {
$seq_name = "_{$this->table}_{$this->seq}"; // again, $this->seq
}
// manually add '_seq' or similar to replicate PEAR::DB::nextID() behavior - db agnostic?
$seq_name = sprintf($this->db->options['seqname_format'], $seq_name);
// only drop if the sequencing table actually exists
if (in_array($seq_name, $list) ) {
$drop = $this->db->query("DROP TABLE {$seq_name}");
if (PEAR::isError($drop)) { // no idea if i'm handling pear errors properly
// $this->throwError(); // need a new error constant? return something here?
}
}
// return expected value
return $create;
Expected result:
----------------
Now a successful call to DB_Table_Manager::create() should trigger dropping of associated sequencing table. Only tested w/ mySQL.
[2004-12-01 04:19 UTC] seangirard at yahoo dot com
changed type from bug to request. oops.