summaryrefslogtreecommitdiff
path: root/ext/sqlite/tests/sqlite_closures_002.phpt
blob: e880bb17335e6ddb14873d58986a3417e729b79a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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!