summaryrefslogtreecommitdiff
path: root/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt')
-rw-r--r--ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt58
1 files changed, 58 insertions, 0 deletions
diff --git a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
new file mode 100644
index 0000000..6626ed6
--- /dev/null
+++ b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
@@ -0,0 +1,58 @@
+--TEST--
+SQLite3::createAggregate() test
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+require_once(dirname(__FILE__) . '/new_db.inc');
+
+function sum_list_step($context, $rows, $string) {
+ if (empty($context))
+ {
+ $context = array('total' => 0, 'values' => array());
+ }
+ $context['total'] += intval($string);
+ $context['values'][] = $context['total'];
+ return $context;
+}
+
+function sum_list_finalize($context) {
+ return implode(',', $context['values']);
+}
+
+echo "Creating Table\n";
+var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)'));
+
+echo "INSERT into table\n";
+var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)"));
+var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)"));
+var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)"));
+var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
+var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
+
+$db->createAggregate('S', 'sum_list_step', 'sum_list_finalize', 1);
+
+print_r($db->querySingle("SELECT S(a), S(b) FROM test", true));
+
+echo "Closing database\n";
+var_dump($db->close());
+echo "Done\n";
+?>
+--EXPECTF--
+Creating Table
+bool(true)
+INSERT into table
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Array
+(
+ [S(a)] => 1,3,6,10,14
+ [S(b)] => -1,-3,-6,-10,-14
+)
+Closing database
+bool(true)
+Done