diff options
author | Dmitry Stogov <dmitry@php.net> | 2008-07-17 09:53:42 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2008-07-17 09:53:42 +0000 |
commit | 833a2295d143c67295dd94e20a56883b4f2d0787 (patch) | |
tree | ae1e5acb20381bbdda96ad813b8772f497329de5 /ext/sqlite/tests/sqlite_closures_001.phpt | |
parent | 47e6c5d017c8e0451003f9eddcfa01db89857bd6 (diff) | |
download | php-git-833a2295d143c67295dd94e20a56883b4f2d0787.tar.gz |
Support for closures
Diffstat (limited to 'ext/sqlite/tests/sqlite_closures_001.phpt')
-rwxr-xr-x | ext/sqlite/tests/sqlite_closures_001.phpt | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ext/sqlite/tests/sqlite_closures_001.phpt b/ext/sqlite/tests/sqlite_closures_001.phpt new file mode 100755 index 0000000000..8a90d1e5e0 --- /dev/null +++ b/ext/sqlite/tests/sqlite_closures_001.phpt @@ -0,0 +1,54 @@ +--TEST-- +sqlite: aggregate functions with closures +--INI-- +sqlite.assoc_case=0 +--SKIPIF-- +<?php # vim:ft=php +if (!extension_loaded("sqlite")) print "skip"; ?> +--FILE-- +<?php +include "blankdb.inc"; + +$data = array( + "one", + "two", + "three" + ); + +sqlite_query("CREATE TABLE strings(a)", $db); + +foreach ($data as $str) { + sqlite_query("INSERT INTO strings VALUES('" . sqlite_escape_string($str) . "')", $db); +} + +function cat_step(&$context, $string) +{ + $context .= $string; +} + +function cat_fin(&$context) +{ + return $context; +} + +sqlite_create_aggregate($db, "cat", function (&$context, $string) { + $context .= $string; +}, function (&$context) { + return $context; +}); + +$r = sqlite_query("SELECT cat(a) from strings", $db); +while ($row = sqlite_fetch_array($r, SQLITE_NUM)) { + var_dump($row); +} + +sqlite_close($db); + +echo "DONE!\n"; +?> +--EXPECT-- +array(1) { + [0]=> + string(11) "onetwothree" +} +DONE! |