1--TEST--
2SQLite3::createAggregate() trampoline callback
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8require_once(__DIR__ . '/new_db.inc');
9
10class TrampolineTest {
11    public function __call(string $name, array $arguments) {
12        echo 'Trampoline for ', $name, PHP_EOL;
13        $context = $arguments[0];
14        if ($name === 'finalize') {
15            return implode(',', $context['values']);
16        }
17        if (empty($context)) {
18            $context = ['total' => 0, 'values' => []];
19        }
20        $context['total'] += (int) $arguments[2];
21        $context['values'][] = $context['total'];
22        return $context;
23    }
24}
25$o = new TrampolineTest();
26$step = [$o, 'step'];
27$finalize = [$o, 'finalize'];
28
29echo "Creating Table\n";
30var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)'));
31
32echo "INSERT into table\n";
33var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)"));
34var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)"));
35var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)"));
36var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
37var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
38
39$db->createAggregate('S', $step, $finalize, 1);
40
41print_r($db->querySingle("SELECT S(a), S(b) FROM test", true));
42
43echo "Closing database\n";
44var_dump($db->close());
45echo "Done\n";
46?>
47--EXPECT--
48Creating Table
49bool(true)
50INSERT into table
51bool(true)
52bool(true)
53bool(true)
54bool(true)
55bool(true)
56Trampoline for step
57Trampoline for step
58Trampoline for step
59Trampoline for step
60Trampoline for step
61Trampoline for step
62Trampoline for step
63Trampoline for step
64Trampoline for step
65Trampoline for step
66Trampoline for finalize
67Trampoline for finalize
68Array
69(
70    [S(a)] => 1,3,6,10,14
71    [S(b)] => -1,-3,-6,-10,-14
72)
73Closing database
74bool(true)
75Done
76