update to latest rusqlite

This commit is contained in:
Damien Elmes 2021-06-25 16:22:21 +10:00
parent 59e17950ad
commit ca0374782e
29 changed files with 393 additions and 261 deletions

31
Cargo.lock generated
View file

@ -16,9 +16,14 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.4.7"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
dependencies = [
"getrandom 0.2.3",
"once_cell",
"version_check",
]
[[package]]
name = "aho-corasick"
@ -775,17 +780,23 @@ name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]
[[package]]
name = "hashlink"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8"
checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf"
dependencies = [
"hashbrown",
"hashbrown 0.11.2",
]
[[package]]
@ -959,7 +970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.9.1",
]
[[package]]
@ -1108,9 +1119,9 @@ checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "libsqlite3-sys"
version = "0.20.1"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64d31059f22935e6c31830db5249ba2b7ecd54fd73a9909286f0a67aa55c2fbd"
checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d"
dependencies = [
"cc",
"pkg-config",
@ -1991,9 +2002,9 @@ dependencies = [
[[package]]
name = "rusqlite"
version = "0.24.2"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112"
checksum = "57adcf67c8faaf96f3248c2a7b419a0dbc52ebe36ba83dd57fe83827c1ea4eb3"
dependencies = [
"bitflags",
"fallible-iterator",

View file

@ -33,12 +33,12 @@ def raze_fetch_remote_crates():
maybe(
http_archive,
name = "raze__ahash__0_4_7",
url = "https://crates.io/api/v1/crates/ahash/0.4.7/download",
name = "raze__ahash__0_7_4",
url = "https://crates.io/api/v1/crates/ahash/0.7.4/download",
type = "tar.gz",
sha256 = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e",
strip_prefix = "ahash-0.4.7",
build_file = Label("//cargo/remote:BUILD.ahash-0.4.7.bazel"),
sha256 = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98",
strip_prefix = "ahash-0.7.4",
build_file = Label("//cargo/remote:BUILD.ahash-0.7.4.bazel"),
)
maybe(
@ -751,6 +751,16 @@ def raze_fetch_remote_crates():
build_file = Label("//cargo/remote:BUILD.h2-0.3.3.bazel"),
)
maybe(
http_archive,
name = "raze__hashbrown__0_11_2",
url = "https://crates.io/api/v1/crates/hashbrown/0.11.2/download",
type = "tar.gz",
sha256 = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e",
strip_prefix = "hashbrown-0.11.2",
build_file = Label("//cargo/remote:BUILD.hashbrown-0.11.2.bazel"),
)
maybe(
http_archive,
name = "raze__hashbrown__0_9_1",
@ -763,12 +773,12 @@ def raze_fetch_remote_crates():
maybe(
http_archive,
name = "raze__hashlink__0_6_0",
url = "https://crates.io/api/v1/crates/hashlink/0.6.0/download",
name = "raze__hashlink__0_7_0",
url = "https://crates.io/api/v1/crates/hashlink/0.7.0/download",
type = "tar.gz",
sha256 = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8",
strip_prefix = "hashlink-0.6.0",
build_file = Label("//cargo/remote:BUILD.hashlink-0.6.0.bazel"),
sha256 = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf",
strip_prefix = "hashlink-0.7.0",
build_file = Label("//cargo/remote:BUILD.hashlink-0.7.0.bazel"),
)
maybe(
@ -1103,12 +1113,12 @@ def raze_fetch_remote_crates():
maybe(
http_archive,
name = "raze__libsqlite3_sys__0_20_1",
url = "https://crates.io/api/v1/crates/libsqlite3-sys/0.20.1/download",
name = "raze__libsqlite3_sys__0_22_2",
url = "https://crates.io/api/v1/crates/libsqlite3-sys/0.22.2/download",
type = "tar.gz",
sha256 = "64d31059f22935e6c31830db5249ba2b7ecd54fd73a9909286f0a67aa55c2fbd",
strip_prefix = "libsqlite3-sys-0.20.1",
build_file = Label("//cargo/remote:BUILD.libsqlite3-sys-0.20.1.bazel"),
sha256 = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d",
strip_prefix = "libsqlite3-sys-0.22.2",
build_file = Label("//cargo/remote:BUILD.libsqlite3-sys-0.22.2.bazel"),
)
maybe(
@ -1963,12 +1973,12 @@ def raze_fetch_remote_crates():
maybe(
http_archive,
name = "raze__rusqlite__0_24_2",
url = "https://crates.io/api/v1/crates/rusqlite/0.24.2/download",
name = "raze__rusqlite__0_25_3",
url = "https://crates.io/api/v1/crates/rusqlite/0.25.3/download",
type = "tar.gz",
sha256 = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112",
strip_prefix = "rusqlite-0.24.2",
build_file = Label("//cargo/remote:BUILD.rusqlite-0.24.2.bazel"),
sha256 = "57adcf67c8faaf96f3248c2a7b419a0dbc52ebe36ba83dd57fe83827c1ea4eb3",
strip_prefix = "rusqlite-0.25.3",
build_file = Label("//cargo/remote:BUILD.rusqlite-0.25.3.bazel"),
)
maybe(

View file

@ -19,7 +19,7 @@
},
{
"name": "ahash",
"version": "0.4.7",
"version": "0.7.4",
"authors": "Tom Kaitchuck <Tom.Kaitchuck@gmail.com>",
"repository": "https://github.com/tkaitchuck/ahash",
"license": "Apache-2.0 OR MIT",
@ -701,9 +701,18 @@
"license_file": null,
"description": "A Rust port of Google's SwissTable hash map"
},
{
"name": "hashbrown",
"version": "0.11.2",
"authors": "Amanieu d'Antras <amanieu@gmail.com>",
"repository": "https://github.com/rust-lang/hashbrown",
"license": "Apache-2.0 OR MIT",
"license_file": null,
"description": "A Rust port of Google's SwissTable hash map"
},
{
"name": "hashlink",
"version": "0.6.0",
"version": "0.7.0",
"authors": "kyren <kerriganw@gmail.com>",
"repository": "https://github.com/kyren/hashlink",
"license": "Apache-2.0 OR MIT",
@ -1009,7 +1018,7 @@
},
{
"name": "libsqlite3-sys",
"version": "0.20.1",
"version": "0.22.2",
"authors": "The rusqlite developers",
"repository": "https://github.com/rusqlite/rusqlite",
"license": "MIT",
@ -1792,7 +1801,7 @@
},
{
"name": "rusqlite",
"version": "0.24.2",
"version": "0.25.3",
"authors": "The rusqlite developers",
"repository": "https://github.com/rusqlite/rusqlite",
"license": "MIT",

122
cargo/remote/BUILD.ahash-0.7.4.bazel vendored Normal file
View file

@ -0,0 +1,122 @@
"""
@generated
cargo-raze crate build file.
DO NOT EDIT! Replaced on runs of cargo-raze
"""
# buildifier: disable=load
load("@bazel_skylib//lib:selects.bzl", "selects")
# buildifier: disable=load
load(
"@rules_rust//rust:rust.bzl",
"rust_binary",
"rust_library",
"rust_test",
)
package(default_visibility = [
# Public for visibility by "@raze__crate__version//" targets.
#
# Prefer access through "//cargo", which limits external
# visibility to explicit Cargo.toml dependencies.
"//visibility:public",
])
licenses([
"notice", # MIT from expression "MIT OR Apache-2.0"
])
# Generated Targets
# buildifier: disable=out-of-order-load
# buildifier: disable=load-on-top
load(
"@rules_rust//cargo:cargo_build_script.bzl",
"cargo_build_script",
)
cargo_build_script(
name = "ahash_build_script",
srcs = glob(["**/*.rs"]),
build_script_env = {
},
crate_features = [
],
crate_root = "build.rs",
data = glob(["**"]),
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-raze",
"manual",
],
version = "0.7.4",
visibility = ["//visibility:private"],
deps = [
"@raze__version_check__0_9_3//:version_check",
] + selects.with_or({
# cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi"))
(
"@rules_rust//rust/platform:aarch64-apple-ios",
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu",
"@rules_rust//rust/platform:x86_64-apple-darwin",
"@rules_rust//rust/platform:x86_64-apple-ios",
"@rules_rust//rust/platform:x86_64-pc-windows-msvc",
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu",
): [
],
"//conditions:default": [],
}),
)
# Unsupported target "ahash" with type "bench" omitted
# Unsupported target "map" with type "bench" omitted
rust_library(
name = "ahash",
srcs = glob(["**/*.rs"]),
aliases = {
},
crate_features = [
],
crate_root = "src/lib.rs",
crate_type = "lib",
data = [],
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-raze",
"manual",
],
version = "0.7.4",
# buildifier: leave-alone
deps = [
":ahash_build_script",
] + selects.with_or({
# cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi"))
(
"@rules_rust//rust/platform:aarch64-apple-ios",
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu",
"@rules_rust//rust/platform:x86_64-apple-darwin",
"@rules_rust//rust/platform:x86_64-apple-ios",
"@rules_rust//rust/platform:x86_64-pc-windows-msvc",
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu",
): [
"@raze__getrandom__0_2_3//:getrandom",
"@raze__once_cell__1_8_0//:once_cell",
],
"//conditions:default": [],
}),
)
# Unsupported target "bench" with type "test" omitted
# Unsupported target "map_tests" with type "test" omitted
# Unsupported target "nopanic" with type "test" omitted

View file

@ -25,19 +25,20 @@ package(default_visibility = [
])
licenses([
"notice", # MIT from expression "MIT OR Apache-2.0"
"notice", # Apache-2.0 from expression "Apache-2.0 OR MIT"
])
# Generated Targets
# Unsupported target "ahash" with type "bench" omitted
# Unsupported target "map" with type "bench" omitted
# Unsupported target "bench" with type "bench" omitted
rust_library(
name = "ahash",
name = "hashbrown",
srcs = glob(["**/*.rs"]),
crate_features = [
"ahash",
"default",
"inline-more",
],
crate_root = "src/lib.rs",
crate_type = "lib",
@ -50,14 +51,17 @@ rust_library(
"cargo-raze",
"manual",
],
version = "0.4.7",
version = "0.11.2",
# buildifier: leave-alone
deps = [
"@raze__ahash__0_7_4//:ahash",
],
)
# Unsupported target "bench" with type "test" omitted
# Unsupported target "hasher" with type "test" omitted
# Unsupported target "map_tests" with type "test" omitted
# Unsupported target "rayon" with type "test" omitted
# Unsupported target "nopanic" with type "test" omitted
# Unsupported target "serde" with type "test" omitted
# Unsupported target "set" with type "test" omitted

View file

@ -36,9 +36,6 @@ rust_library(
name = "hashbrown",
srcs = glob(["**/*.rs"]),
crate_features = [
"ahash",
"default",
"inline-more",
"raw",
],
crate_root = "src/lib.rs",
@ -55,7 +52,6 @@ rust_library(
version = "0.9.1",
# buildifier: leave-alone
deps = [
"@raze__ahash__0_4_7//:ahash",
],
)

View file

@ -46,10 +46,10 @@ rust_library(
"cargo-raze",
"manual",
],
version = "0.6.0",
version = "0.7.0",
# buildifier: leave-alone
deps = [
"@raze__hashbrown__0_9_1//:hashbrown",
"@raze__hashbrown__0_11_2//:hashbrown",
],
)

View file

@ -63,7 +63,7 @@ cargo_build_script(
"cargo-raze",
"manual",
],
version = "0.20.1",
version = "0.22.2",
visibility = ["//visibility:private"],
deps = [
"@raze__cc__1_0_68//:cc",
@ -106,7 +106,7 @@ rust_library(
"cargo-raze",
"manual",
],
version = "0.20.1",
version = "0.22.2",
# buildifier: leave-alone
deps = [
":libsqlite3_sys_build_script",

View file

@ -52,6 +52,7 @@ rust_library(
"default",
"race",
"std",
"unstable",
],
crate_root = "src/lib.rs",
crate_type = "lib",

View file

@ -55,14 +55,14 @@ rust_library(
"cargo-raze",
"manual",
],
version = "0.24.2",
version = "0.25.3",
# buildifier: leave-alone
deps = [
"@raze__bitflags__1_2_1//:bitflags",
"@raze__fallible_iterator__0_2_0//:fallible_iterator",
"@raze__fallible_streaming_iterator__0_1_9//:fallible_streaming_iterator",
"@raze__hashlink__0_6_0//:hashlink",
"@raze__libsqlite3_sys__0_20_1//:libsqlite3_sys",
"@raze__hashlink__0_7_0//:hashlink",
"@raze__libsqlite3_sys__0_22_2//:libsqlite3_sys",
"@raze__memchr__2_4_0//:memchr",
"@raze__smallvec__1_6_1//:smallvec",
],

View file

@ -37,7 +37,7 @@ slog-term = "=2.6.0"
anki_i18n = { path="i18n" }
askama = "0.10.5"
async-compression = { version="0.3.8", features=["tokio", "gzip"] }
async-compression = { version = "0.3.8", features = ["tokio", "gzip"] }
blake3 = "0.3.8"
bytes = "1.0.1"
chrono = "0.4.19"
@ -69,7 +69,7 @@ reqwest = { git="https://github.com/ankitects/reqwest.git", rev="7591444614de02b
"rustls-tls-webpki-roots",
"rustls-tls-native-roots",
] }
rusqlite = { version="0.24.1", features=["trace", "functions", "collation", "bundled"] }
rusqlite = { version = "0.25.3", features = ["trace", "functions", "collation", "bundled"] }
scopeguard = "1.1.0"
serde = "1.0.126"
serde_derive = "1.0.126"
@ -78,18 +78,18 @@ serde_repr = "0.1.7"
serde_tuple = "0.5.0"
serde-aux = "2.2.0"
sha1 = "0.6.0"
slog = { version="2.7.0", features=["max_level_trace", "release_max_level_debug"] }
slog = { version = "2.7.0", features = ["max_level_trace", "release_max_level_debug"] }
slog-async = "2.6.0"
slog-envlogger = "2.2.0"
tempfile = "3.2.0"
tokio = { version="1.7.1", features=["fs", "rt-multi-thread"] }
unic-langid = { version="0.9.0", features=["macros"] }
tokio = { version = "1.7.1", features = ["fs", "rt-multi-thread"] }
unic-langid = { version = "0.9.0", features = ["macros"] }
unicode-normalization = "0.1.19"
utime = "0.3.1"
zip = { version="0.5.13", default-features=false, features=["deflate", "time"] }
zip = { version = "0.5.13", default-features = false, features = ["deflate", "time"] }
async-trait = "0.1.50"
ammonia = "3.1.1"
pulldown-cmark = "0.8.0"
fnv = "1.0.7"
strum = { version="0.21.0", features=["derive"] }
tokio-util = { version="0.6.7", features=["io"] }
strum = { version = "0.21.0", features = ["derive"] }
tokio-util = { version = "0.6.7", features = ["io"] }

View file

@ -293,7 +293,7 @@ alias(
alias(
name = "rusqlite",
actual = "@raze__rusqlite__0_24_2//:rusqlite",
actual = "@raze__rusqlite__0_25_3//:rusqlite",
tags = [
"cargo-raze",
"manual",

View file

@ -2,6 +2,7 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use rusqlite::{
params_from_iter,
types::{FromSql, FromSqlError, ToSql, ToSqlOutput, ValueRef},
OptionalExtension,
};
@ -132,7 +133,7 @@ pub(super) fn db_query_row(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) ->
let columns = stmt.column_count();
let row = stmt
.query_row(args, |row| {
.query_row(params_from_iter(args), |row| {
let mut orow = Vec::with_capacity(columns);
for i in 0..columns {
let v: SqlValue = row.get(i)?;
@ -156,7 +157,7 @@ pub(super) fn db_query(ctx: &SqliteStorage, sql: &str, args: &[SqlValue]) -> Res
let columns = stmt.column_count();
let res: std::result::Result<Vec<Vec<_>>, rusqlite::Error> = stmt
.query_map(args, |row| {
.query_map(params_from_iter(args), |row| {
let mut orow = Vec::with_capacity(columns);
for i in 0..columns {
let v: SqlValue = row.get(i)?;
@ -177,7 +178,7 @@ pub(super) fn db_execute_many(
let mut stmt = ctx.db.prepare_cached(sql)?;
for params in args {
stmt.execute(params)?;
stmt.execute(params_from_iter(params))?;
}
Ok(DbResult::None)

View file

@ -587,7 +587,7 @@ mod test {
col.storage
.db
.prepare("delete from decks where id != ? and id != 1")?
.execute(&[deck.id])?;
.execute([deck.id])?;
assert_eq!(col.storage.get_all_deck_names()?.len(), 2);
let out = col.check_database(progress_fn)?;

View file

@ -3,7 +3,7 @@
use std::{collections::HashMap, path::Path};
use rusqlite::{params, Connection, OptionalExtension, Row, Statement, NO_PARAMS};
use rusqlite::{params, Connection, OptionalExtension, Row, Statement};
use crate::error::Result;
@ -31,12 +31,12 @@ fn initial_db_setup(db: &mut Connection) -> Result<()> {
// tables already exist?
if db
.prepare("select null from sqlite_master where type = 'table' and name = 'media'")?
.exists(NO_PARAMS)?
.exists([])?
{
return Ok(());
}
db.execute("begin", NO_PARAMS)?;
db.execute("begin", [])?;
db.execute_batch(include_str!("schema.sql"))?;
db.execute_batch("commit; vacuum; analyze;")?;
@ -172,7 +172,7 @@ delete from media where fname=?"
pub(super) fn get_meta(&mut self) -> Result<MediaDatabaseMetadata> {
let mut stmt = self.db.prepare("select dirMod, lastUsn from meta")?;
stmt.query_row(NO_PARAMS, |row| {
stmt.query_row([], |row| {
Ok(MediaDatabaseMetadata {
folder_mtime: row.get(0)?,
last_sync_usn: row.get(1)?,
@ -192,7 +192,7 @@ delete from media where fname=?"
self.db
.query_row(
"select count(*) from media where csum is not null",
NO_PARAMS,
[],
|row| row.get(0),
)
.map_err(Into::into)
@ -204,7 +204,7 @@ delete from media where fname=?"
.prepare("select fname from media where dirty=1 limit ?")?;
let results: Result<Vec<_>> = stmt
.query_and_then(params![max_entries], |row| {
let fname = row.get_raw(0).as_str()?;
let fname = row.get_ref_unwrap(0).as_str()?;
Ok(self.get_entry(fname)?.unwrap())
})?
.collect();
@ -217,7 +217,7 @@ delete from media where fname=?"
.db
.prepare("select fname, mtime from media where csum is not null")?;
let map: std::result::Result<HashMap<String, i64>, rusqlite::Error> = stmt
.query_map(NO_PARAMS, |row| Ok((row.get(0)?, row.get(1)?)))?
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))?
.collect();
Ok(map?)
}

View file

@ -10,7 +10,7 @@ use std::borrow::Cow;
pub use parser::{
parse as parse_search, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind,
};
use rusqlite::types::FromSql;
use rusqlite::{params_from_iter, types::FromSql};
use sqlwriter::{RequiredTable, SqlWriter};
pub use writer::{concatenate_searches, replace_search_node, write_nodes, BoolSeparator};
@ -158,7 +158,7 @@ impl Collection {
let mut stmt = self.storage.db.prepare(&sql)?;
let ids: Vec<_> = stmt
.query_map(&args, |row| row.get(0))?
.query_map(params_from_iter(args.iter()), |row| row.get(0))?
.collect::<std::result::Result<_, _>>()?;
Ok(ids)
@ -210,7 +210,7 @@ impl Collection {
self.storage
.db
.prepare(&sql)?
.execute(&args)
.execute(params_from_iter(args))
.map_err(Into::into)
}
}

View file

@ -8,7 +8,7 @@ use std::{collections::HashSet, convert::TryFrom, result};
use rusqlite::{
named_params, params,
types::{FromSql, FromSqlError, ValueRef},
OptionalExtension, Row, NO_PARAMS,
OptionalExtension, Row,
};
use super::ids_to_string;
@ -160,7 +160,7 @@ impl super::SqliteStorage {
pub(crate) fn remove_card(&self, cid: CardId) -> Result<()> {
self.db
.prepare_cached("delete from cards where id = ?")?
.execute(&[cid])?;
.execute([cid])?;
Ok(())
}
@ -292,21 +292,21 @@ impl super::SqliteStorage {
pub(crate) fn delete_orphaned_cards(&self) -> Result<usize> {
self.db
.prepare("delete from cards where nid not in (select id from notes)")?
.execute(NO_PARAMS)
.execute([])
.map_err(Into::into)
}
pub(crate) fn all_filtered_cards_by_deck(&self) -> Result<Vec<(CardId, DeckId)>> {
self.db
.prepare("select id, did from cards where odid > 0")?
.query_and_then(NO_PARAMS, |r| -> Result<_> { Ok((r.get(0)?, r.get(1)?)) })?
.query_and_then([], |r| -> Result<_> { Ok((r.get(0)?, r.get(1)?)) })?
.collect()
}
pub(crate) fn max_new_card_position(&self) -> Result<u32> {
self.db
.prepare("select max(due)+1 from cards where type=0")?
.query_row(NO_PARAMS, |r| r.get(0))
.query_row([], |r| r.get(0))
.map_err(Into::into)
}
@ -324,14 +324,14 @@ impl super::SqliteStorage {
pub(crate) fn clear_pending_card_usns(&self) -> Result<()> {
self.db
.prepare("update cards set usn = 0 where usn = -1")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
pub(crate) fn have_at_least_one_card(&self) -> Result<bool> {
self.db
.prepare_cached("select null from cards")?
.query(NO_PARAMS)?
.query([])?
.next()
.map(|o| o.is_some())
.map_err(Into::into)
@ -340,7 +340,7 @@ impl super::SqliteStorage {
pub(crate) fn all_cards_of_note(&self, nid: NoteId) -> Result<Vec<Card>> {
self.db
.prepare_cached(concat!(include_str!("get_card.sql"), " where nid = ?"))?
.query_and_then(&[nid], |r| row_to_card(r).map_err(Into::into))?
.query_and_then([nid], |r| row_to_card(r).map_err(Into::into))?
.collect()
}
@ -355,7 +355,7 @@ impl super::SqliteStorage {
include_str!("get_card.sql"),
" where nid in (select nid from search_nids) and ord > ?"
))?
.query_and_then(&[ordinal as i64], |r| row_to_card(r).map_err(Into::into))?
.query_and_then([ordinal as i64], |r| row_to_card(r).map_err(Into::into))?
.collect()
}
@ -365,7 +365,7 @@ impl super::SqliteStorage {
) -> Result<Vec<CardId>> {
self.db
.prepare_cached("select id from cards where nid = ? order by ord")?
.query_and_then(&[nid], |r| Ok(CardId(r.get(0)?)))?
.query_and_then([nid], |r| Ok(CardId(r.get(0)?)))?
.collect()
}
@ -375,7 +375,7 @@ impl super::SqliteStorage {
.prepare_cached("select id from cards where nid = ?")?;
let mut cids = vec![];
for nid in nids {
for cid in stmt.query_map(&[nid], |row| row.get(0))? {
for cid in stmt.query_map([nid], |row| row.get(0))? {
cids.push(cid?);
}
}
@ -411,7 +411,7 @@ impl super::SqliteStorage {
let mut nids = HashSet::new();
for cid in cids {
if let Some(nid) = stmt
.query_row(&[cid], |r| r.get::<_, NoteId>(0))
.query_row([cid], |r| r.get::<_, NoteId>(0))
.optional()?
{
nids.insert(nid);
@ -426,7 +426,7 @@ impl super::SqliteStorage {
include_str!("get_card.sql"),
" where id in (select cid from search_cids)"
))?
.query_and_then(NO_PARAMS, |r| row_to_card(r).map_err(Into::into))?
.query_and_then([], |r| row_to_card(r).map_err(Into::into))?
.collect()
}
@ -436,7 +436,7 @@ impl super::SqliteStorage {
include_str!("get_card.sql"),
", search_cids where cards.id = search_cids.cid order by search_cids.rowid"
))?
.query_and_then(NO_PARAMS, |r| row_to_card(r).map_err(Into::into))?
.query_and_then([], |r| row_to_card(r).map_err(Into::into))?
.collect()
}
@ -449,7 +449,7 @@ impl super::SqliteStorage {
include_str!("get_card.sql"),
" where id in (select cid from search_cids)"
))?;
let mut rows = stmt.query(NO_PARAMS)?;
let mut rows = stmt.query([])?;
while let Some(row) = rows.next()? {
let card = row_to_card(row)?;
func(card)?
@ -464,7 +464,7 @@ impl super::SqliteStorage {
self.update_active_decks(current)?;
self.db
.prepare(include_str!("congrats.sql"))?
.query_and_then_named(
.query_and_then(
named_params! {
":review_queue": CardQueue::Review as i8,
":day_learn_queue": CardQueue::DayLearn as i8,
@ -493,7 +493,7 @@ impl super::SqliteStorage {
self.setup_searched_cards_table()?;
self.db
.prepare(include_str!("at_or_above_position.sql"))?
.execute(&[start, CardType::New as u32])?;
.execute([start, CardType::New as u32])?;
Ok(())
}
@ -510,8 +510,7 @@ impl super::SqliteStorage {
}
pub(crate) fn clear_searched_cards_table(&self) -> Result<()> {
self.db
.execute("drop table if exists search_cids", NO_PARAMS)?;
self.db.execute("drop table if exists search_cids", [])?;
Ok(())
}
@ -532,7 +531,7 @@ impl super::SqliteStorage {
.db
.prepare_cached("insert into search_cids values (?)")?;
for cid in cards {
stmt.execute(&[cid])?;
stmt.execute([cid])?;
}
Ok(())

View file

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use rusqlite::{params, NO_PARAMS};
use rusqlite::params;
use super::SqliteStorage;
use crate::{collection::timestamps::CollectionTimestamps, prelude::*};
@ -10,7 +10,7 @@ impl SqliteStorage {
pub(crate) fn get_collection_timestamps(&self) -> Result<CollectionTimestamps> {
self.db
.prepare_cached("select mod, scm, ls from col")?
.query_row(NO_PARAMS, |row| {
.query_row([], |row| {
Ok(CollectionTimestamps {
collection_change: row.get(0)?,
schema_change: row.get(1)?,
@ -23,14 +23,12 @@ impl SqliteStorage {
pub(crate) fn set_schema_modified_time(&self, stamp: TimestampMillis) -> Result<()> {
self.db
.prepare_cached("update col set scm = ?")?
.execute(&[stamp])?;
.execute([stamp])?;
Ok(())
}
pub(crate) fn set_last_sync(&self, stamp: TimestampMillis) -> Result<()> {
self.db
.prepare("update col set ls = ?")?
.execute(&[stamp])?;
self.db.prepare("update col set ls = ?")?.execute([stamp])?;
Ok(())
}
@ -46,14 +44,14 @@ impl SqliteStorage {
pub(crate) fn creation_stamp(&self) -> Result<TimestampSecs> {
self.db
.prepare_cached("select crt from col")?
.query_row(NO_PARAMS, |row| row.get(0))
.query_row([], |row| row.get(0))
.map_err(Into::into)
}
pub(crate) fn set_creation_stamp(&self, stamp: TimestampSecs) -> Result<()> {
self.db
.prepare("update col set crt = ?")?
.execute(&[stamp])?;
.execute([stamp])?;
Ok(())
}
}

View file

@ -3,7 +3,7 @@
use std::collections::HashMap;
use rusqlite::{params, NO_PARAMS};
use rusqlite::params;
use serde::de::DeserializeOwned;
use serde_json::Value;
@ -21,15 +21,15 @@ impl SqliteStorage {
pub(crate) fn remove_config(&self, key: &str) -> Result<()> {
self.db
.prepare_cached("delete from config where key=?")?
.execute(&[key])?;
.execute([key])?;
Ok(())
}
pub(crate) fn get_config_value<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(&[key], |row| {
let blob = row.get_raw(0).as_blob()?;
.query_and_then([key], |row| {
let blob = row.get_ref_unwrap(0).as_blob()?;
serde_json::from_slice(blob).map_err(Into::into)
})?
.next()
@ -40,7 +40,7 @@ impl SqliteStorage {
pub(crate) fn get_config_entry(&self, key: &str) -> Result<Option<Box<ConfigEntry>>> {
self.db
.prepare_cached(include_str!("get_entry.sql"))?
.query_and_then(&[key], |row| {
.query_and_then([key], |row| {
Ok(ConfigEntry::boxed(
key,
row.get(0)?,
@ -66,8 +66,8 @@ impl SqliteStorage {
pub(crate) fn get_all_config(&self) -> Result<HashMap<String, Value>> {
self.db
.prepare("select key, val from config")?
.query_and_then(NO_PARAMS, |row| {
let val: Value = serde_json::from_slice(row.get_raw(1).as_blob()?)?;
.query_and_then([], |row| {
let val: Value = serde_json::from_slice(row.get_ref_unwrap(1).as_blob()?)?;
Ok((row.get::<usize, String>(0)?, val))
})?
.collect()
@ -79,7 +79,7 @@ impl SqliteStorage {
usn: Usn,
mtime: TimestampSecs,
) -> Result<()> {
self.db.execute("delete from config", NO_PARAMS)?;
self.db.execute("delete from config", [])?;
for (key, val) in conf.iter() {
self.set_config_entry(&ConfigEntry::boxed(
key,
@ -94,7 +94,7 @@ impl SqliteStorage {
pub(crate) fn clear_config_usns(&self) -> Result<()> {
self.db
.prepare("update config set usn = 0 where usn != 0")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -103,9 +103,9 @@ impl SqliteStorage {
pub(super) fn upgrade_config_to_schema14(&self) -> Result<()> {
let conf = self
.db
.query_row_and_then("select conf from col", NO_PARAMS, |row| {
.query_row_and_then("select conf from col", [], |row| {
let conf: Result<HashMap<String, Value>> =
serde_json::from_str(row.get_raw(0).as_str()?).map_err(Into::into);
serde_json::from_str(row.get_ref_unwrap(0).as_str()?).map_err(Into::into);
conf
})?;
self.set_all_config(conf, Usn(0), TimestampSecs(0))?;
@ -117,7 +117,7 @@ impl SqliteStorage {
pub(super) fn downgrade_config_from_schema14(&self) -> Result<()> {
let allconf = self.get_all_config()?;
self.db
.execute("update col set conf=?", &[serde_json::to_string(&allconf)?])?;
.execute("update col set conf=?", [serde_json::to_string(&allconf)?])?;
Ok(())
}
}

View file

@ -7,7 +7,7 @@ use std::{
};
use prost::Message;
use rusqlite::{named_params, params, Row, NO_PARAMS};
use rusqlite::{named_params, params, Row};
use unicase::UniCase;
use super::SqliteStorage;
@ -20,12 +20,12 @@ use crate::{
};
fn row_to_deck(row: &Row) -> Result<Deck> {
let common = DeckCommon::decode(row.get_raw(4).as_blob()?)?;
let kind = DeckKindContainer::decode(row.get_raw(5).as_blob()?)?;
let common = DeckCommon::decode(row.get_ref_unwrap(4).as_blob()?)?;
let kind = DeckKindContainer::decode(row.get_ref_unwrap(5).as_blob()?)?;
let id = row.get(0)?;
Ok(Deck {
id,
name: NativeDeckName::from_native_str(row.get_raw(1).as_str()?),
name: NativeDeckName::from_native_str(row.get_ref_unwrap(1).as_str()?),
mtime_secs: row.get(2)?,
usn: row.get(3)?,
common,
@ -69,7 +69,7 @@ impl SqliteStorage {
pub(crate) fn get_deck(&self, did: DeckId) -> Result<Option<Deck>> {
self.db
.prepare_cached(concat!(include_str!("get_deck.sql"), " where id = ?"))?
.query_and_then(&[did], row_to_deck)?
.query_and_then([did], row_to_deck)?
.next()
.transpose()
}
@ -77,14 +77,14 @@ impl SqliteStorage {
pub(crate) fn get_all_decks(&self) -> Result<Vec<Deck>> {
self.db
.prepare(include_str!("get_deck.sql"))?
.query_and_then(NO_PARAMS, row_to_deck)?
.query_and_then([], row_to_deck)?
.collect()
}
pub(crate) fn get_decks_map(&self) -> Result<HashMap<DeckId, Deck>> {
self.db
.prepare(include_str!("get_deck.sql"))?
.query_and_then(NO_PARAMS, row_to_deck)?
.query_and_then([], row_to_deck)?
.map(|res| res.map(|d| (d.id, d)))
.collect()
}
@ -93,8 +93,11 @@ impl SqliteStorage {
pub(crate) fn get_all_deck_names(&self) -> Result<Vec<(DeckId, String)>> {
self.db
.prepare("select id, name from decks order by name")?
.query_and_then(NO_PARAMS, |row| {
Ok((row.get(0)?, row.get_raw(1).as_str()?.replace('\x1f', "::")))
.query_and_then([], |row| {
Ok((
row.get(0)?,
row.get_ref_unwrap(1).as_str()?.replace('\x1f', "::"),
))
})?
.collect()
}
@ -102,7 +105,7 @@ impl SqliteStorage {
pub(crate) fn get_deck_id(&self, machine_name: &str) -> Result<Option<DeckId>> {
self.db
.prepare("select id from decks where name = ?")?
.query_and_then(&[machine_name], |row| row.get(0))?
.query_and_then([machine_name], |row| row.get(0))?
.next()
.transpose()
.map_err(Into::into)
@ -114,7 +117,7 @@ impl SqliteStorage {
deck.id.0 = self
.db
.prepare(include_str!("alloc_id.sql"))?
.query_row(&[TimestampMillis::now()], |r| r.get(0))?;
.query_row([TimestampMillis::now()], |r| r.get(0))?;
self.add_or_update_deck_with_existing_id(deck)
.map_err(|err| {
// restore id of 0
@ -184,14 +187,14 @@ impl SqliteStorage {
pub(crate) fn remove_deck(&self, did: DeckId) -> Result<()> {
self.db
.prepare_cached("delete from decks where id = ?")?
.execute(&[did])?;
.execute([did])?;
Ok(())
}
pub(crate) fn all_cards_in_single_deck(&self, did: DeckId) -> Result<Vec<CardId>> {
self.db
.prepare_cached(include_str!("cards_for_deck.sql"))?
.query_and_then(&[did], |r| r.get(0).map_err(Into::into))?
.query_and_then([did], |r| r.get(0).map_err(Into::into))?
.collect()
}
@ -203,7 +206,7 @@ impl SqliteStorage {
include_str!("get_deck.sql"),
" where name >= ? and name < ?"
))?
.query_and_then(&[prefix_start, prefix_end], row_to_deck)?
.query_and_then([prefix_start, prefix_end], row_to_deck)?
.collect()
}
@ -229,7 +232,7 @@ impl SqliteStorage {
include_str!("get_deck.sql"),
" where name > ? and name < ?"
))?
.query_and_then(&[prefix_start, prefix_end], row_to_deck)?,
.query_and_then([prefix_start, prefix_end], row_to_deck)?,
)
.collect()
}
@ -303,7 +306,7 @@ impl SqliteStorage {
self.db
.prepare_cached(sql)?
.query_and_then_named(&params, |row| row_to_due_counts(row, v3))?
.query_and_then(&*params, |row| row_to_due_counts(row, v3))?
.collect()
}
@ -311,14 +314,14 @@ impl SqliteStorage {
pub(crate) fn missing_decks(&self) -> Result<Vec<DeckId>> {
self.db
.prepare(include_str!("missing-decks.sql"))?
.query_and_then(NO_PARAMS, |r| r.get(0).map_err(Into::into))?
.query_and_then([], |r| r.get(0).map_err(Into::into))?
.collect()
}
pub(crate) fn deck_is_empty(&self, did: DeckId) -> Result<bool> {
self.db
.prepare_cached("select null from cards where did=?")?
.query(&[did])?
.query([did])?
.next()
.map(|o| o.is_none())
.map_err(Into::into)
@ -327,7 +330,7 @@ impl SqliteStorage {
pub(crate) fn clear_deck_usns(&self) -> Result<()> {
self.db
.prepare("update decks set usn = 0 where usn != 0")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -344,7 +347,7 @@ impl SqliteStorage {
self.db
.prepare_cached(include_str!("update_active.sql"))?
.execute(&[top, prefix_start, prefix_end])?;
.execute([top, prefix_start, prefix_end])?;
Ok(())
}
@ -382,7 +385,7 @@ impl SqliteStorage {
}
self.add_or_update_deck_with_existing_id(&deck)?;
}
self.db.execute("update col set decks = ''", NO_PARAMS)?;
self.db.execute("update col set decks = ''", [])?;
Ok(())
}
@ -394,9 +397,9 @@ impl SqliteStorage {
fn get_schema11_decks(&self) -> Result<HashMap<DeckId, DeckSchema11>> {
let mut stmt = self.db.prepare("select decks from col")?;
let decks = stmt
.query_and_then(NO_PARAMS, |row| -> Result<HashMap<DeckId, DeckSchema11>> {
.query_and_then([], |row| -> Result<HashMap<DeckId, DeckSchema11>> {
let v: HashMap<DeckId, DeckSchema11> =
serde_json::from_str(row.get_raw(0).as_str()?)?;
serde_json::from_str(row.get_ref_unwrap(0).as_str()?)?;
Ok(v)
})?
.next()
@ -406,7 +409,7 @@ impl SqliteStorage {
pub(crate) fn set_schema11_decks(&self, decks: HashMap<DeckId, DeckSchema11>) -> Result<()> {
let json = serde_json::to_string(&decks)?;
self.db.execute("update col set decks = ?", &[json])?;
self.db.execute("update col set decks = ?", [json])?;
Ok(())
}
}

View file

@ -4,7 +4,7 @@
use std::collections::HashMap;
use prost::Message;
use rusqlite::{params, Row, NO_PARAMS};
use rusqlite::{params, Row};
use serde_json::Value;
use super::SqliteStorage;
@ -14,7 +14,7 @@ use crate::{
};
fn row_to_deckconf(row: &Row) -> Result<DeckConfig> {
let config = DeckConfigInner::decode(row.get_raw(4).as_blob()?)?;
let config = DeckConfigInner::decode(row.get_ref_unwrap(4).as_blob()?)?;
Ok(DeckConfig {
id: row.get(0)?,
name: row.get(1)?,
@ -28,14 +28,14 @@ impl SqliteStorage {
pub(crate) fn all_deck_config(&self) -> Result<Vec<DeckConfig>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(NO_PARAMS, row_to_deckconf)?
.query_and_then([], row_to_deckconf)?
.collect()
}
pub(crate) fn get_deck_config_map(&self) -> Result<HashMap<DeckConfigId, DeckConfig>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(NO_PARAMS, row_to_deckconf)?
.query_and_then([], row_to_deckconf)?
.map(|res| res.map(|d| (d.id, d)))
.collect()
}
@ -115,7 +115,7 @@ impl SqliteStorage {
pub(crate) fn clear_deck_conf_usns(&self) -> Result<()> {
self.db
.prepare("update deck_config set usn = 0 where usn != 0")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -150,8 +150,8 @@ impl SqliteStorage {
pub(super) fn upgrade_deck_conf_to_schema14(&self) -> Result<()> {
let conf: HashMap<DeckConfigId, DeckConfSchema11> =
self.db
.query_row_and_then("select dconf from col", NO_PARAMS, |row| -> Result<_> {
let text = row.get_raw(0).as_str()?;
.query_row_and_then("select dconf from col", [], |row| -> Result<_> {
let text = row.get_ref_unwrap(0).as_str()?;
// try direct parse
serde_json::from_str(text)
.or_else(|_| {
@ -177,8 +177,8 @@ impl SqliteStorage {
fn all_deck_config_schema14(&self) -> Result<Vec<DeckConfSchema11>> {
self.db
.prepare_cached("select config from deck_config")?
.query_and_then(NO_PARAMS, |row| -> Result<_> {
Ok(serde_json::from_slice(row.get_raw(0).as_blob()?)?)
.query_and_then([], |row| -> Result<_> {
Ok(serde_json::from_slice(row.get_ref_unwrap(0).as_blob()?)?)
})?
.collect()
}

View file

@ -4,7 +4,7 @@
use std::convert::TryFrom;
use num_enum::TryFromPrimitive;
use rusqlite::{params, NO_PARAMS};
use rusqlite::params;
use super::SqliteStorage;
use crate::{
@ -26,7 +26,7 @@ enum GraveKind {
impl SqliteStorage {
pub(crate) fn clear_all_graves(&self) -> Result<()> {
self.db.execute("delete from graves", NO_PARAMS)?;
self.db.execute("delete from graves", [])?;
Ok(())
}
@ -59,7 +59,7 @@ impl SqliteStorage {
"select oid, type from graves where {}",
pending_usn.pending_object_clause()
))?;
let mut rows = stmt.query(&[pending_usn])?;
let mut rows = stmt.query([pending_usn])?;
let mut graves = Graves::default();
while let Some(row) = rows.next()? {
let oid: i64 = row.get(0)?;
@ -77,7 +77,7 @@ impl SqliteStorage {
pub(crate) fn update_pending_grave_usns(&self, new_usn: Usn) -> Result<()> {
self.db
.prepare("update graves set usn=? where usn=-1")?
.execute(&[new_usn])?;
.execute([new_usn])?;
Ok(())
}

View file

@ -3,7 +3,7 @@
use std::collections::HashSet;
use rusqlite::{params, Row, NO_PARAMS};
use rusqlite::{params, Row};
use crate::{
error::Result,
@ -97,21 +97,21 @@ impl super::SqliteStorage {
pub(crate) fn remove_note(&self, nid: NoteId) -> Result<()> {
self.db
.prepare_cached("delete from notes where id = ?")?
.execute(&[nid])?;
.execute([nid])?;
Ok(())
}
pub(crate) fn note_is_orphaned(&self, nid: NoteId) -> Result<bool> {
self.db
.prepare_cached(include_str!("is_orphaned.sql"))?
.query_row(&[nid], |r| r.get(0))
.query_row([nid], |r| r.get(0))
.map_err(Into::into)
}
pub(crate) fn clear_pending_note_usns(&self) -> Result<()> {
self.db
.prepare("update notes set usn = 0 where usn = -1")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -119,7 +119,7 @@ impl super::SqliteStorage {
self.db
.query_row(
"select cast(flds as blob) from notes where id=?",
&[nid],
[nid],
|row| {
let fixed_flds: Vec<u8> = row.get(0)?;
let fixed_str = String::from_utf8_lossy(&fixed_flds);
@ -151,7 +151,7 @@ impl super::SqliteStorage {
pub(crate) fn total_notes(&self) -> Result<u32> {
self.db
.prepare("select count() from notes")?
.query_row(NO_PARAMS, |r| r.get(0))
.query_row([], |r| r.get(0))
.map_err(Into::into)
}
@ -159,10 +159,10 @@ impl super::SqliteStorage {
let mut stmt = self
.db
.prepare_cached("select tags from notes where tags != ''")?;
let mut query = stmt.query(NO_PARAMS)?;
let mut query = stmt.query([])?;
let mut seen: HashSet<String> = HashSet::new();
while let Some(rows) = query.next()? {
for tag in split_tags(rows.get_raw(0).as_str()?) {
for tag in split_tags(rows.get_ref_unwrap(0).as_str()?) {
if !seen.contains(tag) {
seen.insert(tag.to_string());
}
@ -174,7 +174,7 @@ impl super::SqliteStorage {
pub(crate) fn get_note_tags_by_id(&mut self, note_id: NoteId) -> Result<Option<NoteTags>> {
self.db
.prepare_cached(&format!("{} where id = ?", include_str!("get_tags.sql")))?
.query_and_then(&[note_id], row_to_note_tags)?
.query_and_then([note_id], row_to_note_tags)?
.next()
.transpose()
}
@ -190,7 +190,7 @@ impl super::SqliteStorage {
"{} where id in (select nid from search_nids)",
include_str!("get_tags.sql")
))?
.query_and_then(NO_PARAMS, row_to_note_tags)?
.query_and_then([], row_to_note_tags)?
.collect::<Result<Vec<_>>>()?;
self.clear_searched_notes_table()?;
Ok(out)
@ -201,10 +201,10 @@ impl super::SqliteStorage {
F: Fn(&str) -> bool,
{
let mut query_stmt = self.db.prepare_cached(include_str!("get_tags.sql"))?;
let mut rows = query_stmt.query(NO_PARAMS)?;
let mut rows = query_stmt.query([])?;
let mut output = vec![];
while let Some(row) = rows.next()? {
let tags = row.get_raw(3).as_str()?;
let tags = row.get_ref_unwrap(3).as_str()?;
if want(tags) {
output.push(row_to_note_tags(row)?)
}
@ -226,8 +226,7 @@ impl super::SqliteStorage {
}
pub(crate) fn clear_searched_notes_table(&self) -> Result<()> {
self.db
.execute("drop table if exists search_nids", NO_PARAMS)?;
self.db.execute("drop table if exists search_nids", [])?;
Ok(())
}
@ -241,7 +240,7 @@ impl super::SqliteStorage {
.db
.prepare_cached("insert into search_nids values (?)")?;
for nid in notes {
stmt.execute(&[nid])?;
stmt.execute([nid])?;
}
Ok(())
@ -255,10 +254,10 @@ fn row_to_note(row: &Row) -> Result<Note> {
row.get(2)?,
row.get(3)?,
row.get(4)?,
split_tags(row.get_raw(5).as_str()?)
split_tags(row.get_ref_unwrap(5).as_str()?)
.map(Into::into)
.collect(),
split_fields(row.get_raw(6).as_str()?),
split_fields(row.get_ref_unwrap(6).as_str()?),
Some(row.get(7)?),
Some(row.get(8).unwrap_or_default()),
))

View file

@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet};
use prost::Message;
use rusqlite::{params, OptionalExtension, Row, NO_PARAMS};
use rusqlite::{params, OptionalExtension, Row};
use unicase::UniCase;
use super::{ids_to_string, SqliteStorage};
@ -19,7 +19,7 @@ use crate::{
};
fn row_to_notetype_core(row: &Row) -> Result<Notetype> {
let config = NotetypeConfig::decode(row.get_raw(4).as_blob()?)?;
let config = NotetypeConfig::decode(row.get_ref_unwrap(4).as_blob()?)?;
Ok(Notetype {
id: row.get(0)?,
name: row.get(1)?,
@ -56,7 +56,7 @@ impl SqliteStorage {
fn get_notetype_core(&self, ntid: NotetypeId) -> Result<Option<Notetype>> {
self.db
.prepare_cached(concat!(include_str!("get_notetype.sql"), " where id = ?"))?
.query_and_then(&[ntid], row_to_notetype_core)?
.query_and_then([ntid], row_to_notetype_core)?
.next()
.transpose()
}
@ -64,8 +64,8 @@ impl SqliteStorage {
fn get_notetype_fields(&self, ntid: NotetypeId) -> Result<Vec<NoteField>> {
self.db
.prepare_cached(include_str!("get_fields.sql"))?
.query_and_then(&[ntid], |row| {
let config = NoteFieldConfig::decode(row.get_raw(2).as_blob()?)?;
.query_and_then([ntid], |row| {
let config = NoteFieldConfig::decode(row.get_ref_unwrap(2).as_blob()?)?;
Ok(NoteField {
ord: Some(row.get(0)?),
name: row.get(1)?,
@ -78,8 +78,8 @@ impl SqliteStorage {
fn get_notetype_templates(&self, ntid: NotetypeId) -> Result<Vec<CardTemplate>> {
self.db
.prepare_cached(include_str!("get_templates.sql"))?
.query_and_then(&[ntid], |row| {
let config = CardTemplateConfig::decode(row.get_raw(4).as_blob()?)?;
.query_and_then([ntid], |row| {
let config = CardTemplateConfig::decode(row.get_ref_unwrap(4).as_blob()?)?;
Ok(CardTemplate {
ord: row.get(0)?,
name: row.get(1)?,
@ -102,7 +102,7 @@ impl SqliteStorage {
pub fn get_all_notetype_names(&self) -> Result<Vec<(NotetypeId, String)>> {
self.db
.prepare_cached(include_str!("get_notetype_names.sql"))?
.query_and_then(NO_PARAMS, |row| Ok((row.get(0)?, row.get(1)?)))?
.query_and_then([], |row| Ok((row.get(0)?, row.get(1)?)))?
.collect()
}
@ -110,14 +110,14 @@ impl SqliteStorage {
pub fn get_notetype_use_counts(&self) -> Result<Vec<(NotetypeId, String, u32)>> {
self.db
.prepare_cached(include_str!("get_use_counts.sql"))?
.query_and_then(NO_PARAMS, |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))?
.query_and_then([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))?
.collect()
}
fn update_notetype_fields(&self, ntid: NotetypeId, fields: &[NoteField]) -> Result<()> {
self.db
.prepare_cached("delete from fields where ntid=?")?
.execute(&[ntid])?;
.execute([ntid])?;
let mut stmt = self.db.prepare_cached(include_str!("update_fields.sql"))?;
for (ord, field) in fields.iter().enumerate() {
let mut config_bytes = vec![];
@ -137,7 +137,7 @@ impl SqliteStorage {
sql += ") order by name";
self.db
.prepare(&sql)?
.query_and_then(NO_PARAMS, |r| r.get(0).map_err(Into::into))?
.query_and_then([], |r| r.get(0).map_err(Into::into))?
.collect()
}
@ -150,7 +150,7 @@ impl SqliteStorage {
sql += " order by mid, id";
self.db
.prepare(&sql)?
.query_and_then(NO_PARAMS, |r| Ok((r.get(0)?, r.get(1)?)))?
.query_and_then([], |r| Ok((r.get(0)?, r.get(1)?)))?
.collect()
}
@ -158,7 +158,7 @@ impl SqliteStorage {
let sql = String::from("select mid, id from notes order by mid, id");
self.db
.prepare(&sql)?
.query_and_then(NO_PARAMS, |r| Ok((r.get(0)?, r.get(1)?)))?
.query_and_then([], |r| Ok((r.get(0)?, r.get(1)?)))?
.collect()
}
@ -169,7 +169,7 @@ impl SqliteStorage {
) -> Result<()> {
self.db
.prepare_cached("delete from templates where ntid=?")?
.execute(&[ntid])?;
.execute([ntid])?;
let mut stmt = self
.db
.prepare_cached(include_str!("update_templates.sql"))?;
@ -237,13 +237,13 @@ impl SqliteStorage {
pub(crate) fn remove_notetype(&self, ntid: NotetypeId) -> Result<()> {
self.db
.prepare_cached("delete from templates where ntid=?")?
.execute(&[ntid])?;
.execute([ntid])?;
self.db
.prepare_cached("delete from fields where ntid=?")?
.execute(&[ntid])?;
.execute([ntid])?;
self.db
.prepare_cached("delete from notetypes where id=?")?
.execute(&[ntid])?;
.execute([ntid])?;
Ok(())
}
@ -257,7 +257,7 @@ impl SqliteStorage {
include_str!("existing_cards.sql"),
" where c.nid in (select id from notes where mid=?)"
))?
.query_and_then(&[ntid], row_to_existing_card)?
.query_and_then([ntid], row_to_existing_card)?
.collect()
}
@ -270,21 +270,21 @@ impl SqliteStorage {
include_str!("existing_cards.sql"),
" where c.nid = ?"
))?
.query_and_then(&[nid], row_to_existing_card)?
.query_and_then([nid], row_to_existing_card)?
.collect()
}
pub(crate) fn clear_notetype_usns(&self) -> Result<()> {
self.db
.prepare("update notetypes set usn = 0 where usn != 0")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
pub(crate) fn highest_card_ordinal_for_notetype(&self, ntid: NotetypeId) -> Result<u16> {
self.db
.prepare(include_str!("highest_card_ord.sql"))?
.query_row(&[ntid], |row| row.get(0))
.query_row([ntid], |row| row.get(0))
.map_err(Into::into)
}
@ -327,7 +327,7 @@ impl SqliteStorage {
self.update_notetype_fields(ntid, &nt.fields)?;
self.update_notetype_templates(ntid, &nt.templates)?;
}
self.db.execute("update col set models = ''", NO_PARAMS)?;
self.db.execute("update col set models = ''", [])?;
Ok(())
}
@ -339,14 +339,11 @@ impl SqliteStorage {
fn get_schema11_notetypes(&self) -> Result<HashMap<NotetypeId, NotetypeSchema11>> {
let mut stmt = self.db.prepare("select models from col")?;
let notetypes = stmt
.query_and_then(
NO_PARAMS,
|row| -> Result<HashMap<NotetypeId, NotetypeSchema11>> {
let v: HashMap<NotetypeId, NotetypeSchema11> =
serde_json::from_str(row.get_raw(0).as_str()?)?;
Ok(v)
},
)?
.query_and_then([], |row| -> Result<HashMap<NotetypeId, NotetypeSchema11>> {
let v: HashMap<NotetypeId, NotetypeSchema11> =
serde_json::from_str(row.get_ref_unwrap(0).as_str()?)?;
Ok(v)
})?
.next()
.ok_or_else(|| AnkiError::db_error("col table empty", DbErrorKind::MissingEntity))??;
Ok(notetypes)
@ -357,7 +354,7 @@ impl SqliteStorage {
notetypes: HashMap<NotetypeId, NotetypeSchema11>,
) -> Result<()> {
let json = serde_json::to_string(&notetypes)?;
self.db.execute("update col set models = ?", &[json])?;
self.db.execute("update col set models = ?", [json])?;
Ok(())
}
}

View file

@ -6,7 +6,7 @@ use std::convert::TryFrom;
use rusqlite::{
params,
types::{FromSql, FromSqlError, ValueRef},
Row, NO_PARAMS,
Row,
};
use super::SqliteStorage;
@ -50,14 +50,14 @@ impl SqliteStorage {
pub(crate) fn fix_revlog_properties(&self) -> Result<usize> {
self.db
.prepare(include_str!("fix_props.sql"))?
.execute(NO_PARAMS)
.execute([])
.map_err(Into::into)
}
pub(crate) fn clear_pending_revlog_usns(&self) -> Result<()> {
self.db
.prepare("update revlog set usn = 0 where usn = -1")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -87,7 +87,7 @@ impl SqliteStorage {
pub(crate) fn get_revlog_entry(&self, id: RevlogId) -> Result<Option<RevlogEntry>> {
self.db
.prepare_cached(concat!(include_str!("get.sql"), " where id=?"))?
.query_and_then(&[id], row_to_revlog_entry)?
.query_and_then([id], row_to_revlog_entry)?
.next()
.transpose()
}
@ -96,14 +96,14 @@ impl SqliteStorage {
pub(crate) fn remove_revlog_entry(&self, id: RevlogId) -> Result<()> {
self.db
.prepare_cached("delete from revlog where id = ?")?
.execute(&[id])?;
.execute([id])?;
Ok(())
}
pub(crate) fn get_revlog_entries_for_card(&self, cid: CardId) -> Result<Vec<RevlogEntry>> {
self.db
.prepare_cached(concat!(include_str!("get.sql"), " where cid=?"))?
.query_and_then(&[cid], row_to_revlog_entry)?
.query_and_then([cid], row_to_revlog_entry)?
.collect()
}
@ -116,9 +116,7 @@ impl SqliteStorage {
include_str!("get.sql"),
" where cid in (select cid from search_cids) and id >= ?"
))?
.query_and_then(&[after.0 * 1000], |r| {
row_to_revlog_entry(r).map(Into::into)
})?
.query_and_then([after.0 * 1000], |r| row_to_revlog_entry(r).map(Into::into))?
.collect()
}
@ -129,9 +127,7 @@ impl SqliteStorage {
) -> Result<Vec<pb::RevlogEntry>> {
self.db
.prepare_cached(concat!(include_str!("get.sql"), " where id >= ?"))?
.query_and_then(&[after.0 * 1000], |r| {
row_to_revlog_entry(r).map(Into::into)
})?
.query_and_then([after.0 * 1000], |r| row_to_revlog_entry(r).map(Into::into))?
.collect()
}
@ -139,7 +135,7 @@ impl SqliteStorage {
let start = day_cutoff.adding_secs(-86_400).as_millis();
self.db
.prepare_cached(include_str!("studied_today.sql"))?
.query_map(&[start.0, RevlogReviewKind::Manual as i64], |row| {
.query_map([start.0, RevlogReviewKind::Manual as i64], |row| {
Ok(StudiedToday {
cards: row.get(0)?,
seconds: row.get(1)?,

View file

@ -5,7 +5,7 @@ use std::{borrow::Cow, cmp::Ordering, hash::Hasher, path::Path, sync::Arc};
use fnv::FnvHasher;
use regex::Regex;
use rusqlite::{functions::FunctionFlags, params, Connection, NO_PARAMS};
use rusqlite::{functions::FunctionFlags, params, Connection};
use unicase::UniCase;
use super::upgrades::{SCHEMA_MAX_VERSION, SCHEMA_MIN_VERSION, SCHEMA_STARTING_VERSION};
@ -135,16 +135,14 @@ fn add_regexp_function(db: &Connection) -> rusqlite::Result<()> {
fn schema_version(db: &Connection) -> Result<(bool, u8)> {
if !db
.prepare("select null from sqlite_master where type = 'table' and name = 'col'")?
.exists(NO_PARAMS)?
.exists([])?
{
return Ok((true, SCHEMA_STARTING_VERSION));
}
Ok((
false,
db.query_row("select ver from col", NO_PARAMS, |r| {
r.get(0).map_err(Into::into)
})?,
db.query_row("select ver from col", [], |r| r.get(0).map_err(Into::into))?,
))
}
@ -173,7 +171,7 @@ impl SqliteStorage {
let upgrade = ver != SCHEMA_MAX_VERSION;
if create || upgrade {
db.execute("begin exclusive", NO_PARAMS)?;
db.execute("begin exclusive", [])?;
}
if create {
@ -227,22 +225,20 @@ impl SqliteStorage {
//////////////////////////////////////
pub(crate) fn begin_trx(&self) -> Result<()> {
self.db
.prepare_cached("begin exclusive")?
.execute(NO_PARAMS)?;
self.db.prepare_cached("begin exclusive")?.execute([])?;
Ok(())
}
pub(crate) fn commit_trx(&self) -> Result<()> {
if !self.db.is_autocommit() {
self.db.prepare_cached("commit")?.execute(NO_PARAMS)?;
self.db.prepare_cached("commit")?.execute([])?;
}
Ok(())
}
pub(crate) fn rollback_trx(&self) -> Result<()> {
if !self.db.is_autocommit() {
self.db.execute("rollback", NO_PARAMS)?;
self.db.execute("rollback", [])?;
}
Ok(())
}
@ -256,21 +252,17 @@ impl SqliteStorage {
// transition these to standard commits.
pub(crate) fn begin_rust_trx(&self) -> Result<()> {
self.db
.prepare_cached("savepoint rust")?
.execute(NO_PARAMS)?;
self.db.prepare_cached("savepoint rust")?.execute([])?;
Ok(())
}
pub(crate) fn commit_rust_trx(&self) -> Result<()> {
self.db.prepare_cached("release rust")?.execute(NO_PARAMS)?;
self.db.prepare_cached("release rust")?.execute([])?;
Ok(())
}
pub(crate) fn rollback_rust_trx(&self) -> Result<()> {
self.db
.prepare_cached("rollback to rust")?
.execute(NO_PARAMS)?;
self.db.prepare_cached("rollback to rust")?.execute([])?;
Ok(())
}
@ -296,8 +288,6 @@ impl SqliteStorage {
#[cfg(test)]
pub(crate) fn db_scalar<T: rusqlite::types::FromSql>(&self, sql: &str) -> Result<T> {
self.db
.query_row(sql, NO_PARAMS, |r| r.get(0))
.map_err(Into::into)
self.db.query_row(sql, [], |r| r.get(0)).map_err(Into::into)
}
}

View file

@ -3,7 +3,7 @@
use std::path::Path;
use rusqlite::{params, types::FromSql, Connection, ToSql, NO_PARAMS};
use rusqlite::{params, types::FromSql, Connection, ToSql};
use super::*;
use crate::prelude::*;
@ -14,7 +14,7 @@ impl SqliteStorage {
Ok(Usn(self
.db
.prepare_cached("select usn from col")?
.query_row(NO_PARAMS, |row| row.get(0))?))
.query_row([], |row| row.get(0))?))
} else {
Ok(Usn(-1))
}
@ -23,14 +23,14 @@ impl SqliteStorage {
pub(crate) fn set_usn(&self, usn: Usn) -> Result<()> {
self.db
.prepare_cached("update col set usn = ?")?
.execute(&[usn])?;
.execute([usn])?;
Ok(())
}
pub(crate) fn increment_usn(&self) -> Result<()> {
self.db
.prepare_cached("update col set usn = usn + 1")?
.execute(NO_PARAMS)?;
.execute([])?;
Ok(())
}
@ -41,7 +41,7 @@ impl SqliteStorage {
table,
usn.pending_object_clause()
))?
.query_and_then(&[usn], |r| r.get(0).map_err(Into::into))?
.query_and_then([usn], |r| r.get(0).map_err(Into::into))?
.collect()
}

View file

@ -1,8 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use rusqlite::NO_PARAMS;
use super::*;
use crate::{
error::SyncErrorKind,
@ -15,16 +13,14 @@ impl SqliteStorage {
Ok(self
.db
.prepare(&format!("select null from {} where usn=-1", table))?
.query(NO_PARAMS)?
.query([])?
.next()?
.is_some())
}
fn table_count(&self, table: &str) -> Result<u32> {
self.db
.query_row(&format!("select count() from {}", table), NO_PARAMS, |r| {
r.get(0)
})
.query_row(&format!("select count() from {}", table), [], |r| r.get(0))
.map_err(Into::into)
}

View file

@ -3,7 +3,7 @@
use std::collections::HashMap;
use rusqlite::{params, Row, NO_PARAMS};
use rusqlite::{params, Row};
use super::SqliteStorage;
use crate::{error::Result, tags::Tag, types::Usn};
@ -21,14 +21,14 @@ impl SqliteStorage {
pub(crate) fn all_tags(&self) -> Result<Vec<Tag>> {
self.db
.prepare_cached(include_str!("get.sql"))?
.query_and_then(NO_PARAMS, row_to_tag)?
.query_and_then([], row_to_tag)?
.collect()
}
pub(crate) fn expanded_tags(&self) -> Result<Vec<String>> {
self.db
.prepare_cached("select tag from tags where collapsed = false")?
.query_and_then(NO_PARAMS, |r| r.get::<_, String>(0).map_err(Into::into))?
.query_and_then([], |r| r.get::<_, String>(0).map_err(Into::into))?
.collect::<Result<Vec<_>>>()
}
@ -37,7 +37,7 @@ impl SqliteStorage {
.db
.prepare_cached("update tags set collapsed = false where tag = ?")?;
for tag in tags {
stmt.execute(&[tag])?;
stmt.execute([tag])?;
}
Ok(())
}
@ -45,7 +45,7 @@ impl SqliteStorage {
pub(crate) fn get_tag(&self, name: &str) -> Result<Option<Tag>> {
self.db
.prepare_cached(&format!("{} where tag = ?", include_str!("get.sql")))?
.query_and_then(&[name], row_to_tag)?
.query_and_then([name], row_to_tag)?
.next()
.transpose()
}
@ -71,10 +71,10 @@ impl SqliteStorage {
F: Fn(&str) -> bool,
{
let mut query_stmt = self.db.prepare_cached(include_str!("get.sql"))?;
let mut rows = query_stmt.query(NO_PARAMS)?;
let mut rows = query_stmt.query([])?;
let mut output = vec![];
while let Some(row) = rows.next()? {
let tag = row.get_raw(0).as_str()?;
let tag = row.get_ref_unwrap(0).as_str()?;
if want(tag) {
output.push(Tag {
name: tag.to_owned(),
@ -89,7 +89,7 @@ impl SqliteStorage {
pub(crate) fn remove_single_tag(&self, tag: &str) -> Result<()> {
self.db
.prepare_cached("delete from tags where tag = ?")?
.execute(&[tag])?;
.execute([tag])?;
Ok(())
}
@ -102,13 +102,13 @@ impl SqliteStorage {
}
pub(crate) fn clear_all_tags(&self) -> Result<()> {
self.db.execute("delete from tags", NO_PARAMS)?;
self.db.execute("delete from tags", [])?;
Ok(())
}
pub(crate) fn clear_tag_usns(&self) -> Result<()> {
self.db
.execute("update tags set usn = 0 where usn != 0", NO_PARAMS)?;
.execute("update tags set usn = 0 where usn != 0", [])?;
Ok(())
}
@ -120,7 +120,7 @@ impl SqliteStorage {
"select tag from tags where {}",
usn.pending_object_clause()
))?
.query_and_then(&[usn], |r| r.get(0).map_err(Into::into))?
.query_and_then([usn], |r| r.get(0).map_err(Into::into))?
.collect()
}
@ -139,9 +139,9 @@ impl SqliteStorage {
pub(super) fn upgrade_tags_to_schema14(&self) -> Result<()> {
let tags = self
.db
.query_row_and_then("select tags from col", NO_PARAMS, |row| {
.query_row_and_then("select tags from col", [], |row| {
let tags: Result<HashMap<String, Usn>> =
serde_json::from_str(row.get_raw(0).as_str()?).map_err(Into::into);
serde_json::from_str(row.get_ref_unwrap(0).as_str()?).map_err(Into::into);
tags
})?;
let mut stmt = self
@ -169,7 +169,7 @@ impl SqliteStorage {
let tags = self
.db
.prepare_cached("select tag, usn from tags")?
.query_and_then(NO_PARAMS, |r| Ok(Tag::new(r.get(0)?, r.get(1)?)))?
.query_and_then([], |r| Ok(Tag::new(r.get(0)?, r.get(1)?)))?
.collect::<Result<Vec<Tag>>>()?;
self.db
.execute_batch(include_str!["../upgrades/schema17_upgrade.sql"])?;