sqlite3_36_create_collation.phpt 865 B

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