From 1f4be3e92fd5c795f8a04c7ca4196abc33af07f6 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Fri, 30 Jun 2023 10:46:27 +0100 Subject: [PATCH] I experimented with custom collations to match JS sort order, but 5x slower --- .../tiddlywiki/sqlite3store/sql-functions.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugins/tiddlywiki/sqlite3store/sql-functions.js b/plugins/tiddlywiki/sqlite3store/sql-functions.js index 8091bcf47..32e662b09 100644 --- a/plugins/tiddlywiki/sqlite3store/sql-functions.js +++ b/plugins/tiddlywiki/sqlite3store/sql-functions.js @@ -14,6 +14,27 @@ $tw.SqlFunctions = function(options) { options = options || {}; var self = this; this.db = new $tw.sqlite3.oo1.DB("/tiddlywiki.sqlite3","c"); + // Setup custom collation to precisely match existing sort orders + // Create field with `title TEXT NOT NULL COLLATE custom_collation` + // Use it like `... order by shadow collate custom_collation` + // function customCollation(ptr,lenA,a,lenB,b) { + // var jsA = $tw.sqlite3.wasm.cstrToJs(a).slice(0,lenA), + // jsB = $tw.sqlite3.wasm.cstrToJs(b).slice(0,lenB); + // if(jsA < jsB) { + // return -1; + // } else if (jsA > jsB) { + // return +1; + // } else { + // return 0; + // } + // } + // var SQLITE_UTF8 = 1; /* IMP: R-37514-35566 */ + // var SQLITE_UTF16LE = 2; /* IMP: R-03371-37637 */ + // var SQLITE_UTF16BE = 3; /* IMP: R-51971-34154 */ + // var SQLITE_UTF16 = 4; /* Use native byte order */ + // var SQLITE_ANY = 5; /* Deprecated */ + // var SQLITE_UTF16_ALIGNED = 8; /* sqlite3_create_collation only */ + // var collationResult = $tw.sqlite3.capi.sqlite3_create_collation_v2(this.db.pointer,"custom_collation",SQLITE_UTF8,this,customCollation,0); /* Create tables and indexes */