Use sqlite_error_code where possible

This commit is contained in:
gwenn 2022-04-07 09:15:55 +02:00
parent f54e550b2b
commit fedf6b41ae
2 changed files with 9 additions and 15 deletions

View File

@ -90,7 +90,7 @@ mod test {
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use crate::{Connection, Error, ErrorCode, Result, TransactionBehavior}; use crate::{Connection, ErrorCode, Result, TransactionBehavior};
#[test] #[test]
fn test_default_busy() -> Result<()> { fn test_default_busy() -> Result<()> {
@ -101,12 +101,10 @@ mod test {
let tx1 = db1.transaction_with_behavior(TransactionBehavior::Exclusive)?; let tx1 = db1.transaction_with_behavior(TransactionBehavior::Exclusive)?;
let db2 = Connection::open(&path)?; let db2 = Connection::open(&path)?;
let r: Result<()> = db2.query_row("PRAGMA schema_version", [], |_| unreachable!()); let r: Result<()> = db2.query_row("PRAGMA schema_version", [], |_| unreachable!());
match r.unwrap_err() { assert_eq!(
Error::SqliteFailure(err, _) => { r.unwrap_err().sqlite_error_code(),
assert_eq!(err.code, ErrorCode::DatabaseBusy); Some(ErrorCode::DatabaseBusy)
} );
err => panic!("Unexpected error {}", err),
}
tx1.rollback() tx1.rollback()
} }

View File

@ -1742,14 +1742,10 @@ mod test {
let result: Result<Vec<i32>> = stmt.query([])?.map(|r| r.get(0)).collect(); let result: Result<Vec<i32>> = stmt.query([])?.map(|r| r.get(0)).collect();
match result.unwrap_err() { assert_eq!(
Error::SqliteFailure(err, _) => { result.unwrap_err().sqlite_error_code(),
assert_eq!(err.code, ErrorCode::OperationInterrupted); Some(ErrorCode::OperationInterrupted)
} );
err => {
panic!("Unexpected error {}", err);
}
}
Ok(()) Ok(())
} }