Merge pull request #1304 from jgraettinger/johnny/stmt-read-only

Add Statement.readonly() accessor
This commit is contained in:
gwenn 2023-03-23 21:54:49 +01:00 committed by GitHub
commit 72fe73219a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -197,7 +197,6 @@ impl RawStatement {
}
// does not work for PRAGMA
#[cfg(feature = "extra_check")]
#[inline]
pub fn readonly(&self) -> bool {
unsafe { ffi::sqlite3_stmt_readonly(self.ptr) != 0 }

View File

@ -709,6 +709,12 @@ impl Statement<'_> {
self.stmt.is_explain()
}
/// Returns true if the statement is read only.
#[inline]
pub fn readonly(&self) -> bool {
self.stmt.readonly()
}
#[cfg(feature = "extra_check")]
#[inline]
pub(crate) fn check_no_tail(&self) -> Result<()> {
@ -1324,6 +1330,14 @@ mod test {
Ok(())
}
#[test]
fn readonly() -> Result<()> {
let db = Connection::open_in_memory()?;
let stmt = db.prepare("SELECT 1;")?;
assert!(stmt.readonly());
Ok(())
}
#[test]
#[cfg(feature = "modern_sqlite")] // SQLite >= 3.38.0
fn test_error_offset() -> Result<()> {