mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 07:09:20 +08:00
Fix clippy warnings
This commit is contained in:
parent
a100adc1f2
commit
7dab08c4b2
@ -235,7 +235,7 @@ impl Connection {
|
|||||||
table.as_ptr(),
|
table.as_ptr(),
|
||||||
column.as_ptr(),
|
column.as_ptr(),
|
||||||
row_id,
|
row_id,
|
||||||
if read_only { 0 } else { 1 },
|
!read_only as std::os::raw::c_int,
|
||||||
&mut blob,
|
&mut blob,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -115,7 +115,7 @@ impl Connection {
|
|||||||
check(ffi::sqlite3_db_config(
|
check(ffi::sqlite3_db_config(
|
||||||
c.db(),
|
c.db(),
|
||||||
config as c_int,
|
config as c_int,
|
||||||
if new_val { 1 } else { 0 },
|
new_val as c_int,
|
||||||
&mut val,
|
&mut val,
|
||||||
))?;
|
))?;
|
||||||
Ok(val != 0)
|
Ok(val != 0)
|
||||||
|
@ -1260,7 +1260,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let path_string = path.to_str().unwrap();
|
let path_string = path.to_str().unwrap();
|
||||||
let db = Connection::open(&path_string)?;
|
let db = Connection::open(path_string)?;
|
||||||
let the_answer: Result<i64> = db.query_row("SELECT x FROM foo", [], |r| r.get(0));
|
let the_answer: Result<i64> = db.query_row("SELECT x FROM foo", [], |r| r.get(0));
|
||||||
|
|
||||||
assert_eq!(42i64, the_answer?);
|
assert_eq!(42i64, the_answer?);
|
||||||
|
@ -369,7 +369,7 @@ mod test {
|
|||||||
fn pragma() -> Result<()> {
|
fn pragma() -> Result<()> {
|
||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
let mut columns = Vec::new();
|
let mut columns = Vec::new();
|
||||||
db.pragma(None, "table_info", &"sqlite_master", |row| {
|
db.pragma(None, "table_info", "sqlite_master", |row| {
|
||||||
let column: String = row.get(1)?;
|
let column: String = row.get(1)?;
|
||||||
columns.push(column);
|
columns.push(column);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -412,8 +412,8 @@ mod test {
|
|||||||
journal_mode,
|
journal_mode,
|
||||||
);
|
);
|
||||||
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
|
||||||
let mode = db
|
let mode =
|
||||||
.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row.get::<_, String>(0))?;
|
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 param: &dyn crate::ToSql = &"OFF";
|
||||||
@ -448,7 +448,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn locking_mode() -> Result<()> {
|
fn locking_mode() -> Result<()> {
|
||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
let r = db.pragma_update(None, "locking_mode", &"exclusive");
|
let r = db.pragma_update(None, "locking_mode", "exclusive");
|
||||||
if cfg!(feature = "extra_check") {
|
if cfg!(feature = "extra_check") {
|
||||||
r.unwrap_err();
|
r.unwrap_err();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1409,7 +1409,7 @@ mod test {
|
|||||||
// dynamic slice:
|
// dynamic slice:
|
||||||
db.query_row(
|
db.query_row(
|
||||||
"SELECT ?1, ?2, ?3",
|
"SELECT ?1, ?2, ?3",
|
||||||
&[&1u8 as &dyn ToSql, &"one", &Some("one")],
|
[&1u8 as &dyn ToSql, &"one", &Some("one")],
|
||||||
|row| row.get::<_, u8>(0),
|
|row| row.get::<_, u8>(0),
|
||||||
)?;
|
)?;
|
||||||
// existing collection:
|
// existing collection:
|
||||||
@ -1494,12 +1494,12 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_utf16_conversion() -> Result<()> {
|
fn test_utf16_conversion() -> Result<()> {
|
||||||
let db = Connection::open_in_memory()?;
|
let db = Connection::open_in_memory()?;
|
||||||
db.pragma_update(None, "encoding", &"UTF-16le")?;
|
db.pragma_update(None, "encoding", "UTF-16le")?;
|
||||||
let encoding: String = db.pragma_query_value(None, "encoding", |row| row.get(0))?;
|
let encoding: String = db.pragma_query_value(None, "encoding", |row| row.get(0))?;
|
||||||
assert_eq!("UTF-16le", encoding);
|
assert_eq!("UTF-16le", encoding);
|
||||||
db.execute_batch("CREATE TABLE foo(x TEXT)")?;
|
db.execute_batch("CREATE TABLE foo(x TEXT)")?;
|
||||||
let expected = "テスト";
|
let expected = "テスト";
|
||||||
db.execute("INSERT INTO foo(x) VALUES (?)", &[&expected])?;
|
db.execute("INSERT INTO foo(x) VALUES (?)", [&expected])?;
|
||||||
let actual: String = db.query_row("SELECT x FROM foo", [], |row| row.get(0))?;
|
let actual: String = db.query_row("SELECT x FROM foo", [], |row| row.get(0))?;
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -244,7 +244,7 @@ mod test {
|
|||||||
{
|
{
|
||||||
for n in out_of_range {
|
for n in out_of_range {
|
||||||
let err = db
|
let err = db
|
||||||
.query_row("SELECT ?", &[n], |r| r.get::<_, T>(0))
|
.query_row("SELECT ?", [n], |r| r.get::<_, T>(0))
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
match err {
|
match err {
|
||||||
Error::IntegralValueOutOfRange(_, value) => assert_eq!(*n, value),
|
Error::IntegralValueOutOfRange(_, value) => assert_eq!(*n, value),
|
||||||
@ -254,7 +254,7 @@ mod test {
|
|||||||
for n in in_range {
|
for n in in_range {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*n,
|
*n,
|
||||||
db.query_row("SELECT ?", &[n], |r| r.get::<_, T>(0))
|
db.query_row("SELECT ?", [n], |r| r.get::<_, T>(0))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into()
|
.into()
|
||||||
);
|
);
|
||||||
|
@ -153,7 +153,7 @@ mod test {
|
|||||||
let db = checked_memory_handle()?;
|
let db = checked_memory_handle()?;
|
||||||
|
|
||||||
let v1234 = vec![1u8, 2, 3, 4];
|
let v1234 = vec![1u8, 2, 3, 4];
|
||||||
db.execute("INSERT INTO foo(b) VALUES (?)", &[&v1234])?;
|
db.execute("INSERT INTO foo(b) VALUES (?)", [&v1234])?;
|
||||||
|
|
||||||
let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0))?;
|
let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0))?;
|
||||||
assert_eq!(v, v1234);
|
assert_eq!(v, v1234);
|
||||||
@ -165,7 +165,7 @@ mod test {
|
|||||||
let db = checked_memory_handle()?;
|
let db = checked_memory_handle()?;
|
||||||
|
|
||||||
let empty = vec![];
|
let empty = vec![];
|
||||||
db.execute("INSERT INTO foo(b) VALUES (?)", &[&empty])?;
|
db.execute("INSERT INTO foo(b) VALUES (?)", [&empty])?;
|
||||||
|
|
||||||
let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0))?;
|
let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0))?;
|
||||||
assert_eq!(v, empty);
|
assert_eq!(v, empty);
|
||||||
@ -177,7 +177,7 @@ mod test {
|
|||||||
let db = checked_memory_handle()?;
|
let db = checked_memory_handle()?;
|
||||||
|
|
||||||
let s = "hello, world!";
|
let s = "hello, world!";
|
||||||
db.execute("INSERT INTO foo(t) VALUES (?)", &[&s])?;
|
db.execute("INSERT INTO foo(t) VALUES (?)", [&s])?;
|
||||||
|
|
||||||
let from: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0))?;
|
let from: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0))?;
|
||||||
assert_eq!(from, s);
|
assert_eq!(from, s);
|
||||||
@ -216,8 +216,8 @@ mod test {
|
|||||||
let s = Some("hello, world!");
|
let s = Some("hello, world!");
|
||||||
let b = Some(vec![1u8, 2, 3, 4]);
|
let b = Some(vec![1u8, 2, 3, 4]);
|
||||||
|
|
||||||
db.execute("INSERT INTO foo(t) VALUES (?)", &[&s])?;
|
db.execute("INSERT INTO foo(t) VALUES (?)", [&s])?;
|
||||||
db.execute("INSERT INTO foo(b) VALUES (?)", &[&b])?;
|
db.execute("INSERT INTO foo(b) VALUES (?)", [&b])?;
|
||||||
|
|
||||||
let mut stmt = db.prepare("SELECT t, b FROM foo ORDER BY ROWID ASC")?;
|
let mut stmt = db.prepare("SELECT t, b FROM foo ORDER BY ROWID ASC")?;
|
||||||
let mut rows = stmt.query([])?;
|
let mut rows = stmt.query([])?;
|
||||||
|
@ -41,7 +41,7 @@ mod test {
|
|||||||
let data: serde_json::Value = serde_json::from_str(json).unwrap();
|
let data: serde_json::Value = serde_json::from_str(json).unwrap();
|
||||||
db.execute(
|
db.execute(
|
||||||
"INSERT INTO foo (t, b) VALUES (?, ?)",
|
"INSERT INTO foo (t, b) VALUES (?, ?)",
|
||||||
&[&data as &dyn ToSql, &json.as_bytes()],
|
[&data as &dyn ToSql, &json.as_bytes()],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let t: serde_json::Value = db.query_row("SELECT t FROM foo", [], |r| r.get(0))?;
|
let t: serde_json::Value = db.query_row("SELECT t FROM foo", [], |r| r.get(0))?;
|
||||||
|
@ -208,7 +208,7 @@ mod test {
|
|||||||
{
|
{
|
||||||
let mut stmt = db.prepare("SELECT value from rarray(?);")?;
|
let mut stmt = db.prepare("SELECT value from rarray(?);")?;
|
||||||
|
|
||||||
let rows = stmt.query_map(&[&ptr], |row| row.get::<_, i64>(0))?;
|
let rows = stmt.query_map([&ptr], |row| row.get::<_, i64>(0))?;
|
||||||
assert_eq!(2, Rc::strong_count(&ptr));
|
assert_eq!(2, Rc::strong_count(&ptr));
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for (i, value) in rows.enumerate() {
|
for (i, value) in rows.enumerate() {
|
||||||
|
@ -457,7 +457,7 @@ impl IndexInfo {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_order_by_consumed(&mut self, order_by_consumed: bool) {
|
pub fn set_order_by_consumed(&mut self, order_by_consumed: bool) {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*self.0).orderByConsumed = if order_by_consumed { 1 } else { 0 };
|
(*self.0).orderByConsumed = order_by_consumed as c_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ impl IndexConstraintUsage<'_> {
|
|||||||
/// if `omit`, do not code a test for this constraint
|
/// if `omit`, do not code a test for this constraint
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_omit(&mut self, omit: bool) {
|
pub fn set_omit(&mut self, omit: bool) {
|
||||||
self.0.omit = if omit { 1 } else { 0 };
|
self.0.omit = omit as std::os::raw::c_uchar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user