Enhance the command-line completion extension to return the names of
[sqlite.git] / ext / misc / anycollseq.c
blob27b7049d5fececb4b7413fc076a06b422212cbb9
1 /*
2 ** 2017-04-16
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
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
23 #include <string.h>
25 static int anyCollFunc(
26 void *NotUsed,
27 int nKey1, const void *pKey1,
28 int nKey2, const void *pKey2
30 int rc, n;
31 n = nKey1<nKey2 ? nKey1 : nKey2;
32 rc = memcmp(pKey1, pKey2, n);
33 if( rc==0 ) rc = nKey1 - nKey2;
34 return rc;
37 static void anyCollNeeded(
38 void *NotUsed,
39 sqlite3 *db,
40 int eTextRep,
41 const char *zCollName
43 sqlite3_create_collation(db, zCollName, eTextRep, 0, anyCollFunc);
46 #ifdef _WIN32
47 __declspec(dllexport)
48 #endif
49 int sqlite3_anycollseq_init(
50 sqlite3 *db,
51 char **pzErrMsg,
52 const sqlite3_api_routines *pApi
54 int rc = SQLITE_OK;
55 SQLITE_EXTENSION_INIT2(pApi);
56 rc = sqlite3_collation_needed(db, 0, anyCollNeeded);
57 return rc;