From 0430b37250c76ab632ed1b3e61d967666b31312a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 8 Jun 2017 19:14:07 -0700 Subject: Add support for collation sequences implemented in Go. This allows Go programs to register custom comparison functions with sqlite, and ORDER BY that comparator. --- sqlite3.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'sqlite3.go') diff --git a/sqlite3.go b/sqlite3.go index 33b9b9c..c16204c 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -100,6 +100,8 @@ int _sqlite3_create_function( } void callbackTrampoline(sqlite3_context*, int, sqlite3_value**); + +int compareTrampoline(void*, int, char*, int, char*); */ import "C" import ( @@ -313,6 +315,29 @@ func (tx *SQLiteTx) Rollback() error { return err } +// RegisterCollation makes a Go function available as a collation. +// +// cmp receives two UTF-8 strings, a and b. The result should be 0 if +// a==b, -1 if a < b, and +1 if a > b. +// +// cmp must always return the same result given the same +// inputs. Additionally, it must have the following properties for all +// strings A, B and C: if A==B then B==A; if A==B and B==C then A==C; +// if AA; if A