1--TEST--
2SQLite3::createAggregate() test
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8require_once(__DIR__ . '/new_db.inc');
9
10function sum_list_step($context, $rows, $string) {
11    if (empty($context))
12    {
13        $context = array('total' => 0, 'values' => array());
14    }
15    $context['total'] += intval($string);
16    $context['values'][] = $context['total'];
17    return $context;
18}
19
20function sum_list_finalize($context) {
21    return implode(',', $context['values']);
22}
23
24echo "Creating Table\n";
25var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)'));
26
27echo "INSERT into table\n";
28var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)"));
29var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)"));
30var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)"));
31var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
32var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
33
34$db->createAggregate('S', 'sum_list_step', 'sum_list_finalize', 1);
35
36print_r($db->querySingle("SELECT S(a), S(b) FROM test", true));
37
38echo "Closing database\n";
39var_dump($db->close());
40echo "Done\n";
41?>
42--EXPECT--
43Creating Table
44bool(true)
45INSERT into table
46bool(true)
47bool(true)
48bool(true)
49bool(true)
50bool(true)
51Array
52(
53    [S(a)] => 1,3,6,10,14
54    [S(b)] => -1,-3,-6,-10,-14
55)
56Closing database
57bool(true)
58Done
59