pdo_sqlite_createcollation.phpt 908 B

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