update rusqlite

This commit is contained in:
Damien Elmes 2020-05-16 19:49:08 +10:00
parent 78a6813b9b
commit da43d22aa5
2 changed files with 8 additions and 21 deletions

View file

@ -47,13 +47,12 @@ rand = "0.7.3"
num-integer = "0.1.42" num-integer = "0.1.42"
itertools = "0.9.0" itertools = "0.9.0"
# pinned until rusqlite 0.22 comes out
[target.'cfg(target_vendor="apple")'.dependencies.rusqlite] [target.'cfg(target_vendor="apple")'.dependencies.rusqlite]
version = "0.22" version = "0.23.1"
features = ["trace", "functions", "collation"] features = ["trace", "functions", "collation"]
[target.'cfg(not(target_vendor="apple"))'.dependencies.rusqlite] [target.'cfg(not(target_vendor="apple"))'.dependencies.rusqlite]
version = "0.22" version = "0.23.1"
features = ["trace", "functions", "collation", "bundled"] features = ["trace", "functions", "collation", "bundled"]
[target.'cfg(linux)'.dependencies] [target.'cfg(linux)'.dependencies]

View file

@ -9,7 +9,7 @@ use crate::{i18n::I18n, sched::cutoff::v1_creation_date, text::without_combining
use regex::Regex; use regex::Regex;
use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS}; use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::{borrow::Cow, path::Path}; use std::{borrow::Cow, path::Path, sync::Arc};
use unicase::UniCase; use unicase::UniCase;
const SCHEMA_MIN_VERSION: u8 = 11; const SCHEMA_MIN_VERSION: u8 = 11;
@ -89,6 +89,7 @@ fn add_without_combining_function(db: &Connection) -> rusqlite::Result<()> {
/// Adds sql function regexp(regex, string) -> is_match /// Adds sql function regexp(regex, string) -> is_match
/// Taken from the rusqlite docs /// Taken from the rusqlite docs
type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> { fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
db.create_scalar_function( db.create_scalar_function(
"regexp", "regexp",
@ -97,21 +98,12 @@ fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
move |ctx| { move |ctx| {
assert_eq!(ctx.len(), 2, "called with unexpected number of arguments"); assert_eq!(ctx.len(), 2, "called with unexpected number of arguments");
let saved_re: Option<&Regex> = ctx.get_aux(0)?; let re: Arc<Regex> = ctx
let new_re = match saved_re { .get_or_create_aux(0, |vr| -> std::result::Result<_, BoxError> {
None => { Ok(Regex::new(vr.as_str()?)?)
let s = ctx.get::<String>(0)?; })?;
match Regex::new(&s) {
Ok(r) => Some(r),
Err(err) => return Err(rusqlite::Error::UserFunctionError(Box::new(err))),
}
}
Some(_) => None,
};
let is_match = { let is_match = {
let re = saved_re.unwrap_or_else(|| new_re.as_ref().unwrap());
let text = ctx let text = ctx
.get_raw(1) .get_raw(1)
.as_str() .as_str()
@ -120,10 +112,6 @@ fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
re.is_match(text) re.is_match(text)
}; };
if let Some(re) = new_re {
ctx.set_aux(0, re);
}
Ok(is_match) Ok(is_match)
}, },
) )