1--TEST--
2Test SQLite3::createCollation() trampoline callback
3--EXTENSIONS--
4sqlite3
5--FILE--
6<?php
7
8require_once __DIR__ .  '/new_db.inc';
9
10class TrampolineTest {
11    public function __call(string $name, array $arguments) {
12        echo 'Trampoline for ', $name, PHP_EOL;
13        return strnatcmp(...$arguments);
14    }
15}
16$o = new TrampolineTest();
17$callback = [$o, 'NAT'];
18
19$db->createCollation('NAT', $callback);
20
21$db->exec('CREATE TABLE t (s varchar(4))');
22
23$stmt = $db->prepare('INSERT INTO t VALUES (?)');
24foreach(array('a1', 'a10', 'a2') as $s){
25    $stmt->bindParam(1, $s);
26    $stmt->execute();
27}
28
29$defaultSort = $db->query('SELECT s FROM t ORDER BY s');             //memcmp() sort
30$naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); //strnatcmp() sort
31
32echo "default\n";
33while ($row = $defaultSort->fetchArray()){
34    echo $row['s'], "\n";
35}
36
37echo "natural\n";
38while ($row = $naturalSort->fetchArray()){
39    echo $row['s'], "\n";
40}
41
42$db->close();
43
44?>
45--EXPECT--
46Trampoline for NAT
47Trampoline for NAT
48default
49a1
50a10
51a2
52natural
53Trampoline for NAT
54Trampoline for NAT
55a1
56a2
57a10
58