File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
ext /
sqlite3 /
tests /
sqlite3_25_create_aggregate.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Feb 21 23:48:02 2012 UTC (13 years, 1 month ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
v5_3_10,
HEAD
php
--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
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>