>
> Is it just me? It seems like the Zend_Db classes and gateways do not
> handle NULL values very well (or at all). All databases differentiate
> between NULL and ''.
>
FYI, that last statement should be true but it isn't. In Oracle, NULL and
'' are equal. :-(
Arthur Kang wrote:
>
> array('key' => NULL) should be valid and should be different than
> array('key' => '')
>
> $a = array();
> $a['key'] = NULL;
> $a['key2'] = '';
> Zend_Debug::Dump($a);
>
Your example code above does distinguish between NULL and ''.
(I changed your 'key' to 'key1' to avoid conflict with SQL keyword KEY.)
The output of your example is:
array(2) {
["key1"] => NULL
["key2"] => string(0) ""
}
If you use this array $a for data to insert into a database, you get
distinct data in the database.
// Adapter method:
$db->insert('foo', $a);
// Table class interface:
class foo extends Zend_Db_Table_Abstract { }
$foo = new foo($db);
$row = $foo->createRow($a);
var_dump($row->toArray());
// Output:
array(3) {
["id"]=>
NULL
["key1"]=>
NULL
["key2"]=>
string(0) ""
}
$row->save();
var_dump($db->fetchAll("SELECT * FROM foo"));
// Output:
array(2) {
[0]=>
array(3) {
["id"]=>
int(12)
["key1"]=>
NULL
["key2"]=>
string(0) ""
}
[1]=>
array(3) {
["id"]=>
int(13)
["key1"]=>
NULL
["key2"]=>
string(0) ""
}
}
If there's a scenario other than inserting data that you're concerned about,
it would help if you were more specific.
Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/Zend_Db-and-NULL-values-tp19097510p19098109.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论