#84 Bad comparison for ADOFieldObject::has_default

open
5
2007-04-29
2007-04-29
Daniel
No

In mysql_driver.inc and mysqli_driver.inc, at line 275 we can find:

if ($d != '' && $d != 'NULL') {
$fld->has_default = true;
$fld->default_value = $d;
} else {
$fld->has_default = false;
}

Which is bad because it would consider a default value of "" or "0" to be non existant, even if explicitly specified via SQL like in:

image VARCHAR(255) DEFAULT ''

The code has to be patched this way:

$fld->has_default = ($d != 'NULL');
if ($fld->has_default)
$fld->default_value = $d;

The bug is present in mysqli_driver.inc and mysql_driver.inc, I have not checked other drivers.

Discussion