This commit is contained in:
gwenn 2022-10-28 19:02:49 +02:00
parent 3717b6d514
commit 6d509afe49
11 changed files with 49 additions and 49 deletions

View File

@ -98,15 +98,15 @@ mod build_bundled {
#[cfg(not(feature = "buildtime_bindgen"))] #[cfg(not(feature = "buildtime_bindgen"))]
{ {
use std::fs; use std::fs;
fs::copy(format!("{}/bindgen_bundled_version.rs", lib_name), out_path) fs::copy(format!("{lib_name}/bindgen_bundled_version.rs"), out_path)
.expect("Could not copy bindings to output directory"); .expect("Could not copy bindings to output directory");
} }
// println!("cargo:rerun-if-changed=sqlite3/sqlite3.c"); // println!("cargo:rerun-if-changed=sqlite3/sqlite3.c");
// println!("cargo:rerun-if-changed=sqlcipher/sqlite3.c"); // println!("cargo:rerun-if-changed=sqlcipher/sqlite3.c");
println!("cargo:rerun-if-changed={}/sqlite3.c", lib_name); println!("cargo:rerun-if-changed={lib_name}/sqlite3.c");
println!("cargo:rerun-if-changed=sqlite3/wasm32-wasi-vfs.c"); println!("cargo:rerun-if-changed=sqlite3/wasm32-wasi-vfs.c");
let mut cfg = cc::Build::new(); let mut cfg = cc::Build::new();
cfg.file(format!("{}/sqlite3.c", lib_name)) cfg.file(format!("{lib_name}/sqlite3.c"))
.flag("-DSQLITE_CORE") .flag("-DSQLITE_CORE")
.flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1") .flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1")
.flag("-DSQLITE_ENABLE_API_ARMOR") .flag("-DSQLITE_ENABLE_API_ARMOR")
@ -261,12 +261,12 @@ mod build_bundled {
} }
if let Ok(limit) = env::var("SQLITE_MAX_VARIABLE_NUMBER") { if let Ok(limit) = env::var("SQLITE_MAX_VARIABLE_NUMBER") {
cfg.flag(&format!("-DSQLITE_MAX_VARIABLE_NUMBER={}", limit)); cfg.flag(&format!("-DSQLITE_MAX_VARIABLE_NUMBER={limit}"));
} }
println!("cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER"); println!("cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER");
if let Ok(limit) = env::var("SQLITE_MAX_EXPR_DEPTH") { if let Ok(limit) = env::var("SQLITE_MAX_EXPR_DEPTH") {
cfg.flag(&format!("-DSQLITE_MAX_EXPR_DEPTH={}", limit)); cfg.flag(&format!("-DSQLITE_MAX_EXPR_DEPTH={limit}"));
} }
println!("cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH"); println!("cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH");
@ -275,7 +275,7 @@ mod build_bundled {
if extra.starts_with("-D") || extra.starts_with("-U") { if extra.starts_with("-D") || extra.starts_with("-U") {
cfg.flag(extra); cfg.flag(extra);
} else if extra.starts_with("SQLITE_") { } else if extra.starts_with("SQLITE_") {
cfg.flag(&format!("-D{}", extra)); cfg.flag(&format!("-D{extra}"));
} else { } else {
panic!("Don't understand {} in LIBSQLITE3_FLAGS", extra); panic!("Don't understand {} in LIBSQLITE3_FLAGS", extra);
} }
@ -285,13 +285,13 @@ mod build_bundled {
cfg.compile(lib_name); cfg.compile(lib_name);
println!("cargo:lib_dir={}", out_dir); println!("cargo:lib_dir={out_dir}");
} }
fn env(name: &str) -> Option<OsString> { fn env(name: &str) -> Option<OsString> {
let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_"); let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_");
let prefixed = format!("{}_{}", prefix, name); let prefixed = format!("{prefix}_{name}");
let var = env::var_os(&prefixed); let var = env::var_os(prefixed);
match var { match var {
None => env::var_os(name), None => env::var_os(name),
@ -334,7 +334,7 @@ impl From<HeaderLocation> for String {
match header { match header {
HeaderLocation::FromEnvironment => { HeaderLocation::FromEnvironment => {
let prefix = env_prefix(); let prefix = env_prefix();
let mut header = env::var(format!("{}_INCLUDE_DIR", prefix)).unwrap_or_else(|_| { let mut header = env::var(format!("{prefix}_INCLUDE_DIR")).unwrap_or_else(|_| {
panic!( panic!(
"{}_INCLUDE_DIR must be set if {}_LIB_DIR is set", "{}_INCLUDE_DIR must be set if {}_LIB_DIR is set",
prefix, prefix prefix, prefix
@ -404,10 +404,10 @@ mod build_linked {
// `links=` value in our Cargo.toml) to get this value. This might be // `links=` value in our Cargo.toml) to get this value. This might be
// useful if you need to ensure whatever crypto library sqlcipher relies // useful if you need to ensure whatever crypto library sqlcipher relies
// on is available, for example. // on is available, for example.
println!("cargo:link-target={}", link_lib); println!("cargo:link-target={link_lib}");
if win_target() && cfg!(feature = "winsqlite3") { if win_target() && cfg!(feature = "winsqlite3") {
println!("cargo:rustc-link-lib=dylib={}", link_lib); println!("cargo:rustc-link-lib=dylib={link_lib}");
return HeaderLocation::Wrapper; return HeaderLocation::Wrapper;
} }
@ -418,8 +418,8 @@ mod build_linked {
env::set_var("PKG_CONFIG_PATH", pkgconfig_path); env::set_var("PKG_CONFIG_PATH", pkgconfig_path);
if pkg_config::Config::new().probe(link_lib).is_err() { if pkg_config::Config::new().probe(link_lib).is_err() {
// Otherwise just emit the bare minimum link commands. // Otherwise just emit the bare minimum link commands.
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib); println!("cargo:rustc-link-lib={}={link_lib}", find_link_mode());
println!("cargo:rustc-link-search={}", dir); println!("cargo:rustc-link-search={dir}");
} }
return HeaderLocation::FromEnvironment; return HeaderLocation::FromEnvironment;
} }
@ -444,7 +444,7 @@ mod build_linked {
// request and hope that the library exists on the system paths. We used to // request and hope that the library exists on the system paths. We used to
// output /usr/lib explicitly, but that can introduce other linking problems; // output /usr/lib explicitly, but that can introduce other linking problems;
// see https://github.com/rusqlite/rusqlite/issues/207. // see https://github.com/rusqlite/rusqlite/issues/207.
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib); println!("cargo:rustc-link-lib={}={link_lib}", find_link_mode());
HeaderLocation::Wrapper HeaderLocation::Wrapper
} }
} }

View File

@ -245,7 +245,7 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
Error::SqliteFailure(ref err, None) => err.fmt(f), Error::SqliteFailure(ref err, None) => err.fmt(f),
Error::SqliteFailure(_, Some(ref s)) => write!(f, "{}", s), Error::SqliteFailure(_, Some(ref s)) => write!(f, "{s}"),
Error::SqliteSingleThreadedMode => write!( Error::SqliteSingleThreadedMode => write!(
f, f,
"SQLite was compiled or configured for single-threaded use only" "SQLite was compiled or configured for single-threaded use only"
@ -263,21 +263,21 @@ impl fmt::Display for Error {
} }
Error::IntegralValueOutOfRange(col, val) => { Error::IntegralValueOutOfRange(col, val) => {
if col != UNKNOWN_COLUMN { if col != UNKNOWN_COLUMN {
write!(f, "Integer {} out of range at index {}", val, col) write!(f, "Integer {val} out of range at index {col}")
} else { } else {
write!(f, "Integer {} out of range", val) write!(f, "Integer {val} out of range")
} }
} }
Error::Utf8Error(ref err) => err.fmt(f), Error::Utf8Error(ref err) => err.fmt(f),
Error::NulError(ref err) => err.fmt(f), Error::NulError(ref err) => err.fmt(f),
Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {}", name), Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {name}"),
Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()), Error::InvalidPath(ref p) => write!(f, "Invalid path: {}", p.to_string_lossy()),
Error::ExecuteReturnedResults => { Error::ExecuteReturnedResults => {
write!(f, "Execute returned results - did you mean to call query?") write!(f, "Execute returned results - did you mean to call query?")
} }
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"), Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {}", i), Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {i}"),
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {}", name), Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {name}"),
Error::InvalidColumnType(i, ref name, ref t) => write!( Error::InvalidColumnType(i, ref name, ref t) => write!(
f, f,
"Invalid column type {} at index: {}, name: {}", "Invalid column type {} at index: {}, name: {}",
@ -288,22 +288,22 @@ impl fmt::Display for Error {
"Wrong number of parameters passed to query. Got {}, needed {}", "Wrong number of parameters passed to query. Got {}, needed {}",
i1, n1 i1, n1
), ),
Error::StatementChangedRows(i) => write!(f, "Query changed {} rows", i), Error::StatementChangedRows(i) => write!(f, "Query changed {i} rows"),
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
Error::InvalidFunctionParameterType(i, ref t) => { Error::InvalidFunctionParameterType(i, ref t) => {
write!(f, "Invalid function parameter type {} at index {}", t, i) write!(f, "Invalid function parameter type {t} at index {i}")
} }
#[cfg(feature = "vtab")] #[cfg(feature = "vtab")]
Error::InvalidFilterParameterType(i, ref t) => { Error::InvalidFilterParameterType(i, ref t) => {
write!(f, "Invalid filter parameter type {} at index {}", t, i) write!(f, "Invalid filter parameter type {t} at index {i}")
} }
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
Error::UserFunctionError(ref err) => err.fmt(f), Error::UserFunctionError(ref err) => err.fmt(f),
Error::ToSqlConversionFailure(ref err) => err.fmt(f), Error::ToSqlConversionFailure(ref err) => err.fmt(f),
Error::InvalidQuery => write!(f, "Query is not read-only"), Error::InvalidQuery => write!(f, "Query is not read-only"),
#[cfg(feature = "vtab")] #[cfg(feature = "vtab")]
Error::ModuleError(ref desc) => write!(f, "{}", desc), Error::ModuleError(ref desc) => write!(f, "{desc}"),
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
Error::UnwindingPanic => write!(f, "unwinding panic"), Error::UnwindingPanic => write!(f, "unwinding panic"),
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
@ -317,7 +317,7 @@ impl fmt::Display for Error {
offset, offset,
ref sql, ref sql,
.. ..
} => write!(f, "{} in {} at offset {}", msg, sql, offset), } => write!(f, "{msg} in {sql} at offset {offset}"),
} }
} }
} }

