Merge pull request #987 from gwenn/checked_memory_handle

[Cosmetic] Replace some usages of checked_memory_handle
This commit is contained in:
gwenn 2021-07-27 18:20:02 +02:00 committed by GitHub
commit 569893531e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1083,7 +1083,7 @@ mod test {
ensure_sync::<InterruptHandle>();
}
pub fn checked_memory_handle() -> Connection {
fn checked_memory_handle() -> Connection {
Connection::open_in_memory().unwrap()
}
@ -1211,7 +1211,7 @@ mod test {
#[test]
fn test_close_retry() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
// force the DB to be busy by preparing a statement; this must be done at the
// FFI level to allow us to call .close() without dropping the prepared
@ -1264,7 +1264,7 @@ mod test {
#[test]
fn test_execute_batch() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER);
INSERT INTO foo VALUES(1);
@ -1282,7 +1282,7 @@ mod test {
#[test]
fn test_execute() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER)")?;
assert_eq!(1, db.execute("INSERT INTO foo(x) VALUES (?)", [1i32])?);
@ -1323,7 +1323,7 @@ mod test {
#[test]
fn test_prepare_column_names() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let stmt = db.prepare("SELECT * FROM foo")?;
@ -1338,7 +1338,7 @@ mod test {
#[test]
fn test_prepare_execute() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let mut insert_stmt = db.prepare("INSERT INTO foo(x) VALUES(?)")?;
@ -1359,7 +1359,7 @@ mod test {
#[test]
fn test_prepare_query() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let mut insert_stmt = db.prepare("INSERT INTO foo(x) VALUES(?)")?;
@ -1394,7 +1394,7 @@ mod test {
#[test]
fn test_query_map() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1413,7 +1413,7 @@ mod test {
#[test]
fn test_query_row() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER);
INSERT INTO foo VALUES(1);
@ -1442,7 +1442,7 @@ mod test {
#[test]
fn test_optional() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let result: Result<i64> = db.query_row("SELECT 1 WHERE 0 <> 0", [], |r| r.get(0));
let result = result.optional();
@ -1466,7 +1466,7 @@ mod test {
#[test]
fn test_pragma_query_row() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
assert_eq!(
"memory",
@ -1481,7 +1481,7 @@ mod test {
#[test]
fn test_prepare_failures() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let err = db.prepare("SELECT * FROM does_not_exist").unwrap_err();
@ -1491,7 +1491,7 @@ mod test {
#[test]
fn test_last_insert_rowid() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER PRIMARY KEY)")?;
db.execute_batch("INSERT INTO foo DEFAULT VALUES")?;
@ -1506,18 +1506,19 @@ mod test {
}
#[test]
fn test_is_autocommit() {
let db = checked_memory_handle();
fn test_is_autocommit() -> Result<()> {
let db = Connection::open_in_memory()?;
assert!(
db.is_autocommit(),
"autocommit expected to be active by default"
);
Ok(())
}
#[test]
#[cfg(feature = "modern_sqlite")]
fn test_is_busy() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
assert!(!db.is_busy());
let mut stmt = db.prepare("PRAGMA schema_version")?;
assert!(!db.is_busy());
@ -1534,7 +1535,7 @@ mod test {
#[test]
fn test_statement_debugging() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let query = "SELECT 12345";
let stmt = db.prepare(query)?;
@ -1553,7 +1554,7 @@ mod test {
#[cfg(not(feature = "modern_sqlite"))]
fn check_extended_code(_extended_code: c_int) {}
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x NOT NULL)")?;
let result = db.execute("INSERT INTO foo (x) VALUES (NULL)", []);
@ -1582,7 +1583,7 @@ mod test {
#[test]
#[cfg(feature = "functions")]
fn test_interrupt() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let interrupt_handle = db.get_interrupt_handle();
@ -1630,7 +1631,7 @@ mod test {
#[test]
fn test_get_raw() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(i, x);")?;
let vals = ["foobar", "1234", "qwerty"];
let mut insert_stmt = db.prepare("INSERT INTO foo(i, x) VALUES(?, ?)")?;
@ -1663,7 +1664,7 @@ mod test {
#[test]
fn test_from_handle() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let handle = unsafe { db.handle() };
{
let db = unsafe { Connection::from_handle(handle) }?;
@ -1715,7 +1716,7 @@ mod test {
#[test]
fn test_query_and_then() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1735,7 +1736,7 @@ mod test {
#[test]
fn test_query_and_then_fails() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1765,7 +1766,7 @@ mod test {
#[test]
fn test_query_and_then_custom_error() -> CustomResult<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1786,7 +1787,7 @@ mod test {
#[test]
fn test_query_and_then_custom_error_fails() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1828,7 +1829,7 @@ mod test {
#[test]
fn test_query_row_and_then_custom_error() -> CustomResult<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1845,7 +1846,7 @@ mod test {
#[test]
fn test_query_row_and_then_custom_error_fails() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1882,7 +1883,7 @@ mod test {
#[test]
fn test_dynamic() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = "BEGIN;
CREATE TABLE foo(x INTEGER, y TEXT);
INSERT INTO foo VALUES(4, \"hello\");
@ -1896,7 +1897,7 @@ mod test {
}
#[test]
fn test_dyn_box() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let b: Box<dyn ToSql> = Box::new(5);
db.execute("INSERT INTO foo VALUES(?)", [b])?;
@ -1908,7 +1909,7 @@ mod test {
#[test]
fn test_params() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.query_row(
"SELECT
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
@ -1929,7 +1930,7 @@ mod test {
#[test]
#[cfg(not(feature = "extra_check"))]
fn test_alter_table() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE x(t);")?;
// `execute_batch` should be used but `execute` should also work
db.execute("ALTER TABLE x RENAME TO y;", [])?;
@ -1938,7 +1939,7 @@ mod test {
#[test]
fn test_batch() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
let sql = r"
CREATE TABLE tbl1 (col);
CREATE TABLE tbl2 (col);
@ -1954,7 +1955,7 @@ mod test {
#[test]
#[cfg(all(feature = "bundled", not(feature = "bundled-sqlcipher")))] // SQLite >= 3.35.0
fn test_returning() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.execute_batch("CREATE TABLE foo(x INTEGER PRIMARY KEY)")?;
let row_id =
db.query_row::<i64, _, _>("INSERT INTO foo DEFAULT VALUES RETURNING ROWID", [], |r| {
@ -1967,7 +1968,7 @@ mod test {
#[test]
#[cfg(feature = "modern_sqlite")]
fn test_cache_flush() -> Result<()> {
let db = checked_memory_handle();
let db = Connection::open_in_memory()?;
db.cache_flush()
}
}