Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite hile循环将只分配一次。否则,如果数据库的行为不符合预期,这将导致错误。“为了减少过度使用,我尝试不对当前程序使用OOP。”-用一种开销换另一种开销更接近事实。@SébastienRenauld我知道婴儿对程序的调用将少于OOP所需的内存总量。这个程序只_Sqlite_Rust - Fatal编程技术网

Sqlite hile循环将只分配一次。否则,如果数据库的行为不符合预期,这将导致错误。“为了减少过度使用,我尝试不对当前程序使用OOP。”-用一种开销换另一种开销更接近事实。@SébastienRenauld我知道婴儿对程序的调用将少于OOP所需的内存总量。这个程序只

Sqlite hile循环将只分配一次。否则,如果数据库的行为不符合预期,这将导致错误。“为了减少过度使用,我尝试不对当前程序使用OOP。”-用一种开销换另一种开销更接近事实。@SébastienRenauld我知道婴儿对程序的调用将少于OOP所需的内存总量。这个程序只,sqlite,rust,Sqlite,Rust,hile循环将只分配一次。否则,如果数据库的行为不符合预期,这将导致错误。“为了减少过度使用,我尝试不对当前程序使用OOP。”-用一种开销换另一种开销更接近事实。@SébastienRenauld我知道婴儿对程序的调用将少于OOP所需的内存总量。这个程序只是一个启动器。它不需要保持OOP,因为进程只是作为启动器的一个副作用挂起。同样对于这个应用程序,我希望在断电时将数据写入磁盘。它不是那种节目,具体时间是琐碎的。 error[E0599]: no method named `query` fou


hile循环将只分配一次。否则,如果数据库的行为不符合预期,这将导致错误。

“为了减少过度使用,我尝试不对当前程序使用OOP。”-用一种开销换另一种开销更接近事实。@SébastienRenauld我知道婴儿对程序的调用将少于OOP所需的内存总量。这个程序只是一个启动器。它不需要保持OOP,因为进程只是作为启动器的一个副作用挂起。同样对于这个应用程序,我希望在断电时将数据写入磁盘。它不是那种节目,具体时间是琐碎的。
error[E0599]: no method named `query` found for type `std::result::Result<usize, rusqlite::Error>` in the current scope
  --> src/main.rs:91:100
   |
91 |         let id = db.execute("SELECT id FROM short_names WHERE short_name = '?1';",params![&short]).query(NO_PARAMS).expect("get record id fail");
   |                                                                                                    ^^^^^

error[E0369]: binary operation `+` cannot be applied to type `&str`
  --> src/main.rs:94:83
   |
94 |         let receiver = db.prepare("SELECT id FROM short_names WHERE short_name = "+short+";").expect("");
   |                                   ------------------------------------------------^----- std::string::String
   |                                   |                                               |
   |                                   |                                               `+` cannot be used to concatenate a `&str` with a `String`
   |                                   &str
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
   |
94 |         let receiver = db.prepare("SELECT id FROM short_names WHERE short_name = ".to_owned()+&short+";").expect("");
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^

error[E0277]: `rusqlite::Rows<'_>` doesn't implement `std::fmt::Debug`
  --> src/main.rs:96:25
   |
96 |         println!("{:?}",id);
   |                         ^^ `rusqlite::Rows<'_>` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `rusqlite::Rows<'_>`
   = note: required by `std::fmt::Debug::fmt`
use rusqlite::{Connection};

pub struct ShortName {
    pub id: i64,
    pub name: String
}

pub fn insert_shortname(db: &Connection, name: &str) -> Result<ShortName, rusqlite::Error> {
    let mut rtn = ShortName {
        id: 0,
        name: name.to_string()
    };
    db.execute("insert into short_names (short_name) values (?)",&[name])?;
    rtn.id = db.last_insert_rowid();
    Ok(rtn)
}
#[test]
fn it_works() {
    let conn = Connection::open_in_memory().expect("Could not test: DB not created");
    let input:Vec<bool> = vec![];
    conn.execute("CREATE TABLE short_names (id INTEGER PRIMARY KEY AUTOINCREMENT, short_name TEXT NOT NULL)", input).expect("Creation failure");
    let output = insert_shortname(&conn, "Fred").expect("Insert failure");
    assert_eq!(output.id, 1);
}