1--TEST--
2PDO_sqlite: Testing sqliteCreateCollation()
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7
8$db = new PDO('sqlite::memory:');
9$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10
11$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
12
13$db->query('INSERT INTO foobar VALUES (NULL, "1")');
14$db->query('INSERT INTO foobar VALUES (NULL, "2")');
15$db->query('INSERT INTO foobar VALUES (NULL, "10")');
16
17$db->sqliteCreateCollation('MYCOLLATE', function($a, $b) { return strnatcmp($a, $b); });
18
19$result = $db->query('SELECT name FROM foobar ORDER BY name COLLATE MYCOLLATE');
20foreach ($result as $row) {
21    echo $row['name'] . "\n";
22}
23
24$result = $db->query('SELECT name FROM foobar ORDER BY name');
25foreach ($result as $row) {
26  echo $row['name'] . "\n";
27}
28
29$db->query('DROP TABLE foobar');
30
31?>
32--EXPECT--
331
342
3510
361
3710
382
39