kawasin73 / prsqlite

Pure Rust implementation of SQLite
Apache License 2.0
563 stars 23 forks source link

Support reusing statement #29

Closed kawasin73 closed 1 year ago

kawasin73 commented 1 year ago

This integration test for INSERT fails

#[test]
fn test_insert_reuse_statement() {
    let file = create_sqlite_database(&["CREATE TABLE example(col);"]);
    let mut conn = Connection::open(file.path()).unwrap();

    let mut stmt = conn
        .prepare("INSERT INTO example (col) VALUES (123);")
        .unwrap();
    assert_eq!(stmt.execute().unwrap(), 1);
    assert_eq!(stmt.execute().unwrap(), 1);

    let mut stmt = conn
        .prepare("INSERT INTO example (col) VALUES (456), (789);")
        .unwrap();
    assert_eq!(stmt.execute().unwrap(), 2);
    assert_eq!(stmt.execute().unwrap(), 2);

    let test_conn = rusqlite::Connection::open(file.path()).unwrap();
    assert_same_results(
        &[
            &[Value::Integer(123)],
            &[Value::Integer(123)],
            &[Value::Integer(123)],
            &[Value::Integer(456)],
            &[Value::Integer(789)],
            &[Value::Integer(456)],
            &[Value::Integer(789)],
        ],
        "SELECT * FROM example;",
        &test_conn,
        &mut conn,
    )
}
kawasin73@kawasin73-pro-2284 ~/s/g/k/prsqlite (insert)> cargo test
   Compiling prsqlite v0.1.0 (/Users/kawasin73/src/github.com/kawasin73/prsqlite)
error[E0499]: cannot borrow `stmt` as mutable more than once at a time
   --> tests/insert.rs:189:16
    |
188 |     assert_eq!(stmt.execute().unwrap(), 1);
    |                -------------- first mutable borrow occurs here
189 |     assert_eq!(stmt.execute().unwrap(), 1);
    |                ^^^^^^^^^^^^^^
    |                |
    |                second mutable borrow occurs here
    |                first borrow later used here

error[E0499]: cannot borrow `stmt` as mutable more than once at a time
   --> tests/insert.rs:195:16
    |
194 |     assert_eq!(stmt.execute().unwrap(), 2);
    |                -------------- first mutable borrow occurs here
195 |     assert_eq!(stmt.execute().unwrap(), 2);
    |                ^^^^^^^^^^^^^^
    |                |
    |                second mutable borrow occurs here
    |                first borrow later used here

For more information about this error, try `rustc --explain E0499`.
error: could not compile `prsqlite` (test "insert") due to 2 previous errors
kawasin73 commented 1 year ago

Resolved by these commits.