首页 > 解决方案 > 如何通过 Vec> 在 rusqlite 作为查询参数

问题描述

我正在关注来自 rusqlite git hub https://github.com/rusqlite/rusqlite/blob/master/src/vtab/array.rs#L206的示例。我有完全相同的代码,但我得到了编译错误

the trait bound `std::vec::Vec<rusqlite::types::Value>: rusqlite::ToSql` is not satisfied

代码片段如下。ids 是字符串的 Vec

let intValues:Vec<i64> = ids.into_iter().map(|s| s.parse::<i64>().expect("Id Parse error.")).collect();
let values:Vec<rusqlite::types::Value> = intValues.into_iter().map(rusqlite::types::Value::from).collect();
let ptr = std::rc::Rc::new(values);
let mut statement = db_connection
    .prepare("select * from item where id in rarray(?);")
    .expect("Failed to prepare second query.");
let results = statement

// This is the error line
    .query_map(&[&ptr], |row| {
        Ok(database::ItemData {
            id: row.get(0)?,
            name: row.get(1)?,
            time_to_prepare: row.get(2)?
        })
    });

标签: rustrusqlite

解决方案


我必须在 toml 文件的功能中添加“数组”。


推荐阅读