Skip to content

SQLITE ATTACH db command fails with sqlite::memory: URI #832

@mikechambers

Description

@mikechambers

Looking at the docs at:
https://docs.rs/sqlx/0.4.0-beta.1/sqlx/sqlite/struct.SqliteConnectOptions.html

The docs specify to use "sqlite::memory:" to create an in-memory database. When using this syntax, doing an ATTACH command silently fails.

    let mut db = match SqliteConnection::connect("sqlite::memory:").await {
        Ok(e) => e,
        Err(e) => panic!("{:?}", e),
    };

    let q = match sqlx::query("ATTACH DATABASE '/Users/mesh/tmp/manifest.sqlite3' as 'tmpDb'").execute(&mut db).await {
        Ok(e) => e,
        Err(e) => panic!("FAIL: {:?}", e),
    };

    let q = match sqlx::query("CREATE TABLE DestinyInventoryItemDefinition AS SELECT * FROM tmpDb.DestinyInventoryItemDefinition").execute(&mut db).await {
        Ok(e) => e,
        Err(e) => panic!("FAIL: {:?}", e),
    };

with the following error:

thread 'main' panicked at 'FAIL: Database(SqliteError { code: 1, message: "no such table: tmpDb.DestinyInventoryItemDefinition" })', src/main.rs:96:19

Looking at the sqlite docs for in-memory databases at:
https://www.sqlite.org/inmemorydb.html

It mentions lists "file::memory:" as a string to create an in-memory database. Using this string above, and the ATTACH command works. ("sqlite:file::memory:") also works.

Not sure if this is a doc bug, or some other issue with SQLX, but I wanted to share here in case it was a bug. For the memory section of the docs, it might be worth link to : https://www.sqlite.org/inmemorydb.html.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdb:sqliteRelated to SQLitequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions