ID: 29266
Updated by: [EMAIL PROTECTED]
Reported By: ozy at ozy dot student dot utwente dot nl
Status: Open
-Bug Type: SQLite related
+Bug Type: Documentation problem
Operating System: Mac OS X
PHP Version: 5.0.0
New Comment:
There is no array type in SQL, so, of course this will not work.
Your finalize function, along with any other UDF, needs to return a
scalar type.
Previous Comments:
------------------------------------------------------------------------
[2004-07-19 22:27:50] ozy at ozy dot student dot utwente dot nl
Description:
------------
[code]
function array_finalize(&$context) {
if (isset($context)) {
return $context;
}
return array();
}
[/code]
see reproduce code for full snip. This is part of an
sqlite_create_aggregate().
seems perfectly legal, but the array_finalize(&$context)
can't return an array. A returned array from
sqlite_fetch_array() will explicitly hold a NULL value
instead of our array from our custom function.
If you can't return an array, please tell so in the
manual, if you are supposed to be able to return an
array, please fix this.
changing the finalize code into:
[code]
function array_finalize(&$context) {
if (isset($context)) {
return serialize($context);
}
return serialize(array());
}
[/code]
does work perfectly (if you use unserialize on the other
end of-course...)
Reproduce code:
---------------
function array_step(&$context, $element) {
if (!is_array($context)) $context = array();
if (isset($element)) {
$e = sqlite_udf_decode_binary($element);
if (!in_array($e, $context)) { // UNIQUE
$context[] = $e;
}
}
}
function array_finalize(&$context) {
if (isset($context)) {
return $context;
}
return array();
}
sqlite_create_aggregate($db, 'ARRAY', 'array_step', 'array_finalize');
$q = "SELECT name, ARRAY(friends) as friends FROM friends GROUP BY
name";
// just an example of a friends table (name,friendsname)
$r = sqlite_query($db, $q);
while ($a = sqlite_fetch_array($r, SQLITE_ASSOC)) {
foreach($a['friends'] as $friend) tellFriend($friend); // whatever
}
Expected result:
----------------
tellFriends gets executed per friend of one person. Then
we while up to the next result and tellFriends gets
executed per friend of the next person ... etc etc
Actual result:
--------------
$a['friends']=NULL
(explicitly set to NULL)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29266&edit=1