xref: /PHP-5.3/ext/sqlite/tests/sqlite_005.phpt (revision b842917d)
1--TEST--
2sqlite: aggregate functions
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", "cat_step", "cat_fin");
35
36$r = sqlite_query("SELECT cat(a) from strings", $db);
37while ($row = sqlite_fetch_array($r, SQLITE_NUM)) {
38	var_dump($row);
39}
40
41sqlite_close($db);
42
43echo "DONE!\n";
44?>
45--EXPECT--
46array(1) {
47  [0]=>
48  string(11) "onetwothree"
49}
50DONE!
51