Skip to content

Commit 5ca3074

Browse files
committed
dict: fix building with rusqlite 0.38.0
1 parent 51fb091 commit 5ca3074

File tree

2 files changed

+128
-25
lines changed

2 files changed

+128
-25
lines changed

Cargo.lock

Lines changed: 119 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dictionary/sqlite.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl SqliteDictionary {
198198
return Ok(());
199199
}
200200

201-
let mut userphrases: Vec<(Vec<Syllable>, String, u32, u32, u64)> = vec![];
201+
let mut userphrases: Vec<(Vec<Syllable>, String, u32, u32, i64)> = vec![];
202202
{
203203
let mut stmt = conn.prepare(
204204
"SELECT
@@ -327,10 +327,10 @@ impl Dictionary for SqliteDictionary {
327327
)
328328
.expect("SQL error");
329329
stmt.query_map([syllables_bytes], |row| {
330-
let (phrase, freq, time): (Box<str>, _, _) = row.try_into()?;
330+
let (phrase, freq, time): (Box<str>, _, Option<i64>) = row.try_into()?;
331331
let mut phrase = Phrase::new(phrase, freq);
332332
if let Some(last_used) = time {
333-
phrase = phrase.with_time(last_used);
333+
phrase = phrase.with_time(last_used as u64);
334334
}
335335
Ok(phrase)
336336
})
@@ -350,7 +350,7 @@ impl Dictionary for SqliteDictionary {
350350
.expect("SQL error");
351351
Box::new(
352352
stmt.query_map([], |row| {
353-
let (syllables_bytes, phrase, freq, time): (Vec<u8>, Box<str>, _, _) =
353+
let (syllables_bytes, phrase, freq, time): (Vec<u8>, Box<str>, _, Option<i64>) =
354354
row.try_into()?;
355355
let syllables = syllables_bytes
356356
.chunks_exact(2)
@@ -363,7 +363,7 @@ impl Dictionary for SqliteDictionary {
363363
.collect::<Vec<_>>();
364364
let mut phrase = Phrase::new(phrase, freq);
365365
if let Some(last_used) = time {
366-
phrase = phrase.with_time(last_used);
366+
phrase = phrase.with_time(last_used as u64);
367367
}
368368
Ok((syllables, phrase))
369369
})
@@ -425,6 +425,8 @@ impl Dictionary for SqliteDictionary {
425425
user_freq: u32,
426426
time: u64,
427427
) -> Result<(), UpdateDictionaryError> {
428+
// sqlite only supports i64
429+
let time: i64 = time.clamp(0, i64::MAX as u64) as i64;
428430
if self.readonly {
429431
return Err(UpdateDictionaryError {
430432
source: Some(Box::new(SqliteDictionaryError::ReadOnly)),
@@ -436,7 +438,7 @@ impl Dictionary for SqliteDictionary {
436438
let mut stmt = tx.prepare_cached(
437439
"SELECT userphrase_id FROM dictionary_v1 WHERE syllables = ? AND phrase = ?",
438440
)?;
439-
let userphrase_id: Option<Option<u64>> = stmt
441+
let userphrase_id: Option<Option<i64>> = stmt
440442
.query_row(params![syllables_bytes, phrase.as_str()], |row| row.get(0))
441443
.optional()?;
442444
match userphrase_id {
@@ -490,7 +492,7 @@ impl Dictionary for SqliteDictionary {
490492
#[derive(Debug)]
491493
pub struct SqliteDictionaryBuilder {
492494
dict: SqliteDictionary,
493-
sort_id: u64,
495+
sort_id: i64,
494496
}
495497

496498
impl SqliteDictionaryBuilder {

0 commit comments

Comments
 (0)