From a4691db6d0c63968905b95a6764caff6609c068c Mon Sep 17 00:00:00 2001 From: gwenn Date: Mon, 17 Aug 2020 19:13:55 +0200 Subject: [PATCH] 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. --- src/lib.rs | 3 ++- src/pragma.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a16106c..53f1773 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -451,7 +451,8 @@ impl Connection { let mut sql = sql; while !sql.is_empty() { 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); } let tail = stmt.stmt.tail(); diff --git a/src/pragma.rs b/src/pragma.rs index b115f8f..4855154 100644 --- a/src/pragma.rs +++ b/src/pragma.rs @@ -430,4 +430,15 @@ mod test { sql.push_string_literal("value'; --"); 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(); + } + } }