]> pd.if.org Git - zpackage/blob - sqlite/extensions.c
182b15e813c76189e66c7ff49537932484e41bce
[zpackage] / sqlite / extensions.c
1 /* Add your header comment here */
2 /* Do not use <sqlite3.h>! */
3 #include <sqlite3ext.h>
4 SQLITE_EXTENSION_INIT1
5
6 #include "zpm.h"
7 /* Insert your extension code here */
8
9 /* TODO: Change the entry point name so that "extension" is replaced by
10 ** text derived from the shared library filename as follows:  Copy every
11 ** ASCII alphabetic character from the filename after the last "/" through
12 ** the next following ".", converting each character to lowercase, and
13 ** discarding the first three characters if they are "lib".
14 */
15
16 static int vercmp(void *not_used, int lena, const void *a,
17                 int lenb, const void *b) {
18         /* not sure what the ints are, possibly string lengths */
19         if (not_used != 0) fprintf(stderr, "sqlite vercmp not_used = %p\n",
20                         not_used);
21         if (lena == 0 && lenb > 0) return 1;
22         return zpm_vercmp(a, b);
23 }
24
25 static int zpm_sqlite_vercmp_init(sqlite3 *db, char **pzErrMsg, 
26                 const sqlite3_api_routines *pApi
27                 ) {
28         int rc = SQLITE_OK;
29         SQLITE_EXTENSION_INIT2(pApi);
30         rc = sqlite3_create_collation(db, "vercmp", SQLITE_UTF8, NULL, vercmp);
31         /* Insert here calls to
32          **     sqlite3_create_function_v2(),
33          **     sqlite3_create_collation_v2(),
34          **     sqlite3_create_module_v2(), and/or
35          **     sqlite3_vfs_register()
36          ** to register the new features that your extension adds.
37          */
38         if (rc == SQLITE_OK) {
39                 fprintf(stderr, "vercmp collation created\n");
40         }
41         return rc;
42 }
43
44 void zpm_setup_extensions(void) {
45         sqlite3_auto_extension( (void (*)(void))zpm_sqlite_vercmp_init);
46         return;
47 }