1--TEST--
2SQLite3::createFunction
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8function my_udf_md5($foo)
9{
10    return md5($foo);
11}
12
13require_once(__DIR__ . '/new_db.inc');
14define('TIMENOW', time());
15
16echo "Creating Table\n";
17var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));
18
19echo "INSERT into table\n";
20var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
21var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));
22
23echo "CREATING UDF\n";
24var_dump($db->createFunction('my_udf_md5', 'my_udf_md5'));
25
26echo "SELECTING results\n";
27$results = $db->query("SELECT my_udf_md5(id) FROM test ORDER BY id ASC");
28while ($result = $results->fetchArray(SQLITE3_NUM))
29{
30    var_dump($result);
31}
32$results->finalize();
33
34echo "Closing database\n";
35var_dump($db->close());
36echo "Done\n";
37?>
38--EXPECT--
39Creating Table
40bool(true)
41INSERT into table
42bool(true)
43bool(true)
44CREATING UDF
45bool(true)
46SELECTING results
47array(1) {
48  [0]=>
49  string(32) "0cc175b9c0f1b6a831c399e269772661"
50}
51array(1) {
52  [0]=>
53  string(32) "92eb5ffee6ae2fec3ad71c777531578f"
54}
55Closing database
56bool(true)
57Done
58