mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 05:41:47 +08:00
[breaking change] Update edition from 2018 to 2021
And fix clippy warnings
This commit is contained in:
parent
51a69b1b74
commit
3aa9addaa3
@ -3,7 +3,7 @@ name = "rusqlite"
|
||||
# Note: Update version in README.md when you change this.
|
||||
version = "0.28.0"
|
||||
authors = ["The rusqlite developers"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
description = "Ergonomic wrapper for SQLite"
|
||||
repository = "https://github.com/rusqlite/rusqlite"
|
||||
documentation = "http://docs.rs/rusqlite/"
|
||||
|
@ -274,7 +274,6 @@ impl Blob<'_> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
use std::convert::TryInto;
|
||||
self.size().try_into().unwrap()
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ mod test {
|
||||
));
|
||||
blob.raw_read_at_exact(&mut s2, 5).unwrap_err();
|
||||
|
||||
let end_pos = blob.seek(std::io::SeekFrom::Current(0)).unwrap();
|
||||
let end_pos = blob.stream_position().unwrap();
|
||||
assert_eq!(end_pos, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ mod test {
|
||||
assert_eq!(ty, Type::Integer);
|
||||
}
|
||||
e => {
|
||||
panic!("Unexpected error type: {:?}", e);
|
||||
panic!("Unexpected error type: {e:?}");
|
||||
}
|
||||
}
|
||||
match row.get::<_, String>("y").unwrap_err() {
|
||||
@ -213,7 +213,7 @@ mod test {
|
||||
assert_eq!(ty, Type::Null);
|
||||
}
|
||||
e => {
|
||||
panic!("Unexpected error type: {:?}", e);
|
||||
panic!("Unexpected error type: {e:?}");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
17
src/error.rs
17
src/error.rs
@ -252,11 +252,7 @@ impl fmt::Display for Error {
|
||||
),
|
||||
Error::FromSqlConversionFailure(i, ref t, ref err) => {
|
||||
if i != UNKNOWN_COLUMN {
|
||||
write!(
|
||||
f,
|
||||
"Conversion error from type {} at index: {}, {}",
|
||||
t, i, err
|
||||
)
|
||||
write!(f, "Conversion error from type {t} at index: {i}, {err}")
|
||||
} else {
|
||||
err.fmt(f)
|
||||
}
|
||||
@ -278,15 +274,12 @@ impl fmt::Display for Error {
|
||||
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
|
||||
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
|
||||
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
|
||||
Error::InvalidColumnType(i, ref name, ref t) => write!(
|
||||
f,
|
||||
"Invalid column type {} at index: {}, name: {}",
|
||||
t, i, name
|
||||
),
|
||||
Error::InvalidColumnType(i, ref name, ref t) => {
|
||||
write!(f, "Invalid column type {t} at index: {i}, name: {name}")
|
||||
}
|
||||
Error::InvalidParameterCount(i1, n1) => write!(
|
||||
f,
|
||||
"Wrong number of parameters passed to query. Got {}, needed {}",
|
||||
i1, n1
|
||||
"Wrong number of parameters passed to query. Got {i1}, needed {n1}"
|
||||
),
|
||||
Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
|
||||
|
||||
|
@ -656,7 +656,7 @@ unsafe fn free_boxed_hook<F>(p: *mut c_void) {
|
||||
|
||||
unsafe fn expect_utf8<'a>(p_str: *const c_char, description: &'static str) -> &'a str {
|
||||
expect_optional_utf8(p_str, description)
|
||||
.unwrap_or_else(|| panic!("received empty {}", description))
|
||||
.unwrap_or_else(|| panic!("received empty {description}"))
|
||||
}
|
||||
|
||||
unsafe fn expect_optional_utf8<'a>(
|
||||
@ -667,7 +667,7 @@ unsafe fn expect_optional_utf8<'a>(
|
||||
return None;
|
||||
}
|
||||
std::str::from_utf8(std::ffi::CStr::from_ptr(p_str).to_bytes())
|
||||
.unwrap_or_else(|_| panic!("received non-utf8 string as {}", description))
|
||||
.unwrap_or_else(|_| panic!("received non-utf8 string as {description}"))
|
||||
.into()
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ impl Drop for InnerConnection {
|
||||
if panicking() {
|
||||
eprintln!("Error while closing SQLite connection: {e:?}");
|
||||
} else {
|
||||
panic!("Error while closing SQLite connection: {:?}", e);
|
||||
panic!("Error while closing SQLite connection: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
src/lib.rs
31
src/lib.rs
@ -1291,9 +1291,7 @@ mod test {
|
||||
assert_eq!(ffi::SQLITE_CANTOPEN, e.extended_code);
|
||||
assert!(
|
||||
msg.contains(filename),
|
||||
"error message '{}' does not contain '{}'",
|
||||
msg,
|
||||
filename
|
||||
"error message '{msg}' does not contain '{filename}'"
|
||||
);
|
||||
} else {
|
||||
panic!("SqliteFailure expected");
|
||||
@ -1421,8 +1419,7 @@ mod test {
|
||||
assert_eq!(
|
||||
err,
|
||||
Error::ExecuteReturnedResults,
|
||||
"Unexpected error: {}",
|
||||
err
|
||||
"Unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
@ -1438,7 +1435,7 @@ mod test {
|
||||
.unwrap_err();
|
||||
match err {
|
||||
Error::MultipleStatement => (),
|
||||
_ => panic!("Unexpected error: {}", err),
|
||||
_ => panic!("Unexpected error: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1549,7 +1546,7 @@ mod test {
|
||||
let result: Result<i64> = db.one_column("SELECT x FROM foo WHERE x > 5");
|
||||
match result.unwrap_err() {
|
||||
Error::QueryReturnedNoRows => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let bad_query_result = db.query_row("NOT A PROPER QUERY; test123", [], |_| Ok(()));
|
||||
@ -1601,7 +1598,7 @@ mod test {
|
||||
// > MEMORY or OFF and can not be changed to a different value. An
|
||||
// > attempt to change the journal_mode of an in-memory database to
|
||||
// > any setting other than MEMORY or OFF is ignored.
|
||||
assert!(mode == "memory" || mode == "off", "Got mode {:?}", mode);
|
||||
assert!(mode == "memory" || mode == "off", "Got mode {mode:?}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -1688,7 +1685,7 @@ mod test {
|
||||
assert_eq!(err.code, ErrorCode::ConstraintViolation);
|
||||
check_extended_code(err.extended_code);
|
||||
}
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -1870,7 +1867,7 @@ mod test {
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
Error::InvalidColumnType(..) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let bad_idx: Result<Vec<String>> =
|
||||
@ -1878,7 +1875,7 @@ mod test {
|
||||
|
||||
match bad_idx.unwrap_err() {
|
||||
Error::InvalidColumnIndex(_) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -1923,7 +1920,7 @@ mod test {
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let bad_idx: CustomResult<Vec<String>> = query
|
||||
@ -1932,7 +1929,7 @@ mod test {
|
||||
|
||||
match bad_idx.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnIndex(_)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let non_sqlite_err: CustomResult<Vec<String>> = query
|
||||
@ -1941,7 +1938,7 @@ mod test {
|
||||
|
||||
match non_sqlite_err.unwrap_err() {
|
||||
CustomError::SomeError => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -1978,7 +1975,7 @@ mod test {
|
||||
|
||||
match bad_type.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnType(..)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let bad_idx: CustomResult<String> =
|
||||
@ -1986,7 +1983,7 @@ mod test {
|
||||
|
||||
match bad_idx.unwrap_err() {
|
||||
CustomError::Sqlite(Error::InvalidColumnIndex(_)) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
|
||||
let non_sqlite_err: CustomResult<String> =
|
||||
@ -1994,7 +1991,7 @@ mod test {
|
||||
|
||||
match non_sqlite_err.unwrap_err() {
|
||||
CustomError::SomeError => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -405,18 +405,17 @@ mod test {
|
||||
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
|
||||
assert!(
|
||||
journal_mode == "off" || journal_mode == "memory",
|
||||
"mode: {:?}",
|
||||
journal_mode,
|
||||
"mode: {journal_mode:?}"
|
||||
);
|
||||
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
||||
let mode =
|
||||
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
assert!(mode == "off" || mode == "memory", "mode: {mode:?}");
|
||||
|
||||
let param: &dyn crate::ToSql = &"OFF";
|
||||
let mode =
|
||||
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
|
||||
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
|
||||
assert!(mode == "off" || mode == "memory", "mode: {mode:?}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1272,12 +1272,12 @@ mod test {
|
||||
assert_eq!(stmt.insert([2i32])?, 2);
|
||||
match stmt.insert([1i32]).unwrap_err() {
|
||||
Error::StatementChangedRows(0) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
let mut multi = db.prepare("INSERT INTO foo (x) SELECT 3 UNION ALL SELECT 4")?;
|
||||
match multi.insert([]).unwrap_err() {
|
||||
Error::StatementChangedRows(2) => (),
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -1532,7 +1532,7 @@ mod test {
|
||||
assert_eq!(error.code, ErrorCode::Unknown);
|
||||
assert_eq!(offset, 7);
|
||||
}
|
||||
err => panic!("Unexpected error {}", err),
|
||||
err => panic!("Unexpected error {err}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ mod test {
|
||||
assert_eq!(e.code, crate::ErrorCode::Unknown);
|
||||
assert!(m.contains("transaction"));
|
||||
} else {
|
||||
panic!("Unexpected error type: {:?}", e);
|
||||
panic!("Unexpected error type: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,7 @@ impl fmt::Display for FromSqlError {
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"Cannot read {} byte value out of {} byte blob",
|
||||
expected_size, blob_size
|
||||
"Cannot read {expected_size} byte value out of {blob_size} byte blob"
|
||||
)
|
||||
}
|
||||
FromSqlError::Other(ref err) => err.fmt(f),
|
||||
@ -248,7 +247,7 @@ mod test {
|
||||
.unwrap_err();
|
||||
match err {
|
||||
Error::IntegralValueOutOfRange(_, value) => assert_eq!(*n, value),
|
||||
_ => panic!("unexpected error: {}", err),
|
||||
_ => panic!("unexpected error: {err}"),
|
||||
}
|
||||
}
|
||||
for n in in_range {
|
||||
|
@ -352,7 +352,7 @@ mod test {
|
||||
assert_eq!(Value::Integer(1), row.get::<_, Value>(2)?);
|
||||
match row.get::<_, Value>(3)? {
|
||||
Value::Real(val) => assert!((1.5 - val).abs() < f64::EPSILON),
|
||||
x => panic!("Invalid Value {:?}", x),
|
||||
x => panic!("Invalid Value {x:?}"),
|
||||
}
|
||||
assert_eq!(Value::Null, row.get::<_, Value>(4)?);
|
||||
Ok(())
|
||||
|
@ -74,7 +74,7 @@ mod test {
|
||||
);
|
||||
}
|
||||
e => {
|
||||
panic!("Expected conversion failure, got {}", e);
|
||||
panic!("Expected conversion failure, got {e}");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -100,7 +100,6 @@ impl SqliteMallocString {
|
||||
/// This means it's safe to use in extern "C" functions even outside of
|
||||
/// `catch_unwind`.
|
||||
pub(crate) fn from_str(s: &str) -> Self {
|
||||
use std::convert::TryFrom;
|
||||
let s = if s.as_bytes().contains(&0) {
|
||||
std::borrow::Cow::Owned(make_nonnull(s))
|
||||
} else {
|
||||
|
@ -113,10 +113,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
||||
match param {
|
||||
"filename" => {
|
||||
if !Path::new(value).exists() {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"file '{}' does not exist",
|
||||
value
|
||||
)));
|
||||
return Err(Error::ModuleError(format!("file '{value}' does not exist")));
|
||||
}
|
||||
vtab.filename = value.to_owned();
|
||||
}
|
||||
@ -137,8 +134,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
||||
n_col = Some(n);
|
||||
} else {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized argument to 'columns': {}",
|
||||
value
|
||||
"unrecognized argument to 'columns': {value}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@ -147,8 +143,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
||||
vtab.has_headers = b;
|
||||
} else {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized argument to 'header': {}",
|
||||
value
|
||||
"unrecognized argument to 'header': {value}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@ -157,8 +152,7 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
||||
vtab.delimiter = b;
|
||||
} else {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized argument to 'delimiter': {}",
|
||||
value
|
||||
"unrecognized argument to 'delimiter': {value}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@ -171,15 +165,13 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
|
||||
}
|
||||
} else {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized argument to 'quote': {}",
|
||||
value
|
||||
"unrecognized argument to 'quote': {value}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized parameter '{}'",
|
||||
param
|
||||
"unrecognized parameter '{param}'"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@ -326,8 +318,7 @@ unsafe impl VTabCursor for CsvTabCursor<'_> {
|
||||
fn column(&self, ctx: &mut Context, col: c_int) -> Result<()> {
|
||||
if col < 0 || col as usize >= self.cols.len() {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"column index out of bounds: {}",
|
||||
col
|
||||
"column index out of bounds: {col}"
|
||||
)));
|
||||
}
|
||||
if self.cols.is_empty() {
|
||||
|
@ -56,8 +56,7 @@ impl VTabLog {
|
||||
"schema" => {
|
||||
if schema.is_some() {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"more than one '{}' parameter",
|
||||
param
|
||||
"more than one '{param}' parameter"
|
||||
)));
|
||||
}
|
||||
schema = Some(value.to_owned())
|
||||
@ -65,8 +64,7 @@ impl VTabLog {
|
||||
"rows" => {
|
||||
if n_row.is_some() {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"more than one '{}' parameter",
|
||||
param
|
||||
"more than one '{param}' parameter"
|
||||
)));
|
||||
}
|
||||
if let Ok(n) = i64::from_str(value) {
|
||||
@ -75,8 +73,7 @@ impl VTabLog {
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::ModuleError(format!(
|
||||
"unrecognized parameter '{}'",
|
||||
param
|
||||
"unrecognized parameter '{param}'"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user