1--TEST--
2sqlite: aggregate functions with closures
3--INI--
4sqlite.assoc_case=0
5--SKIPIF--
6<?php # vim:ft=php
7if (!extension_loaded("sqlite")) print "skip"; ?>
8--FILE--
9<?php
10include "blankdb.inc";
11
12$data = array(
13	"one",
14	"two",
15	"three"
16	);
17
18sqlite_query("CREATE TABLE strings(a)", $db);
19
20foreach ($data as $str) {
21	sqlite_query("INSERT INTO strings VALUES('" . sqlite_escape_string($str) . "')", $db);
22}
23
24function cat_step(&$context, $string)
25{
26	$context .= $string;
27}
28
29function cat_fin(&$context)
30{
31	return $context;
32}
33
34sqlite_create_aggregate($db, "cat", function (&$context, $string) {
35	$context .= $string;
36}, function (&$context) {
37	return $context;
38});
39
40$r = sqlite_query("SELECT cat(a) from strings", $db);
41while ($row = sqlite_fetch_array($r, SQLITE_NUM)) {
42	var_dump($row);
43}
44
45sqlite_close($db);
46
47echo "DONE!\n";
48?>
49--EXPECT--
50array(1) {
51  [0]=>
52  string(11) "onetwothree"
53}
54DONE!
55