From 4ff17d31b3d35ca39944a0f2829e457e6b5dcdda Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 21 Mar 2020 12:40:20 +1000 Subject: [PATCH] add unicase collation sqlite's like is hard-coded to use ASCII comparisons, so we can't take advantage of this yet --- rslib/Cargo.toml | 5 +++-- rslib/src/storage/sqlite.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rslib/Cargo.toml b/rslib/Cargo.toml index 58e5d5c90..627d96efa 100644 --- a/rslib/Cargo.toml +++ b/rslib/Cargo.toml @@ -38,12 +38,13 @@ slog-async = "2.4.0" slog-envlogger = "2.2.0" serde_repr = "0.1.5" num_enum = "0.4.2" +unicase = "2.6.0" [target.'cfg(target_vendor="apple")'.dependencies] -rusqlite = { version = "0.21.0", features = ["trace", "functions"] } +rusqlite = { version = "0.21.0", features = ["trace", "functions", "collation"] } [target.'cfg(not(target_vendor="apple"))'.dependencies] -rusqlite = { version = "0.21.0", features = ["trace", "functions", "bundled"] } +rusqlite = { version = "0.21.0", features = ["trace", "functions", "collation", "bundled"] } [target.'cfg(linux)'.dependencies] reqwest = { version = "0.10.1", features = ["json", "native-tls-vendored"] } diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index e5502f90c..0d8a3936d 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -14,14 +14,20 @@ use crate::{ }; use regex::Regex; use rusqlite::{params, Connection, NO_PARAMS}; +use std::cmp::Ordering; use std::{ collections::HashMap, path::{Path, PathBuf}, }; +use unicase::UniCase; const SCHEMA_MIN_VERSION: u8 = 11; const SCHEMA_MAX_VERSION: u8 = 11; +fn unicase_compare(s1: &str, s2: &str) -> Ordering { + UniCase::new(s1).cmp(&UniCase::new(s2)) +} + // currently public for dbproxy #[derive(Debug)] pub struct SqliteStorage { @@ -53,6 +59,8 @@ fn open_or_create_collection_db(path: &Path) -> Result { add_field_index_function(&db)?; add_regexp_function(&db)?; + db.create_collation("unicase", unicase_compare)?; + Ok(db) }