1--TEST-- 2Test SQLite3::createCollation() by adding strnatcmp() as an SQL COLLATE sequence 3--EXTENSIONS-- 4sqlite3 5--FILE-- 6<?php 7 8require_once __DIR__ . '/new_db.inc'; 9 10$db->createCollation('NAT', 'strnatcmp'); 11 12$db->exec('CREATE TABLE t (s varchar(4))'); 13 14$stmt = $db->prepare('INSERT INTO t VALUES (?)'); 15foreach(array('a1', 'a10', 'a2') as $s){ 16 $stmt->bindParam(1, $s); 17 $stmt->execute(); 18} 19 20$defaultSort = $db->query('SELECT s FROM t ORDER BY s'); //memcmp() sort 21$naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); //strnatcmp() sort 22 23echo "default\n"; 24while ($row = $defaultSort->fetchArray()){ 25 echo $row['s'], "\n"; 26} 27 28echo "natural\n"; 29while ($row = $naturalSort->fetchArray()){ 30 echo $row['s'], "\n"; 31} 32 33$db->close(); 34 35?> 36--EXPECT-- 37default 38a1 39a10 40a2 41natural 42a1 43a2 44a10 45