Edit report at https://bugs.php.net/bug.php?id=60871&edit=1

 ID:                 60871
 User updated by:    macdewar at gmail dot com
 Reported by:        macdewar at gmail dot com
 Summary:            Support creating collations in SQLite3 class
 Status:             Open
 Type:               Feature/Change Request
 Package:            SQLite related
 Operating System:   GNU/Linux
 PHP Version:        5.3.9
 Block user comment: N
 Private report:     N

 New Comment:

Test script has a typo.

replace "COLLATE NAT" with "COLLATE NATCMP"


Previous Comments:
------------------------------------------------------------------------
[2012-01-24 19:09:28] macdewar at gmail dot com

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).



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60871&edit=1

Reply via email to