PEAR is archived and read-only

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

Home » Database » DB_DataObject_FormBuilder » Bug #3036

Use of $this->_do->sequenceKey in processForm();

Details

Submitted2004-12-27 15:20 UTC
Fromrolf at winmutt dot com
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP Version5.0.3
OSGentoo/pgsql
Roadmaps(Not assigned)

Comments

[2004-12-27 15:20 UTC] rolf at winmutt dot com

Description:
------------
Use of $this->_do->sequenceKey in processForm() causes no valid PK to be returned if the PK is a non serial, ie md5(random()) for a user_id in a users table. I havhe changed this to $this->_do->keys() and the code appears to be functioning :

if (isset($this->_do->primary_key)) {
$pk = $this->_do->primary_key;
} else {
// $keys = $this->_do->sequenceKey();
$keys = $this->_do->keys();
if (is_array($keys) && isset($keys[0])) {
$pk = $keys[0];
}
}

Reproduce code:
---------------
original code :

if (isset($this->_do->primary_key)) {
$pk = $this->_do->primary_key;
} else {
$keys = $this->_do->sequenceKey();
if (is_array($keys) && isset($keys[0])) {
$pk = $keys[0];
}
}

Expected result:
----------------
an update instead of an insert with pk set.

[2004-12-27 15:27 UTC] rolf at winmutt dot com

Perhaps an additional if would be more appropriate :

if (isset($this->_do->primary_key)) {
$pk = $this->_do->primary_key;
} elseif ($keys = $this->_do->sequenceKey()) {
if (is_array($keys) && isset($keys[0])) {
$pk = $keys[0];
}
} elseif ($keys = $this->_do->keys()) {
if (is_array($keys) && isset($keys[0])) {
$pk = $keys[0];
}
}

[2004-12-28 17:04 UTC] rolf at winmutt dot com

I have overloaded the insert func to create md5(random()),
I could rework it and have a sequence for the table, but
it makes more sense to me to keep the application of the
function as broad as possible. It would be especially
useful for people who inherit a database (last job I
worked at, I inherited 7th generation code from a wide
variety of skillsets. I am using the CVS ver of
dataObjects, and no mention of deprication for keys,
although I'm sure you guys have more intimate knowledge
than I do.

[2004-12-29 17:45 UTC] rolf at winmutt dot com

I perfer to use a 32character string for user_id's as it
keeps random hijacking of a user_id to a minimum (kcalc
tells me 1 in 256^32 = 1.157920892373162e+77). I agree its
not std, but everyuone likes flexibility!