View File

@ -105,7 +105,7 @@ impl InnerConnection {
{ {
e = Error::SqliteFailure( e = Error::SqliteFailure(
ffi::Error::new(r), ffi::Error::new(r),
Some(format!("{}: {}", msg, c_path.to_string_lossy())), Some(format!("{msg}: {}", c_path.to_string_lossy())),
); );
} }
ffi::sqlite3_close(db); ffi::sqlite3_close(db);
@ -325,7 +325,7 @@ impl InnerConnection {
1 => Ok(true), 1 => Ok(true),
-1 => Err(Error::SqliteFailure( -1 => Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("{:?} is not the name of a database", db_name)), Some(format!("{db_name:?} is not the name of a database")),
)), )),
_ => Err(error_from_sqlite_code( _ => Err(error_from_sqlite_code(
r, r,
@ -351,7 +351,7 @@ impl InnerConnection {
2 => Ok(super::transaction::TransactionState::Write), 2 => Ok(super::transaction::TransactionState::Write),
-1 => Err(Error::SqliteFailure( -1 => Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("{:?} is not the name of a valid schema", db_name)), Some(format!("{db_name:?} is not the name of a valid schema")),
)), )),
_ => Err(error_from_sqlite_code( _ => Err(error_from_sqlite_code(
r, r,
@ -375,7 +375,7 @@ impl Drop for InnerConnection {
if let Err(e) = self.close() { if let Err(e) = self.close() {
if panicking() { if panicking() {
eprintln!("Error while closing SQLite connection: {:?}", e); eprintln!("Error while closing SQLite connection: {e:?}");
} else { } else {
panic!("Error while closing SQLite connection: {:?}", e); panic!("Error while closing SQLite connection: {:?}", e);
} }

View File

@ -1616,7 +1616,7 @@ mod test {
db.execute_batch("CREATE TABLE foo(x INTEGER);")?; db.execute_batch("CREATE TABLE foo(x INTEGER);")?;
let err = db.prepare("SELECT * FROM does_not_exist").unwrap_err(); let err = db.prepare("SELECT * FROM does_not_exist").unwrap_err();
assert!(format!("{}", err).contains("does_not_exist")); assert!(format!("{err}").contains("does_not_exist"));
Ok(()) Ok(())
} }
@ -1669,7 +1669,7 @@ mod test {
let query = "SELECT 12345"; let query = "SELECT 12345";
let stmt = db.prepare(query)?; let stmt = db.prepare(query)?;
assert!(format!("{:?}", stmt).contains(query)); assert!(format!("{stmt:?}").contains(query));
Ok(()) Ok(())
} }
@ -1703,7 +1703,7 @@ mod test {
let minor = (n % 1_000_000) / 1_000; let minor = (n % 1_000_000) / 1_000;
let patch = n % 1_000; let patch = n % 1_000;
assert!(version().contains(&format!("{}.{}.{}", major, minor, patch))); assert!(version().contains(&format!("{major}.{minor}.{patch}")));
} }
#[test] #[test]
@ -1810,7 +1810,7 @@ mod test {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self { match *self {
CustomError::SomeError => write!(f, "my custom error"), CustomError::SomeError => write!(f, "my custom error"),
CustomError::Sqlite(ref se) => write!(f, "my custom error: {}", se), CustomError::Sqlite(ref se) => write!(f, "my custom error: {se}"),
} }
} }
} }

View File

@ -37,7 +37,7 @@ impl Sql {
} else { } else {
Err(Error::SqliteFailure( Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("Invalid keyword \"{}\"", keyword)), Some(format!("Invalid keyword \"{keyword}\"")),
)) ))
} }
} }
@ -67,14 +67,14 @@ impl Sql {
ToSqlOutput::ZeroBlob(_) => { ToSqlOutput::ZeroBlob(_) => {
return Err(Error::SqliteFailure( return Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("Unsupported value \"{:?}\"", value)), Some(format!("Unsupported value \"{value:?}\"")),
)); ));
} }
#[cfg(feature = "array")] #[cfg(feature = "array")]
ToSqlOutput::Array(_) => { ToSqlOutput::Array(_) => {
return Err(Error::SqliteFailure( return Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("Unsupported value \"{:?}\"", value)), Some(format!("Unsupported value \"{value:?}\"")),
)); ));
} }
}; };
@ -92,7 +92,7 @@ impl Sql {
_ => { _ => {
return Err(Error::SqliteFailure( return Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("Unsupported value \"{:?}\"", value)), Some(format!("Unsupported value \"{value:?}\"")),
)); ));
} }
}; };

