Annotation of embedaddon/php/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: SQLite3::createAggregate() test
                      3: --SKIPIF--
                      4: <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
                      5: --FILE--
                      6: <?php
                      7: 
                      8: require_once(dirname(__FILE__) . '/new_db.inc');
                      9: 
                     10: function sum_list_step($context, $rows, $string) {
                     11:        if (empty($context))
                     12:        {
                     13:                $context = array('total' => 0, 'values' => array());
                     14:        }
                     15:        $context['total'] += intval($string);
                     16:        $context['values'][] = $context['total'];
                     17:        return $context;
                     18: }
                     19: 
                     20: function sum_list_finalize($context) {
                     21:        return implode(',', $context['values']);
                     22: }
                     23: 
                     24: echo "Creating Table\n";
                     25: var_dump($db->exec('CREATE TABLE test (a INTEGER, b INTEGER)'));
                     26: 
                     27: echo "INSERT into table\n";
                     28: var_dump($db->exec("INSERT INTO test (a, b) VALUES (1, -1)"));
                     29: var_dump($db->exec("INSERT INTO test (a, b) VALUES (2, -2)"));
                     30: var_dump($db->exec("INSERT INTO test (a, b) VALUES (3, -3)"));
                     31: var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
                     32: var_dump($db->exec("INSERT INTO test (a, b) VALUES (4, -4)"));
                     33: 
                     34: $db->createAggregate('S', 'sum_list_step', 'sum_list_finalize', 1);
                     35: 
                     36: print_r($db->querySingle("SELECT S(a), S(b) FROM test", true));
                     37: 
                     38: echo "Closing database\n";
                     39: var_dump($db->close());
                     40: echo "Done\n";
                     41: ?>
                     42: --EXPECTF--
                     43: Creating Table
                     44: bool(true)
                     45: INSERT into table
                     46: bool(true)
                     47: bool(true)
                     48: bool(true)
                     49: bool(true)
                     50: bool(true)
                     51: Array
                     52: (
                     53:     [S(a)] => 1,3,6,10,14
                     54:     [S(b)] => -1,-3,-6,-10,-14
                     55: )
                     56: Closing database
                     57: bool(true)
                     58: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>