mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +00:00
fix(sqlite): with caching disabled force persistent to false
additionally, set persistent to true for a cached statement and correctly only reset the statement when its being reused
This commit is contained in:
parent
8d24dfc0ef
commit
8d1368f163
@ -22,21 +22,25 @@ fn prepare<'a>(
|
||||
query: &str,
|
||||
persistent: bool,
|
||||
) -> Result<&'a mut SqliteStatement, Error> {
|
||||
if !persistent {
|
||||
if !persistent || statements.capacity() == 0 {
|
||||
*statement = Some(SqliteStatement::prepare(conn, query, false)?);
|
||||
return Ok(statement.as_mut().unwrap());
|
||||
}
|
||||
|
||||
if !statements.contains_key(query) {
|
||||
let statement = SqliteStatement::prepare(conn, query, false)?;
|
||||
let exists = !statements.contains_key(query);
|
||||
|
||||
if !exists {
|
||||
let statement = SqliteStatement::prepare(conn, query, true)?;
|
||||
statements.insert(query, statement);
|
||||
}
|
||||
|
||||
let statement = statements.get_mut(query).unwrap();
|
||||
|
||||
// as this statement has been executed before, we reset before continuing
|
||||
// this also causes any rows that are from the statement to be inflated
|
||||
statement.reset();
|
||||
if exists {
|
||||
// as this statement has been executed before, we reset before continuing
|
||||
// this also causes any rows that are from the statement to be inflated
|
||||
statement.reset();
|
||||
}
|
||||
|
||||
Ok(statement)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user