diff options
Diffstat (limited to 'ext/sqlite/tests')
-rwxr-xr-x | ext/sqlite/tests/sqlite_closures_001.phpt | 54 | ||||
-rwxr-xr-x | ext/sqlite/tests/sqlite_closures_002.phpt | 52 |
2 files changed, 106 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! diff --git a/ext/sqlite/tests/sqlite_closures_002.phpt b/ext/sqlite/tests/sqlite_closures_002.phpt new file mode 100755 index 0000000000..e880bb1733 --- /dev/null +++ b/ext/sqlite/tests/sqlite_closures_002.phpt @@ -0,0 +1,52 @@ +--TEST-- +sqlite: regular 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( + array("one", "uno"), + array("two", "dos"), + array("three", "tres"), + ); + +sqlite_query("CREATE TABLE strings(a,b)", $db); + +foreach ($data as $row) { + sqlite_query("INSERT INTO strings VALUES('" . sqlite_escape_string($row[0]) . "','" . sqlite_escape_string($row[1]) . "')", $db); +} + +sqlite_create_function($db, "implode", function () { + $args = func_get_args(); + $sep = array_shift($args); + return implode($sep, $args); +}); + +$r = sqlite_query("SELECT implode('-', a, b) 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(7) "one-uno" +} +array(1) { + [0]=> + string(7) "two-dos" +} +array(1) { + [0]=> + string(10) "three-tres" +} +DONE! |