Skip to content

Calling Statement::excecute multiple times does not change the parameter binding #2135

@bikeshedder

Description

@bikeshedder

When calling Connection::prepare once and using the Statement to execute multiple times with varying parameters it causes the query to be executed with the first bound parameters.

Minimal reproduction example:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let database = libsql::Builder::new_local("example.db").build().await?;
    let conn = database.connect()?;
    conn.execute_batch("CREATE TABLE domain (fqdn TEXT NOT NULL PRIMARY KEY)").await?;
    let mut stmt = conn.prepare("INSERT INTO domain VALUES (?1)").await?;
    for domain in ["example.com", "example.org"] {
        println!("{}", domain);
        stmt.execute([domain]).await?;
    }
    Ok(())
}

Output:

example.com
example.org
Error: SqliteFailure(1555, "UNIQUE constraint failed: domain.fqdn")

I just released the first version of deadpool-libsql and ran into this issue in my first application I'm trying to build with libsql.

When moving the Connection::prepare call inside the loop it does the right thing. But that's really not how I would expect prepared statements to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions