diff options
author | dan <dan@noemail.net> | 2017-04-20 17:35:46 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2017-04-20 17:35:46 +0000 |
commit | c42a0056d7817f629d78de5d285e2df189ceb10e (patch) | |
tree | 80269bfa40a3837a9b99fe062257f9779217df4a /ext/misc/anycollseq.c | |
parent | ac33c0343f54bca37411b9f4b11115f7a583b241 (diff) | |
parent | dc62daca866006c4afa4c32c405d1a327dc7334f (diff) | |
download | sqlite-c42a0056d7817f629d78de5d285e2df189ceb10e.tar.gz sqlite-c42a0056d7817f629d78de5d285e2df189ceb10e.zip |
Merge latest trunk changes into this branch.
FossilOrigin-Name: b1533bc455f52f570c0f4b8aaa0da802757dc89b0e45b9a9b31aa591a44bf7bd
Diffstat (limited to 'ext/misc/anycollseq.c')
-rw-r--r-- | ext/misc/anycollseq.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/ext/misc/anycollseq.c b/ext/misc/anycollseq.c new file mode 100644 index 000000000..27b7049d5 --- /dev/null +++ b/ext/misc/anycollseq.c @@ -0,0 +1,58 @@ +/* +** 2017-04-16 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This file implements a run-time loadable extension to SQLite that +** registers a sqlite3_collation_needed() callback to register a fake +** collating function for any unknown collating sequence. The fake +** collating function works like BINARY. +** +** This extension can be used to load schemas that contain one or more +** unknown collating sequences. +*/ +#include "sqlite3ext.h" +SQLITE_EXTENSION_INIT1 +#include <string.h> + +static int anyCollFunc( + void *NotUsed, + int nKey1, const void *pKey1, + int nKey2, const void *pKey2 +){ + int rc, n; + n = nKey1<nKey2 ? nKey1 : nKey2; + rc = memcmp(pKey1, pKey2, n); + if( rc==0 ) rc = nKey1 - nKey2; + return rc; +} + +static void anyCollNeeded( + void *NotUsed, + sqlite3 *db, + int eTextRep, + const char *zCollName +){ + sqlite3_create_collation(db, zCollName, eTextRep, 0, anyCollFunc); +} + +#ifdef _WIN32 +__declspec(dllexport) +#endif +int sqlite3_anycollseq_init( + sqlite3 *db, + char **pzErrMsg, + const sqlite3_api_routines *pApi +){ + int rc = SQLITE_OK; + SQLITE_EXTENSION_INIT2(pApi); + rc = sqlite3_collation_needed(db, 0, anyCollNeeded); + return rc; +} |