tursodatabase / tursodatabase/libsql
Calling `Statement::excecute` multiple times does not change the parameter binding
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 17.2k
- Forks
- 531
- Avg merge
- 1h 12m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal Rust reproduction using Connection::prepare and repeated Statement::execute calls with different parameters. Trace those prepare and execute entry points to find why the first binding is reused; done means the loop inserts both example.com and example.org without preparing a new statement each time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sqlite
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100