View File

@ -255,7 +255,7 @@ impl Savepoint<'_> {
name: T, name: T,
) -> Result<Savepoint<'_>> { ) -> Result<Savepoint<'_>> {
let name = name.into(); let name = name.into();
conn.execute_batch(&format!("SAVEPOINT {}", name)) conn.execute_batch(&format!("SAVEPOINT {name}"))
.map(|_| Savepoint { .map(|_| Savepoint {
conn, conn,
name, name,
@ -267,7 +267,7 @@ impl Savepoint<'_> {
#[inline] #[inline]
fn with_depth(conn: &Connection, depth: u32) -> Result<Savepoint<'_>> { fn with_depth(conn: &Connection, depth: u32) -> Result<Savepoint<'_>> {
let name = format!("_rusqlite_sp_{}", depth); let name = format!("_rusqlite_sp_{depth}");
Savepoint::with_depth_and_name(conn, depth, name) Savepoint::with_depth_and_name(conn, depth, name)
} }

View File

@ -52,7 +52,7 @@ impl fmt::Display for FromSqlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
FromSqlError::InvalidType => write!(f, "Invalid type"), FromSqlError::InvalidType => write!(f, "Invalid type"),
FromSqlError::OutOfRange(i) => write!(f, "Value {} out of range", i), FromSqlError::OutOfRange(i) => write!(f, "Value {i} out of range"),
FromSqlError::InvalidBlobSize { FromSqlError::InvalidBlobSize {
expected_size, expected_size,
blob_size, blob_size,

View File

@ -212,7 +212,7 @@ mod test {
let mut v = vec![]; let mut v = vec![];
for i in 0..1000 { for i in 0..1000 {
v.push(SqliteMallocString::from_str(&i.to_string()).into_raw()); v.push(SqliteMallocString::from_str(&i.to_string()).into_raw());
v.push(SqliteMallocString::from_str(&format!("abc {} 😀", i)).into_raw()); v.push(SqliteMallocString::from_str(&format!("abc {i} 😀")).into_raw());
} }
unsafe { unsafe {
for (i, s) in v.chunks_mut(2).enumerate() { for (i, s) in v.chunks_mut(2).enumerate() {
@ -224,7 +224,7 @@ mod test {
); );
assert_eq!( assert_eq!(
std::ffi::CStr::from_ptr(s1).to_str().unwrap(), std::ffi::CStr::from_ptr(s1).to_str().unwrap(),
&format!("abc {} 😀", i) &format!("abc {i} 😀")
); );
let _ = SqliteMallocString::from_raw(s0).unwrap(); let _ = SqliteMallocString::from_raw(s0).unwrap();
let _ = SqliteMallocString::from_raw(s1).unwrap(); let _ = SqliteMallocString::from_raw(s1).unwrap();

View File

@ -208,13 +208,13 @@ unsafe impl<'vtab> VTab<'vtab> for CsvTab {
let mut record = csv::ByteRecord::new(); let mut record = csv::ByteRecord::new();
if reader.read_byte_record(&mut record)? { if reader.read_byte_record(&mut record)? {
for (i, _) in record.iter().enumerate() { for (i, _) in record.iter().enumerate() {
cols.push(format!("c{}", i)); cols.push(format!("c{i}"));
} }
} }
} }
} else if let Some(n_col) = n_col { } else if let Some(n_col) = n_col {
for i in 0..n_col { for i in 0..n_col {
cols.push(format!("c{}", i)); cols.push(format!("c{i}"));
} }
} }

View File

@ -499,7 +499,7 @@ impl IndexInfo {
if collation.is_null() { if collation.is_null() {
return Err(Error::SqliteFailure( return Err(Error::SqliteFailure(
ffi::Error::new(ffi::SQLITE_MISUSE), ffi::Error::new(ffi::SQLITE_MISUSE),
Some(format!("{} is out of range", constraint_idx)), Some(format!("{constraint_idx} is out of range")),
)); ));
} }
Ok(unsafe { CStr::from_ptr(collation) }.to_str()?) Ok(unsafe { CStr::from_ptr(collation) }.to_str()?)
@ -924,7 +924,7 @@ pub fn parameter(c_slice: &[u8]) -> Result<(&str, &str)> {
return Ok((param, value)); return Ok((param, value));
} }
} }
Err(Error::ModuleError(format!("illegal argument: '{}'", arg))) Err(Error::ModuleError(format!("illegal argument: '{arg}'")))
} }
// FIXME copy/paste from function.rs // FIXME copy/paste from function.rs

View File

@ -153,7 +153,7 @@ impl<'vtab> CreateVTab<'vtab> for VTabLog {
impl<'vtab> UpdateVTab<'vtab> for VTabLog { impl<'vtab> UpdateVTab<'vtab> for VTabLog {
fn delete(&mut self, arg: ValueRef<'_>) -> Result<()> { fn delete(&mut self, arg: ValueRef<'_>) -> Result<()> {
println!("VTabLog::delete({}, {:?})", self.i_inst, arg); println!("VTabLog::delete({}, {arg:?})", self.i_inst);
Ok(()) Ok(())
} }
@ -246,7 +246,7 @@ unsafe impl VTabCursor for VTabLogCursor<'_> {
self.row_id self.row_id
) )
} else { } else {
format!("{}{}", i, self.row_id) format!("{i}{}", self.row_id)
}; };
println!( println!(
"VTabLogCursor::column(tab={}, cursor={}, i={}): {}", "VTabLogCursor::column(tab={}, cursor={}, i={}): {}",