PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject_FormBuilder » Bug #4902

saving new objects to database

Details

Submitted2005-07-24 12:47 UTC
Fromjoost at deetman dot nl
Assignedjustinpatrin
StatusNo Feedback
PackageDB_DataObject_FormBuilder
PHP Version4.3.10
Roadmaps(Not assigned)

Comments

[2005-07-24 12:47 UTC] joost at deetman dot nl

Description:
------------
I have a problem with saving new objects to the database. (PostgreSQL)

Test script:
---------------
$do =& new MyDataObject();
$fg =& DB_DataObject_FormBuilder::create($do);
$form =& $fg->getForm();

if ($form->validate()) {
$form->process(array(&$fg,'processForm'), false);
$form->freeze();
}

$form->display();

Expected result:
----------------
FormBuilder.php has to autodedect if the submitted values requires a update or insert. However, in a situation where a new value has to be inserted, FormBuilder tries to update a null-value:

if (!isset($this->_do->$pk) || !strlen($this->_do->$pk)) {
$action = DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT;
}

Actual result:
--------------
However $this->_do->$pk is set with the value "NULL", so it would not pass the test. isset -> true, strlen('Object') = 6 -> = true.

A fix for this problem:

if (!isset($this->_do->$pk) || !strlen($this->_do->$pk) || $this->_do->$pk->value == "NULL") {
$action = DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT;
}

[2005-07-24 18:45 UTC] joost at deetman dot nl

I'm not setting the primary key, however when I var_dump the primary key:

var_dump($this->_do->$pk);

object(db_dataobject_cast)(8) {
["type"]=>
string(3) "sql"
["day"]=>
NULL
["month"]=>
NULL
["year"]=>
NULL
["value"]=>
string(4) "NULL"
["hour"]=>
NULL
["minute"]=>
NULL
["second"]=>
NULL
}

Could it be a problem related to DataObject?