pragma_update fails with ExecuteReturnedResults

Ideally, while executing a batch, we should fail if it contains a SELECT
statement. But currently there is no way to make the distinction between
a SELECT and a PRAGMA which both updates and returns a row.
So we fail only when `extra_check` feature is activated.
This commit is contained in:
gwenn 2020-08-17 19:13:55 +02:00
parent 0063db53ca
commit a4691db6d0
2 changed files with 13 additions and 1 deletions

View File

@ -451,7 +451,8 @@ impl Connection {
let mut sql = sql; let mut sql = sql;
while !sql.is_empty() { while !sql.is_empty() {
let stmt = self.prepare(sql)?; let stmt = self.prepare(sql)?;
if !stmt.stmt.is_null() && stmt.step()? { if !stmt.stmt.is_null() && stmt.step()? && cfg!(feature = "extra_check") {
// Some PRAGMA may return rows
return Err(Error::ExecuteReturnedResults); return Err(Error::ExecuteReturnedResults);
} }
let tail = stmt.stmt.tail(); let tail = stmt.stmt.tail();

View File

@ -430,4 +430,15 @@ mod test {
sql.push_string_literal("value'; --"); sql.push_string_literal("value'; --");
assert_eq!("'value''; --'", sql.as_str()); assert_eq!("'value''; --'", sql.as_str());
} }
#[test]
fn locking_mode() {
let db = Connection::open_in_memory().unwrap();
let r = db.pragma_update(None, "locking_mode", &"exclusive");
if cfg!(feature = "extra_check") {
r.unwrap_err();
} else {
r.unwrap();
}
}
} }