diff --git a/ext/hash/hash.go b/ext/hash/hash.go index 4ee9cc1..c9c3cd9 100644 --- a/ext/hash/hash.go +++ b/ext/hash/hash.go @@ -29,7 +29,7 @@ import ( // Register registers cryptographic hash functions for a database connection. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS var errs util.ErrorJoiner if crypto.MD4.Available() { diff --git a/ext/regexp/regexp.go b/ext/regexp/regexp.go index 6b8ce35..8253c53 100644 --- a/ext/regexp/regexp.go +++ b/ext/regexp/regexp.go @@ -20,7 +20,7 @@ import ( // Register registers Unicode aware functions for a database connection. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS return errors.Join( db.CreateFunction("regexp", 2, flags, regex), db.CreateFunction("regexp_like", 2, flags, regexLike), diff --git a/ext/stats/stats.go b/ext/stats/stats.go index 69371c4..f16423d 100644 --- a/ext/stats/stats.go +++ b/ext/stats/stats.go @@ -52,7 +52,7 @@ import ( // Register registers statistics functions. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS return errors.Join( db.CreateWindowFunction("var_pop", 1, flags, newVariance(var_pop)), db.CreateWindowFunction("var_samp", 1, flags, newVariance(var_samp)), diff --git a/ext/unicode/unicode.go b/ext/unicode/unicode.go index 1e8989e..3620cee 100644 --- a/ext/unicode/unicode.go +++ b/ext/unicode/unicode.go @@ -38,12 +38,22 @@ import ( "golang.org/x/text/unicode/norm" ) +// Set RegisterLike to false to not register a Unicode aware LIKE operator. +// Overriding the built-in LIKE operator disables the [LIKE optimization]. +// +// [LIKE optimization]: https://sqlite.org/optoverview.html#the_like_optimization +var RegisterLike = true + // Register registers Unicode aware functions for a database connection. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS - return errors.Join( - db.CreateFunction("like", 2, flags, like), - db.CreateFunction("like", 3, flags, like), + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + var errs util.ErrorJoiner + if RegisterLike { + errs.Join( + db.CreateFunction("like", 2, flags, like), + db.CreateFunction("like", 3, flags, like)) + } + errs.Join( db.CreateFunction("upper", 1, flags, upper), db.CreateFunction("upper", 2, flags, upper), db.CreateFunction("lower", 1, flags, lower), @@ -59,12 +69,13 @@ func Register(db *sqlite3.Conn) error { return } - err := RegisterCollation(db, arg[0].Text(), name) + err := RegisterCollation(ctx.Conn(), arg[0].Text(), name) if err != nil { ctx.ResultError(err) return // notest } })) + return errors.Join(errs...) } // RegisterCollation registers a Unicode collation sequence for a database connection. @@ -146,7 +157,7 @@ func unaccent(ctx sqlite3.Context, arg ...sqlite3.Value) { unaccent := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) res, _, err := transform.Bytes(unaccent, arg[0].RawText()) if err != nil { - ctx.ResultError(err) + ctx.ResultError(err) // notest } else { ctx.ResultRawText(res) } diff --git a/ext/uuid/uuid.go b/ext/uuid/uuid.go index 05bb12d..2febdef 100644 --- a/ext/uuid/uuid.go +++ b/ext/uuid/uuid.go @@ -27,7 +27,7 @@ import ( // // Converts a UUID into a 16-byte blob. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS return errors.Join( db.CreateFunction("uuid", 0, sqlite3.INNOCUOUS, generate), db.CreateFunction("uuid", 1, sqlite3.INNOCUOUS, generate), diff --git a/ext/zorder/zorder.go b/ext/zorder/zorder.go index be5a290..627b632 100644 --- a/ext/zorder/zorder.go +++ b/ext/zorder/zorder.go @@ -12,7 +12,7 @@ import ( // Register registers the zorder and unzorder SQL functions. func Register(db *sqlite3.Conn) error { - flags := sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS + const flags = sqlite3.DETERMINISTIC | sqlite3.INNOCUOUS return errors.Join( db.CreateFunction("zorder", -1, flags, zorder), db.CreateFunction("unzorder", 3, flags, unzorder))