mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
update rusqlite
This commit is contained in:
parent
78a6813b9b
commit
da43d22aa5
2 changed files with 8 additions and 21 deletions
|
@ -47,13 +47,12 @@ rand = "0.7.3"
|
|||
num-integer = "0.1.42"
|
||||
itertools = "0.9.0"
|
||||
|
||||
# pinned until rusqlite 0.22 comes out
|
||||
[target.'cfg(target_vendor="apple")'.dependencies.rusqlite]
|
||||
version = "0.22"
|
||||
version = "0.23.1"
|
||||
features = ["trace", "functions", "collation"]
|
||||
|
||||
[target.'cfg(not(target_vendor="apple"))'.dependencies.rusqlite]
|
||||
version = "0.22"
|
||||
version = "0.23.1"
|
||||
features = ["trace", "functions", "collation", "bundled"]
|
||||
|
||||
[target.'cfg(linux)'.dependencies]
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{i18n::I18n, sched::cutoff::v1_creation_date, text::without_combining
|
|||
use regex::Regex;
|
||||
use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS};
|
||||
use std::cmp::Ordering;
|
||||
use std::{borrow::Cow, path::Path};
|
||||
use std::{borrow::Cow, path::Path, sync::Arc};
|
||||
use unicase::UniCase;
|
||||
|
||||
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
|
||||
/// Taken from the rusqlite docs
|
||||
type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
|
||||
db.create_scalar_function(
|
||||
"regexp",
|
||||
|
@ -97,21 +98,12 @@ fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
|
|||
move |ctx| {
|
||||
assert_eq!(ctx.len(), 2, "called with unexpected number of arguments");
|
||||
|
||||
let saved_re: Option<&Regex> = ctx.get_aux(0)?;
|
||||
let new_re = match saved_re {
|
||||
None => {
|
||||
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 re: Arc<Regex> = ctx
|
||||
.get_or_create_aux(0, |vr| -> std::result::Result<_, BoxError> {
|
||||
Ok(Regex::new(vr.as_str()?)?)
|
||||
})?;
|
||||
|
||||
let is_match = {
|
||||
let re = saved_re.unwrap_or_else(|| new_re.as_ref().unwrap());
|
||||
|
||||
let text = ctx
|
||||
.get_raw(1)
|
||||
.as_str()
|
||||
|
@ -120,10 +112,6 @@ fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
|
|||
re.is_match(text)
|
||||
};
|
||||
|
||||
if let Some(re) = new_re {
|
||||
ctx.set_aux(0, re);
|
||||
}
|
||||
|
||||
Ok(is_match)
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue