From:             
Operating system: GNU/Linux
PHP version:      5.3.9
Package:          SQLite related
Bug Type:         Feature/Change Request
Bug description:Support creating collations in SQLite3 class

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 bug report at https://bugs.php.net/bug.php?id=60871&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60871&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60871&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60871&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60871&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60871&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60871&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60871&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60871&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60871&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60871&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60871&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60871&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60871&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60871&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60871&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60871&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60871&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60871&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60871&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60871&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60871&r=mysqlcfg

Reply via email to