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:
Ryan Leckey 2020-06-25 03:44:26 -07:00
parent 8d24dfc0ef
commit 8d1368f163

View File

@ -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)
}