0

The PDO SQLite extension has a sqliteCreateCollation() method that isn't documented.

Seems like it's usage involves 3 arguments:

  • &collation_name
  • &collation_name_len
  • &callback

I assume &collation_name must be the collation name / identifier to use in SQL statements:

 SELECT foo FROM bar ORDER BY foo COLLATE &collation_name;

I'm clueless about &collation_name_len however. Also, what arguments does &callback need?

Alix Axel
  • 151,645
  • 95
  • 393
  • 500

1 Answers1

0

Checks Sqlite collation documentation. sqliteCreateCollation registers a function for use as a collating function within SQL statements. I don't know about collation_name_len (suggest string length of first parameter, but that no make sense) parameter, but callback is the function we wants call in collation sequence.

See SQLite3::createCollation for further details and full working example.

rernesto
  • 554
  • 4
  • 11
  • I'm aware of SQLite UDF collations. I interested in knowing how to call that method (in the PDO context). Something like this for instance: `PDO::sqliteCreateCollation('pt_PT', ?, function ($a, $b){ return (new \Collator('pt_PT'))->collator_compare($a, $b); });`. – Alix Axel Nov 08 '13 at 19:01
  • First, your callback function must be capable of receive multiple parameters, would use func_get_args inside callback. Second, wouldn't be defined inline. Third, to apply collate you need add collate statement to your query... give me a break to bring you a working example. – rernesto Nov 08 '13 at 19:17
  • What you're saying doesn't make much sense man: the callback can be defined as an anonymous (inlined) function since PHP 5.4. And the variadic argument support (`func_get_args`) would be a total waste of resources (I think) - since there's no apparent need for the callback to receive more than 1 or 2 arguments, depending on the implementation. And the last point, as per the SQLite documentation, `SELECT foo FROM bar ORDER BY foo COLLATE pt_PT;` would work with that UDF collation (if I knew the right syntax, I mean). – Alix Axel Nov 08 '13 at 19:26
  • You're right, sorry, the problem is i'm working with PHP 5.3.11 on Ubuntu 12.04 LTS version (and can't be upgraded until next LTS will be released). Whatever it is, the callback function receive an array as input parameter... your callback must handle the input array as result of select statement of your query. I'm moving to other PC with PHP 5.4 to make some tests, cause i need something similar. – rernesto Nov 08 '13 at 19:59
  • Same 12.04 LTS here, but I'm running [PHP 5.5.5 via `ondrej/php5` PPA](https://github.com/alixaxel/halBox/blob/master/halBox.sh). As for the array input, that kind of scares me off. The SQLite3 extension way of doing things (2 arguments at a time) seems much much more efficient. In fact, I might use this to sort a couple million rows, indexed of course - I can't imagine PHP handling such a big array without kicking and screaming. :( – Alix Axel Nov 08 '13 at 20:06
  • The pdo function to create collations in 5.4 only require two parameters, the name and the callback... – rernesto Nov 08 '13 at 20:32
  • What is that `collation_name_len` argument in the extension source code then? And the callback, how many arguments does it accept? That's what I'm trying to understand. – Alix Axel Nov 08 '13 at 20:55