]> pd.if.org Git - zpackage/blobdiff - sqlite/extensions.c
add vercmp collation to zpm-shell
[zpackage] / sqlite / extensions.c
diff --git a/sqlite/extensions.c b/sqlite/extensions.c
new file mode 100644 (file)
index 0000000..7502734
--- /dev/null
@@ -0,0 +1,44 @@
+/* Add your header comment here */
+/* Do not use <sqlite3.h>! */
+#include <sqlite3ext.h>
+SQLITE_EXTENSION_INIT1
+
+#include "zpm.h"
+/* Insert your extension code here */
+
+/* TODO: Change the entry point name so that "extension" is replaced by
+** text derived from the shared library filename as follows:  Copy every
+** ASCII alphabetic character from the filename after the last "/" through
+** the next following ".", converting each character to lowercase, and
+** discarding the first three characters if they are "lib".
+*/
+
+static int vercmp(void *not_used, int lena, const void *a,
+               int lenb, const void *b) {
+       /* not sure what the ints are, possibly string lengths */
+       if (not_used != 0) fprintf(stderr, "sqlite vercmp not_used = %p\n",
+                       not_used);
+       if (lena == 0 && lenb > 0) return 1;
+       return zpm_vercmp(a, b);
+}
+
+static int zpm_sqlite_vercmp_init(sqlite3 *db, char **pzErrMsg, 
+               const sqlite3_api_routines *pApi
+               ) {
+       int rc = SQLITE_OK;
+       SQLITE_EXTENSION_INIT2(pApi);
+       rc = sqlite3_create_collation(db, "vercmp", SQLITE_UTF8, NULL, vercmp);
+       /* Insert here calls to
+        **     sqlite3_create_function_v2(),
+        **     sqlite3_create_collation_v2(),
+        **     sqlite3_create_module_v2(), and/or
+        **     sqlite3_vfs_register()
+        ** to register the new features that your extension adds.
+        */
+       return rc;
+}
+
+void zpm_setup_extensions(void) {
+       sqlite3_auto_extension( (void (*)(void))zpm_sqlite_vercmp_init);
+       return;
+}