Req #60871 [Opn->Fbk]: Support creating collations in SQLite3 class
Edit report at https://bugs.php.net/bug.php?id=60871&edit=1
ID: 60871
Updated by: rasmus@php.net
Reported by: macdewar at gmail dot com
Summary: Support creating collations in SQLite3 class
-Status: Open
+Status: Feedback
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:
This doesn't compile for me. It applied cleanly but I get:
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c: In function
âphp_sqlite3_callback_compareâ:
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:885:58: warning:
dereferencing âvoid *â pointer [enabled by default]
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:885:58: error:
request for member âfciâ in something not a structure or union
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c: In function
âzim_sqlite3_createCollationâ:
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:1053:62: error:
âud_cmp_funcâ undeclared (first use in this function)
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:1053:62: note: each
undeclared identifier is reported only once for each function it appears in
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:1054:12: error:
âphp_sqlite3_collationâ has no member named âcollation_nameâ
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c: In function
âphp_sqlite3_object_free_storageâ:
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:2055:50: error:
âphp_sqlite3_collationâ has no member named âcollation_nameâ
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:2057:27: error:
âphp_sqlite3_collationâ has no member named âcollation_nameâ
/home/rasmus/php-src/branches/PHP_5_3/ext/sqlite3/sqlite3.c:2058:7: error:
âcmp_funcâ undeclared (first use in this function)
make: *** [ext/sqlite3/sqlite3.lo] Error 1
I haven't looked into it beyond applying the patch and trying to build.
Previous Comments:
------------------------------------------------------------------------
[2012-01-24 19:14:37] macdewar at gmail dot com
Test script has a typo.
replace "COLLATE NAT" with "COLLATE NATCMP"
------------------------------------------------------------------------
[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
Thread (6 messages)