|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesphp_sqlite3_create_collation.patch (last revision 2012-01-29 02:52 UTC by macdewar at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-01-24 19:14 UTC] macdewar at gmail dot com
[2012-01-28 02:17 UTC] rasmus@php.net
[2012-01-28 02:17 UTC] rasmus@php.net
-Status: Open
+Status: Feedback
[2012-01-29 02:50 UTC] macdewar at gmail dot com
[2012-01-29 03:03 UTC] macdewar at gmail dot com
-Status: Feedback
+Status: Open
[2012-01-29 03:03 UTC] macdewar at gmail dot com
[2012-01-29 03:57 UTC] rasmus@php.net
[2012-01-29 04:01 UTC] rasmus@php.net
[2012-01-29 04:01 UTC] rasmus@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: rasmus
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Description: ------------ The C API for SQLite3 offers an sqlite3_create_collation() feature that is missing from the PHP SQLite3 class. createCollation() should be added to SQLite3, much like createFunction() and createAggregate(). This allows using a PHP function or user-defined function as a collation for use in SQL, e.g.: $db->createCollation('my_sort_rule', function($a,$b){ return custom_compare($a,$b); }); $db->query('SELECT col FROM table ORDER BY col COLLATE my_sort_rule'); The included patch adds SQLite3::createCollation(). (the diff is against 5.3.9 release code, but patching 5.3-dev or 5.4-dev with it works as of 2012-01-24) Request #55226 is related -- asking for the same feature in PDO-sqlite3. Test script: --------------- <?php $db = new SQLite3(':memory:'); $db->createCollation('NATCMP', 'strnatcmp'); $db->exec('CREATE TABLE t (s varchar(4))'); $db->exec("INSERT INTO t VALUES ('a1') "); $db->exec("INSERT INTO t VALUES ('a10')"); $db->exec("INSERT INTO t VALUES ('a2') "); $defaultSort = $db->query('SELECT s FROM t ORDER BY s'); $naturalSort = $db->query('SELECT s FROM t ORDER BY s COLLATE NAT'); echo "default\n"; while ($row = $defaultSort->fetchArray()){ echo $row['s'], "\n"; } echo "natural\n"; while ($row = $naturalSort->fetchArray()){ echo $row['s'], "\n"; } $db->close(); ?> Expected result: ---------------- default a1 a10 a2 natural a1 a2 a10 Actual result: -------------- SQLite3::createCollation doesn't exist (yet).