PEAR is archived and read-only

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

Home » Database » DB_DataObject » Bug #1873

DB_DataObject::Validate() incorrectly handles null values

Details

Request #1873DB_DataObject::Validate() incorrectly handles null values
Submitted2004-07-14 15:45 UTC
Fromncosta at alum dot rpi dot edu
StatusSuspended
PackageDB_DataObject
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-07-14 15:45 UTC] ncosta at alum dot rpi dot edu

Description:
------------
DB_DataObject::Validate() flags NULL values in columns
marked as NOT NULL as invalid. However, a NULL value may
NOT be invalid prior to an insert if the column has a
default value or is an auto_increment value. Thus for
any such column DB_DataObject:: Validate() will return a
false invalid column for an object that will insert
successfully.

It may be difficult for the object to determine whether
the validation should be for a new insert or a current
row in the table; the current version of the function is
correct for the latter. The function could determine
whether the object has been inserted or not and then
validate according to default and auto_increment values.

Reproduce code:
---------------
/* table:
row_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
row_name VARCHAR(255)
*/

$myRow = new Row;
$myRow->row_name = "Name";

$validity = $myRow->validate();
if($validity === true) {
echo "Success!";
}
else {
foreach($validity as $k => $v) {
if($v === false) echo 'Invalid '.$k;

Expected result:
----------------
Success!

Actual result:
--------------
Invalid row_id