4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
13 ** This file implements a run-time loadable extension to SQLite that
14 ** registers a sqlite3_collation_needed() callback to register a fake
15 ** collating function for any unknown collating sequence. The fake
16 ** collating function works like BINARY.
18 ** This extension can be used to load schemas that contain one or more
19 ** unknown collating sequences.
21 #include "sqlite3ext.h"
22 SQLITE_EXTENSION_INIT1
25 static int anyCollFunc(
27 int nKey1
, const void *pKey1
,
28 int nKey2
, const void *pKey2
31 n
= nKey1
<nKey2
? nKey1
: nKey2
;
32 rc
= memcmp(pKey1
, pKey2
, n
);
33 if( rc
==0 ) rc
= nKey1
- nKey2
;
37 static void anyCollNeeded(
43 sqlite3_create_collation(db
, zCollName
, eTextRep
, 0, anyCollFunc
);
49 int sqlite3_anycollseq_init(
52 const sqlite3_api_routines
*pApi
55 SQLITE_EXTENSION_INIT2(pApi
);
56 rc
= sqlite3_collation_needed(db
, 0, anyCollNeeded
);