php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61661 Error in aggreagate function in PDO or Sqlite3
Submitted: 2012-04-07 20:25 UTC Modified: 2014-01-01 12:38 UTC
From: xelloss at hotmail dot it Assigned:
Status: Open Package: PDO SQLite
PHP Version: 5.3.10 OS: Windows XP
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-04-07 20:25 UTC] xelloss at hotmail dot it
Description:
------------
---
From manual page: http://www.php.net/sqlite3.createaggregate#refsect1-sqlite3.createaggregate-description
---
I'm trying to use the aggregate function of sqlite3class and also in pdo.
I try to use the same code from SQLiteDatabase (http://php.net/manual/en/function.sqlite-create-aggregate.php), changed for work with these two function.
But the variable context is always empty.
See code below for example.
I can declare a global variable context, but it will be used always (everytime it start with last value and if I use the aggregate function more than 1 time in a query the variable became shared)

Test script:
---------------
$data = array(
   'one',
   'two',
   'three',
   'four',
   'five',
   'six',
   'seven',
   'eight',
   'nine',
   'ten',
   );

$dbhandle = new SQLite3(':memory:');
$dbhandle->exec("CREATE TABLE strings(a)");
foreach ($data as $str) {
    $str = sqlite_escape_string($str);
    $dbhandle->exec("INSERT INTO strings VALUES ('$str')");
}

function max_len_step(&$context, $string)
{
	echo "-" . $context;
	echo "<br>";
    if (strlen($string) > $context) {
        $context = strlen($string);
    }
}

function max_len_finalize(&$context)
{
    return $context;
}

$dbhandle->createAggregate('max_len', 'max_len_step', 'max_len_finalize');

$rs = $dbhandle->query('SELECT max_len(a) from strings');


Expected result:
----------------
-
-3
-3
-5
-5
-5
-5
-5
-5
-5


Actual result:
--------------
-
-
-
-
-
-
-
-
-
-

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-01 12:38 UTC] felipe@php.net
-Package: PDO related +Package: PDO SQLite
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Feb 24 19:01:40 2017 UTC