我在 rusqlite 中阅读了以下内容文档:
Connection::open(path)
is equivalent toConnection::open_with_flags(path, SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE)
.
我将其复制到以下简单代码中:
extern crate rusqlite;
use rusqlite::Connection;
fn main() {
let path = "/usr/local/data/mydb.sqlite";
let conn = Connection::open_with_flags(path, SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE);
}
我实际上想用 SQLITE_OPEN_READ_ONLY
替换这些标志,但认为这是一个很好的起点。
我收到以下错误:
error[E0425]: cannot find value `SQLITE_OPEN_READ_WRITE` in this scope
--> src/main.rs:6:50
|
6 | let conn = Connection::open_with_flags(path, SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE);
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find value `SQLITE_OPEN_CREATE` in this scope
--> src/main.rs:6:75
|
6 | let conn = Connection::open_with_flags(path, SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE);
| ^^^^^^^^^^^^^^^^^^ not found in this scope
似乎我缺少类似 use rusqlite::Something;
的东西,但那是什么东西?我想不通。
我的 Cargo.toml
[dependencies.rusqlite]
version = "0.13.0"
features = ["bundled"]
最佳答案
is equivalent to
Connection::open_with_flags
你应该看看 open_with_flags
documentation :
fn open_with_flags<P: AsRef<Path>>(
path: P,
flags: OpenFlags
) -> Result<Connection>
然后点击进入 OpenFlags
.这定义了 your flag作为关联常量:
const SQLITE_OPEN_READ_ONLY: OpenFlags
一起:
extern crate rusqlite;
use rusqlite::{Connection, OpenFlags};
fn main() {
let path = "/usr/local/data/mydb.sqlite";
let conn = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_ONLY);
}
关于sqlite - 如何使用 rusqlite crate 打开带有标志的连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48829416/