/* call-seq: db.collation(name, comparator)
*
* Add a collation with name +name+, and a +comparator+ object. The
* +comparator+ object should implement a method called "compare" that takes
* two parameters and returns an integer less than, equal to, or greater than
* 0.
*/
static VALUE collation(VALUE self, VALUE name, VALUE comparator)
{
sqlite3RubyPtr ctx;
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);
CHECK(ctx->db, sqlite3_create_collation_v2(
ctx->db,
StringValuePtr(name),
SQLITE_UTF8,
(void *)comparator,
NIL_P(comparator) ? NULL : rb_comparator_func,
NULL));
/* Make sure our comparator doesn't get garbage collected. */
rb_hash_aset(rb_iv_get(self, "@collations"), name, comparator);
return self;
}