百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
返回工具页/返回 Issues 列表
#2244·libsql

在一个查询中多个语句没有错误

作者: CharaVerKys创建于 2026年5月28日更新于 2026年5月28日
rust
--------------charaverk | ~/repos/libsql_execute/src ~$ cat ../Cargo.toml
[package]
name = "libsql_execute"
version = "0.1.0"
edition = "2024"

[dependencies]
libsql = { version = "0.9.30", default-features = false, features = ["core"] }
tokio = { version = "1.52.*", features = ["full"] }

------------charaverk | ~/repos/libsql_execute/src ~$ cat main.rs
fn main() {
    let runtime = tokio::runtime::Runtime::new().unwrap();
    runtime.block_on(async{
        let db = libsql::Builder::new_local("/tmp/test.db").build().await.unwrap();
        let conn = db.connect().unwrap();
        //? works as expected
        conn.execute("CREATE TABLE IF NOT EXISTS test_table(id INTEGER PRIMARY KEY, data INTEGER)", ()).await.unwrap();

        //? this return ok, but should return error
        let res = conn.execute(
            "INSERT OR IGNORE INTO test_table(id, data) VALUES(?1, 0);
             UPDATE test_table SET data = data + 1 WHERE id == ?1;
            ", [ 1 ]).await;
        assert!(res.is_ok(), "not ok on two statements");
        assert!(res.unwrap() == 1, "affected not_eq 1 lines");

        //? and value here is 0; but expect 1 since last statement not returned error
        let mut res = conn.query(
            "SELECT data FROM test_table WHERE id == ?1;
            ", [ 1 ]).await.unwrap();
        let data = res.next().await.unwrap().unwrap().get_value(0).unwrap().as_integer().unwrap().clone();
        assert_eq!(data, 1); //* panic
    });
}
expected behavior: error about multiple statements in query
*rustsql do this*

内容来源: tursodatabase/libsql

查看 GitHub 原文在 GitHub 查看讨论