Deprecate NO_PARAMS in favor of passing an empty array

This commit is contained in:
Thom Chiovoloni 2020-11-03 01:32:46 -08:00
parent 2461ebf62f
commit 22121772a2
23 changed files with 126 additions and 210 deletions

View File

@ -1,10 +1,10 @@
use bencher::{benchmark_group, benchmark_main, Bencher}; use bencher::{benchmark_group, benchmark_main, Bencher};
use rusqlite::{Connection, NO_PARAMS}; use rusqlite::Connection;
fn bench_execute(b: &mut Bencher) { fn bench_execute(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
let sql = "PRAGMA user_version=1"; let sql = "PRAGMA user_version=1";
b.iter(|| db.execute(sql, NO_PARAMS).unwrap()); b.iter(|| db.execute(sql, []).unwrap());
} }
fn bench_execute_batch(b: &mut Bencher) { fn bench_execute_batch(b: &mut Bencher) {

View File

@ -306,7 +306,7 @@ impl Drop for Backup<'_, '_> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::Backup; use super::Backup;
use crate::{Connection, DatabaseName, NO_PARAMS}; use crate::{Connection, DatabaseName};
use std::time::Duration; use std::time::Duration;
#[test] #[test]
@ -326,7 +326,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT x FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT x FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42, the_answer); assert_eq!(42, the_answer);
@ -340,7 +340,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42 + 43, the_answer); assert_eq!(42 + 43, the_answer);
} }
@ -364,7 +364,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT x FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT x FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42, the_answer); assert_eq!(42, the_answer);
@ -380,7 +380,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42 + 43, the_answer); assert_eq!(42 + 43, the_answer);
} }
@ -409,7 +409,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT x FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT x FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42, the_answer); assert_eq!(42, the_answer);
@ -429,7 +429,7 @@ mod test {
} }
let the_answer: i64 = dst let the_answer: i64 = dst
.query_row("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) .query_row("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(42 + 43, the_answer); assert_eq!(42 + 43, the_answer);
} }

View File

@ -101,7 +101,7 @@
//! //!
//! ```rust //! ```rust
//! # use rusqlite::blob::ZeroBlob; //! # use rusqlite::blob::ZeroBlob;
//! # use rusqlite::{Connection, DatabaseName, NO_PARAMS}; //! # use rusqlite::{Connection, DatabaseName};
//! # use std::error::Error; //! # use std::error::Error;
//! # use std::io::{Read, Seek, SeekFrom, Write}; //! # use std::io::{Read, Seek, SeekFrom, Write};
//! # fn main() -> Result<(), Box<dyn Error>> { //! # fn main() -> Result<(), Box<dyn Error>> {
@ -113,7 +113,7 @@
//! // must be done via SQL. //! // must be done via SQL.
//! db.execute( //! db.execute(
//! "INSERT INTO test_table (content) VALUES (ZEROBLOB(10))", //! "INSERT INTO test_table (content) VALUES (ZEROBLOB(10))",
//! NO_PARAMS, //! [],
//! )?; //! )?;
//! //!
//! // Get the row id off the BLOB we just inserted. //! // Get the row id off the BLOB we just inserted.
@ -154,7 +154,7 @@
//! //!
//! ```rust //! ```rust
//! # use rusqlite::blob::ZeroBlob; //! # use rusqlite::blob::ZeroBlob;
//! # use rusqlite::{Connection, DatabaseName, NO_PARAMS}; //! # use rusqlite::{Connection, DatabaseName};
//! # use std::error::Error; //! # use std::error::Error;
//! # fn main() -> Result<(), Box<dyn Error>> { //! # fn main() -> Result<(), Box<dyn Error>> {
//! let db = Connection::open_in_memory()?; //! let db = Connection::open_in_memory()?;
@ -164,7 +164,7 @@
//! // must be done via SQL. //! // must be done via SQL.
//! db.execute( //! db.execute(
//! "INSERT INTO test_table (content) VALUES (ZEROBLOB(10))", //! "INSERT INTO test_table (content) VALUES (ZEROBLOB(10))",
//! NO_PARAMS, //! [],
//! )?; //! )?;
//! // Get the row id off the blob we just inserted. //! // Get the row id off the blob we just inserted.
//! let rowid = db.last_insert_rowid(); //! let rowid = db.last_insert_rowid();

View File

@ -194,7 +194,7 @@ impl<'conn> Blob<'conn> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{Connection, DatabaseName, NO_PARAMS}; use crate::{Connection, DatabaseName};
// to ensure we don't modify seek pos // to ensure we don't modify seek pos
use std::io::Seek as _; use std::io::Seek as _;
@ -203,10 +203,7 @@ mod test {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
db.execute_batch("CREATE TABLE test_table(content BLOB);") db.execute_batch("CREATE TABLE test_table(content BLOB);")
.unwrap(); .unwrap();
db.execute( db.execute("INSERT INTO test_table(content) VALUES (ZEROBLOB(10))", [])
"INSERT INTO test_table(content) VALUES (ZEROBLOB(10))",
NO_PARAMS,
)
.unwrap(); .unwrap();
let rowid = db.last_insert_rowid(); let rowid = db.last_insert_rowid();

View File

@ -82,7 +82,7 @@ mod test {
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use crate::{Connection, Error, ErrorCode, Result, TransactionBehavior, NO_PARAMS}; use crate::{Connection, Error, ErrorCode, Result, TransactionBehavior};
#[test] #[test]
fn test_default_busy() { fn test_default_busy() {
@ -94,7 +94,7 @@ mod test {
.transaction_with_behavior(TransactionBehavior::Exclusive) .transaction_with_behavior(TransactionBehavior::Exclusive)
.unwrap(); .unwrap();
let db2 = Connection::open(&path).unwrap(); let db2 = Connection::open(&path).unwrap();
let r: Result<()> = db2.query_row("PRAGMA schema_version", NO_PARAMS, |_| unreachable!()); let r: Result<()> = db2.query_row("PRAGMA schema_version", [], |_| unreachable!());
match r.unwrap_err() { match r.unwrap_err() {
Error::SqliteFailure(err, _) => { Error::SqliteFailure(err, _) => {
assert_eq!(err.code, ErrorCode::DatabaseBusy); assert_eq!(err.code, ErrorCode::DatabaseBusy);
@ -126,9 +126,7 @@ mod test {
assert_eq!(tx.recv().unwrap(), 1); assert_eq!(tx.recv().unwrap(), 1);
let _ = db2 let _ = db2
.query_row("PRAGMA schema_version", NO_PARAMS, |row| { .query_row("PRAGMA schema_version", [], |row| row.get::<_, i32>(0))
row.get::<_, i32>(0)
})
.expect("unexpected error"); .expect("unexpected error");
child.join().unwrap(); child.join().unwrap();
@ -163,9 +161,7 @@ mod test {
assert_eq!(tx.recv().unwrap(), 1); assert_eq!(tx.recv().unwrap(), 1);
let _ = db2 let _ = db2
.query_row("PRAGMA schema_version", NO_PARAMS, |row| { .query_row("PRAGMA schema_version", [], |row| row.get::<_, i32>(0))
row.get::<_, i32>(0)
})
.expect("unexpected error"); .expect("unexpected error");
assert_eq!(CALLED.load(Ordering::Relaxed), true); assert_eq!(CALLED.load(Ordering::Relaxed), true);

View File

@ -164,7 +164,7 @@ impl StatementCache {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::StatementCache; use super::StatementCache;
use crate::{Connection, NO_PARAMS}; use crate::Connection;
use fallible_iterator::FallibleIterator; use fallible_iterator::FallibleIterator;
impl StatementCache { impl StatementCache {
@ -193,20 +193,14 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
@ -224,10 +218,7 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
@ -237,10 +228,7 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
@ -248,10 +236,7 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
} }
@ -265,10 +250,7 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
stmt.discard(); stmt.discard();
} }
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
@ -291,7 +273,7 @@ mod test {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!( assert_eq!(
Ok(Some(1i32)), Ok(Some(1i32)),
stmt.query(NO_PARAMS).unwrap().map(|r| r.get(0)).next() stmt.query([]).unwrap().map(|r| r.get(0)).next()
); );
} }
@ -307,7 +289,7 @@ mod test {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!( assert_eq!(
Ok(Some((1i32, 2i32))), Ok(Some((1i32, 2i32))),
stmt.query(NO_PARAMS) stmt.query([])
.unwrap() .unwrap()
.map(|r| Ok((r.get(0)?, r.get(1)?))) .map(|r| Ok((r.get(0)?, r.get(1)?)))
.next() .next()
@ -334,20 +316,14 @@ mod test {
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
{ {
let mut stmt = db.prepare_cached(sql).unwrap(); let mut stmt = db.prepare_cached(sql).unwrap();
assert_eq!(0, cache.len()); assert_eq!(0, cache.len());
assert_eq!( assert_eq!(0, stmt.query_row([], |r| r.get::<_, i64>(0)).unwrap());
0,
stmt.query_row(NO_PARAMS, |r| r.get::<_, i64>(0)).unwrap()
);
} }
assert_eq!(1, cache.len()); assert_eq!(1, cache.len());
} }

View File

@ -157,7 +157,7 @@ impl InnerConnection {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{Connection, Result, NO_PARAMS}; use crate::{Connection, Result};
use fallible_streaming_iterator::FallibleStreamingIterator; use fallible_streaming_iterator::FallibleStreamingIterator;
use std::cmp::Ordering; use std::cmp::Ordering;
use unicase::UniCase; use unicase::UniCase;
@ -185,7 +185,7 @@ mod test {
let mut stmt = db let mut stmt = db
.prepare("SELECT DISTINCT bar COLLATE unicase FROM foo ORDER BY 1") .prepare("SELECT DISTINCT bar COLLATE unicase FROM foo ORDER BY 1")
.unwrap(); .unwrap();
let rows = stmt.query(NO_PARAMS).unwrap(); let rows = stmt.query([]).unwrap();
assert_eq!(rows.count().unwrap(), 1); assert_eq!(rows.count().unwrap(), 1);
} }

View File

@ -194,7 +194,7 @@ mod test {
) )
.unwrap(); .unwrap();
let mut stmt = db.prepare("SELECT x as renamed, y FROM foo").unwrap(); let mut stmt = db.prepare("SELECT x as renamed, y FROM foo").unwrap();
let mut rows = stmt.query(crate::NO_PARAMS).unwrap(); let mut rows = stmt.query([]).unwrap();
let row = rows.next().unwrap().unwrap(); let row = rows.next().unwrap().unwrap();
match row.get::<_, String>(0).unwrap_err() { match row.get::<_, String>(0).unwrap_err() {
Error::InvalidColumnType(idx, name, ty) => { Error::InvalidColumnType(idx, name, ty) => {

View File

@ -11,7 +11,7 @@
//! ```rust //! ```rust
//! use regex::Regex; //! use regex::Regex;
//! use rusqlite::functions::FunctionFlags; //! use rusqlite::functions::FunctionFlags;
//! use rusqlite::{Connection, Error, Result, NO_PARAMS}; //! use rusqlite::{Connection, Error, Result};
//! use std::sync::Arc; //! use std::sync::Arc;
//! type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>; //! type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
//! //!
@ -745,7 +745,7 @@ mod test {
#[cfg(feature = "window")] #[cfg(feature = "window")]
use crate::functions::WindowAggregate; use crate::functions::WindowAggregate;
use crate::functions::{Aggregate, Context, FunctionFlags}; use crate::functions::{Aggregate, Context, FunctionFlags};
use crate::{Connection, Error, Result, NO_PARAMS}; use crate::{Connection, Error, Result};
fn half(ctx: &Context<'_>) -> Result<c_double> { fn half(ctx: &Context<'_>) -> Result<c_double> {
assert_eq!(ctx.len(), 1, "called with unexpected number of arguments"); assert_eq!(ctx.len(), 1, "called with unexpected number of arguments");
@ -763,7 +763,7 @@ mod test {
half, half,
) )
.unwrap(); .unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", NO_PARAMS, |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", [], |r| r.get(0));
assert!((3f64 - result.unwrap()).abs() < EPSILON); assert!((3f64 - result.unwrap()).abs() < EPSILON);
} }
@ -778,11 +778,11 @@ mod test {
half, half,
) )
.unwrap(); .unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", NO_PARAMS, |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", [], |r| r.get(0));
assert!((3f64 - result.unwrap()).abs() < EPSILON); assert!((3f64 - result.unwrap()).abs() < EPSILON);
db.remove_function("half", 1).unwrap(); db.remove_function("half", 1).unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", NO_PARAMS, |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", [], |r| r.get(0));
assert!(result.is_err()); assert!(result.is_err());
} }
@ -830,15 +830,13 @@ mod test {
.unwrap(); .unwrap();
let result: Result<bool> = let result: Result<bool> =
db.query_row("SELECT regexp('l.s[aeiouy]', 'lisa')", NO_PARAMS, |r| { db.query_row("SELECT regexp('l.s[aeiouy]', 'lisa')", [], |r| r.get(0));
r.get(0)
});
assert_eq!(true, result.unwrap()); assert_eq!(true, result.unwrap());
let result: Result<i64> = db.query_row( let result: Result<i64> = db.query_row(
"SELECT COUNT(*) FROM foo WHERE regexp('l.s[aeiouy]', x) == 1", "SELECT COUNT(*) FROM foo WHERE regexp('l.s[aeiouy]', x) == 1",
NO_PARAMS, [],
|r| r.get(0), |r| r.get(0),
); );
@ -870,7 +868,7 @@ mod test {
("onetwo", "SELECT my_concat('one', 'two')"), ("onetwo", "SELECT my_concat('one', 'two')"),
("abc", "SELECT my_concat('a', 'b', 'c')"), ("abc", "SELECT my_concat('a', 'b', 'c')"),
] { ] {
let result: String = db.query_row(query, NO_PARAMS, |r| r.get(0)).unwrap(); let result: String = db.query_row(query, [], |r| r.get(0)).unwrap();
assert_eq!(expected, result); assert_eq!(expected, result);
} }
} }
@ -892,7 +890,7 @@ mod test {
let res: bool = db let res: bool = db
.query_row( .query_row(
"SELECT example(0, i) FROM (SELECT 0 as i UNION SELECT 1)", "SELECT example(0, i) FROM (SELECT 0 as i UNION SELECT 1)",
NO_PARAMS, [],
|r| r.get(0), |r| r.get(0),
) )
.unwrap(); .unwrap();
@ -946,17 +944,17 @@ mod test {
// sum should return NULL when given no columns (contrast with count below) // sum should return NULL when given no columns (contrast with count below)
let no_result = "SELECT my_sum(i) FROM (SELECT 2 AS i WHERE 1 <> 1)"; let no_result = "SELECT my_sum(i) FROM (SELECT 2 AS i WHERE 1 <> 1)";
let result: Option<i64> = db.query_row(no_result, NO_PARAMS, |r| r.get(0)).unwrap(); let result: Option<i64> = db.query_row(no_result, [], |r| r.get(0)).unwrap();
assert!(result.is_none()); assert!(result.is_none());
let single_sum = "SELECT my_sum(i) FROM (SELECT 2 AS i UNION ALL SELECT 2)"; let single_sum = "SELECT my_sum(i) FROM (SELECT 2 AS i UNION ALL SELECT 2)";
let result: i64 = db.query_row(single_sum, NO_PARAMS, |r| r.get(0)).unwrap(); let result: i64 = db.query_row(single_sum, [], |r| r.get(0)).unwrap();
assert_eq!(4, result); assert_eq!(4, result);
let dual_sum = "SELECT my_sum(i), my_sum(j) FROM (SELECT 2 AS i, 1 AS j UNION ALL SELECT \ let dual_sum = "SELECT my_sum(i), my_sum(j) FROM (SELECT 2 AS i, 1 AS j UNION ALL SELECT \
2, 1)"; 2, 1)";
let result: (i64, i64) = db let result: (i64, i64) = db
.query_row(dual_sum, NO_PARAMS, |r| Ok((r.get(0)?, r.get(1)?))) .query_row(dual_sum, [], |r| Ok((r.get(0)?, r.get(1)?)))
.unwrap(); .unwrap();
assert_eq!((4, 2), result); assert_eq!((4, 2), result);
} }
@ -974,11 +972,11 @@ mod test {
// count should return 0 when given no columns (contrast with sum above) // count should return 0 when given no columns (contrast with sum above)
let no_result = "SELECT my_count(i) FROM (SELECT 2 AS i WHERE 1 <> 1)"; let no_result = "SELECT my_count(i) FROM (SELECT 2 AS i WHERE 1 <> 1)";
let result: i64 = db.query_row(no_result, NO_PARAMS, |r| r.get(0)).unwrap(); let result: i64 = db.query_row(no_result, [], |r| r.get(0)).unwrap();
assert_eq!(result, 0); assert_eq!(result, 0);
let single_sum = "SELECT my_count(i) FROM (SELECT 2 AS i UNION ALL SELECT 2)"; let single_sum = "SELECT my_count(i) FROM (SELECT 2 AS i UNION ALL SELECT 2)";
let result: i64 = db.query_row(single_sum, NO_PARAMS, |r| r.get(0)).unwrap(); let result: i64 = db.query_row(single_sum, [], |r| r.get(0)).unwrap();
assert_eq!(2, result); assert_eq!(2, result);
} }
@ -1027,7 +1025,7 @@ mod test {
.unwrap(); .unwrap();
let results: Vec<(String, i64)> = stmt let results: Vec<(String, i64)> = stmt
.query(NO_PARAMS) .query([])
.unwrap() .unwrap()
.map(|row| Ok((row.get("x")?, row.get("sum_y")?))) .map(|row| Ok((row.get("x")?, row.get("sum_y")?)))
.collect() .collect()

View File

@ -133,12 +133,8 @@ const STATEMENT_CACHE_DEFAULT_CAPACITY: usize = 16;
/// ///
/// [sqlite-varparam]: https://sqlite.org/lang_expr.html#varparam /// [sqlite-varparam]: https://sqlite.org/lang_expr.html#varparam
/// ///
/// Note that for most uses this is no longer necessary, and an empty array /// This is deprecated in favor of using an empty array literal.
/// should be used instead. #[deprecated = "Use an empty array instead; `stmt.execute(NO_PARAMS)` => `stmt.execute([])`"]
///
/// That is, in previous rusqlite releases you would need to do
/// `conn.execute(rusqlite::NO_PARAMS)`, however you can now do
/// `conn.execute([])` which is equivalent.
pub const NO_PARAMS: &[&dyn ToSql] = &[]; pub const NO_PARAMS: &[&dyn ToSql] = &[];
/// A macro making it more convenient to pass heterogeneous or long lists of /// A macro making it more convenient to pass heterogeneous or long lists of
@ -165,7 +161,7 @@ pub const NO_PARAMS: &[&dyn ToSql] = &[];
#[macro_export] #[macro_export]
macro_rules! params { macro_rules! params {
() => { () => {
$crate::NO_PARAMS (&[] as &[&dyn $crate::ToSql])
}; };
($($param:expr),+ $(,)?) => { ($($param:expr),+ $(,)?) => {
&[$(&$param as &dyn $crate::ToSql),+] as &[&dyn $crate::ToSql] &[$(&$param as &dyn $crate::ToSql),+] as &[&dyn $crate::ToSql]

View File

@ -129,7 +129,7 @@ use sealed::Sealed;
/// ///
/// You can just use an empty array literal for no params. The /// You can just use an empty array literal for no params. The
/// `rusqlite::NO_PARAMS` constant which was so common in previous versions of /// `rusqlite::NO_PARAMS` constant which was so common in previous versions of
/// this library is no longer needed. /// this library is no longer needed (and is now deprecated).
/// ///
/// ### Example (no parameters) /// ### Example (no parameters)
/// ///

View File

@ -5,7 +5,7 @@ use std::ops::Deref;
use crate::error::Error; use crate::error::Error;
use crate::ffi; use crate::ffi;
use crate::types::{ToSql, ToSqlOutput, ValueRef}; use crate::types::{ToSql, ToSqlOutput, ValueRef};
use crate::{Connection, DatabaseName, Result, Row, NO_PARAMS}; use crate::{Connection, DatabaseName, Result, Row};
pub struct Sql { pub struct Sql {
buf: String, buf: String,
@ -176,7 +176,7 @@ impl Connection {
{ {
let mut query = Sql::new(); let mut query = Sql::new();
query.push_pragma(schema_name, pragma_name)?; query.push_pragma(schema_name, pragma_name)?;
self.query_row(&query, NO_PARAMS, f) self.query_row(&query, [], f)
} }
/// Query the current rows/values of `pragma_name`. /// Query the current rows/values of `pragma_name`.
@ -195,7 +195,7 @@ impl Connection {
let mut query = Sql::new(); let mut query = Sql::new();
query.push_pragma(schema_name, pragma_name)?; query.push_pragma(schema_name, pragma_name)?;
let mut stmt = self.prepare(&query)?; let mut stmt = self.prepare(&query)?;
let mut rows = stmt.query(NO_PARAMS)?; let mut rows = stmt.query([])?;
while let Some(result_row) = rows.next()? { while let Some(result_row) = rows.next()? {
let row = result_row; let row = result_row;
f(&row)?; f(&row)?;
@ -231,7 +231,7 @@ impl Connection {
sql.push_value(pragma_value)?; sql.push_value(pragma_value)?;
sql.close_brace(); sql.close_brace();
let mut stmt = self.prepare(&sql)?; let mut stmt = self.prepare(&sql)?;
let mut rows = stmt.query(NO_PARAMS)?; let mut rows = stmt.query([])?;
while let Some(result_row) = rows.next()? { while let Some(result_row) = rows.next()? {
let row = result_row; let row = result_row;
f(&row)?; f(&row)?;
@ -279,7 +279,7 @@ impl Connection {
// The two syntaxes yield identical results. // The two syntaxes yield identical results.
sql.push_equal_sign(); sql.push_equal_sign();
sql.push_value(pragma_value)?; sql.push_value(pragma_value)?;
self.query_row(&sql, NO_PARAMS, f) self.query_row(&sql, [], f)
} }
} }
@ -328,15 +328,11 @@ mod test {
#[test] #[test]
#[cfg(feature = "modern_sqlite")] #[cfg(feature = "modern_sqlite")]
fn pragma_func_query_value() { fn pragma_func_query_value() {
use crate::NO_PARAMS;
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
let user_version: i32 = db let user_version: i32 = db
.query_row( .query_row("SELECT user_version FROM pragma_user_version", [], |row| {
"SELECT user_version FROM pragma_user_version", row.get(0)
NO_PARAMS, })
|row| row.get(0),
)
.unwrap(); .unwrap();
assert_eq!(0, user_version); assert_eq!(0, user_version);
} }

View File

@ -40,9 +40,9 @@ impl<'stmt> Rows<'stmt> {
/// implements `FallibleIterator`. /// implements `FallibleIterator`.
/// ```rust,no_run /// ```rust,no_run
/// use fallible_iterator::FallibleIterator; /// use fallible_iterator::FallibleIterator;
/// # use rusqlite::{Result, Statement, NO_PARAMS}; /// # use rusqlite::{Result, Statement};
/// fn query(stmt: &mut Statement) -> Result<Vec<i64>> { /// fn query(stmt: &mut Statement) -> Result<Vec<i64>> {
/// let rows = stmt.query(NO_PARAMS)?; /// let rows = stmt.query([])?;
/// rows.map(|r| r.get(0)).collect() /// rows.map(|r| r.get(0)).collect()
/// } /// }
/// ``` /// ```
@ -193,9 +193,9 @@ where
/// While these iterators cannot be used with Rust `for` loops, `while let` /// While these iterators cannot be used with Rust `for` loops, `while let`
/// loops offer a similar level of ergonomics: /// loops offer a similar level of ergonomics:
/// ```rust,no_run /// ```rust,no_run
/// # use rusqlite::{Result, Statement, NO_PARAMS}; /// # use rusqlite::{Result, Statement};
/// fn query(stmt: &mut Statement) -> Result<()> { /// fn query(stmt: &mut Statement) -> Result<()> {
/// let mut rows = stmt.query(NO_PARAMS)?; /// let mut rows = stmt.query([])?;
/// while let Some(row) = rows.next()? { /// while let Some(row) = rows.next()? {
/// // scan columns value /// // scan columns value
/// } /// }

View File

@ -909,7 +909,7 @@ pub enum StatementStatus {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::types::ToSql; use crate::types::ToSql;
use crate::{params_from_iter, Connection, Error, Result, NO_PARAMS}; use crate::{params_from_iter, Connection, Error, Result};
#[test] #[test]
#[allow(deprecated)] #[allow(deprecated)]
@ -1188,9 +1188,7 @@ mod test {
stmt.execute(&[(":y", &"two")]).unwrap(); stmt.execute(&[(":y", &"two")]).unwrap();
let result: String = db let result: String = db
.query_row("SELECT x FROM test WHERE y = 'two'", NO_PARAMS, |row| { .query_row("SELECT x FROM test WHERE y = 'two'", [], |row| row.get(0))
row.get(0)
})
.unwrap(); .unwrap();
assert_eq!(result, "one"); assert_eq!(result, "one");
} }
@ -1297,7 +1295,7 @@ mod test {
END;"; END;";
db.execute_batch(sql).unwrap(); db.execute_batch(sql).unwrap();
let mut stmt = db.prepare("SELECT y as Y FROM foo").unwrap(); let mut stmt = db.prepare("SELECT y as Y FROM foo").unwrap();
let y: Result<i64> = stmt.query_row(NO_PARAMS, |r| r.get("y")); let y: Result<i64> = stmt.query_row([], |r| r.get("y"));
assert_eq!(3i64, y.unwrap()); assert_eq!(3i64, y.unwrap());
} }
@ -1366,7 +1364,7 @@ mod test {
assert!(stmt.parameter_index("test").is_ok()); assert!(stmt.parameter_index("test").is_ok());
assert!(stmt.step().is_err()); assert!(stmt.step().is_err());
stmt.reset(); stmt.reset();
assert!(stmt.execute(NO_PARAMS).is_err()); assert!(stmt.execute([]).is_err());
} }
#[test] #[test]
@ -1402,7 +1400,7 @@ mod test {
db.execute("INSERT INTO foo(x) VALUES (?)", &[&expected]) db.execute("INSERT INTO foo(x) VALUES (?)", &[&expected])
.unwrap(); .unwrap();
let actual: String = db let actual: String = db
.query_row("SELECT x FROM foo", NO_PARAMS, |row| row.get(0)) .query_row("SELECT x FROM foo", [], |row| row.get(0))
.unwrap(); .unwrap();
assert_eq!(expected, actual); assert_eq!(expected, actual);
} }

View File

@ -467,7 +467,7 @@ impl Connection {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::DropBehavior; use super::DropBehavior;
use crate::{Connection, Error, NO_PARAMS}; use crate::{Connection, Error};
fn checked_memory_handle() -> Connection { fn checked_memory_handle() -> Connection {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
@ -492,7 +492,7 @@ mod test {
let tx = db.transaction().unwrap(); let tx = db.transaction().unwrap();
assert_eq!( assert_eq!(
2i32, 2i32,
tx.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) tx.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap() .unwrap()
); );
} }
@ -531,7 +531,7 @@ mod test {
assert_eq!( assert_eq!(
2i32, 2i32,
db.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) db.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap() .unwrap()
); );
} }
@ -559,7 +559,7 @@ mod test {
let tx = db.transaction().unwrap(); let tx = db.transaction().unwrap();
assert_eq!( assert_eq!(
6i32, 6i32,
tx.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) tx.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap() .unwrap()
); );
} }
@ -666,7 +666,7 @@ mod test {
fn assert_current_sum(x: i32, conn: &Connection) { fn assert_current_sum(x: i32, conn: &Connection) {
let i = conn let i = conn
.query_row::<i32, _, _>("SELECT SUM(x) FROM foo", NO_PARAMS, |r| r.get(0)) .query_row::<i32, _, _>("SELECT SUM(x) FROM foo", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(x, i); assert_eq!(x, i);
} }

View File

@ -128,7 +128,7 @@ impl FromSql for DateTime<Local> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{Connection, Result, NO_PARAMS}; use crate::{Connection, Result};
use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc}; use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
fn checked_memory_handle() -> Connection { fn checked_memory_handle() -> Connection {
@ -145,13 +145,9 @@ mod test {
db.execute("INSERT INTO foo (t) VALUES (?)", &[&date]) db.execute("INSERT INTO foo (t) VALUES (?)", &[&date])
.unwrap(); .unwrap();
let s: String = db let s: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!("2016-02-23", s); assert_eq!("2016-02-23", s);
let t: NaiveDate = db let t: NaiveDate = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(date, t); assert_eq!(date, t);
} }
@ -162,13 +158,9 @@ mod test {
db.execute("INSERT INTO foo (t) VALUES (?)", &[&time]) db.execute("INSERT INTO foo (t) VALUES (?)", &[&time])
.unwrap(); .unwrap();
let s: String = db let s: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!("23:56:04", s); assert_eq!("23:56:04", s);
let v: NaiveTime = db let v: NaiveTime = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(time, v); assert_eq!(time, v);
} }
@ -182,20 +174,13 @@ mod test {
db.execute("INSERT INTO foo (t) VALUES (?)", &[&dt]) db.execute("INSERT INTO foo (t) VALUES (?)", &[&dt])
.unwrap(); .unwrap();
let s: String = db let s: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!("2016-02-23T23:56:04", s); assert_eq!("2016-02-23T23:56:04", s);
let v: NaiveDateTime = db let v: NaiveDateTime = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(dt, v); assert_eq!(dt, v);
db.execute("UPDATE foo set b = datetime(t)", NO_PARAMS) db.execute("UPDATE foo set b = datetime(t)", []).unwrap(); // "YYYY-MM-DD HH:MM:SS"
.unwrap(); // "YYYY-MM-DD HH:MM:SS" let hms: NaiveDateTime = db.query_row("SELECT b FROM foo", [], |r| r.get(0)).unwrap();
let hms: NaiveDateTime = db
.query_row("SELECT b FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(dt, hms); assert_eq!(dt, hms);
} }
@ -210,30 +195,24 @@ mod test {
db.execute("INSERT INTO foo (t) VALUES (?)", &[&utc]) db.execute("INSERT INTO foo (t) VALUES (?)", &[&utc])
.unwrap(); .unwrap();
let s: String = db let s: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!("2016-02-23T23:56:04.789+00:00", s); assert_eq!("2016-02-23T23:56:04.789+00:00", s);
let v1: DateTime<Utc> = db let v1: DateTime<Utc> = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(utc, v1); assert_eq!(utc, v1);
let v2: DateTime<Utc> = db let v2: DateTime<Utc> = db
.query_row("SELECT '2016-02-23 23:56:04.789'", NO_PARAMS, |r| r.get(0)) .query_row("SELECT '2016-02-23 23:56:04.789'", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(utc, v2); assert_eq!(utc, v2);
let v3: DateTime<Utc> = db let v3: DateTime<Utc> = db
.query_row("SELECT '2016-02-23 23:56:04'", NO_PARAMS, |r| r.get(0)) .query_row("SELECT '2016-02-23 23:56:04'", [], |r| r.get(0))
.unwrap(); .unwrap();
assert_eq!(utc - Duration::milliseconds(789), v3); assert_eq!(utc - Duration::milliseconds(789), v3);
let v4: DateTime<Utc> = db let v4: DateTime<Utc> = db
.query_row("SELECT '2016-02-23 23:56:04.789+00:00'", NO_PARAMS, |r| { .query_row("SELECT '2016-02-23 23:56:04.789+00:00'", [], |r| r.get(0))
r.get(0)
})
.unwrap(); .unwrap();
assert_eq!(utc, v4); assert_eq!(utc, v4);
} }
@ -250,31 +229,25 @@ mod test {
.unwrap(); .unwrap();
// Stored string should be in UTC // Stored string should be in UTC
let s: String = db let s: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert!(s.ends_with("+00:00")); assert!(s.ends_with("+00:00"));
let v: DateTime<Local> = db let v: DateTime<Local> = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(local, v); assert_eq!(local, v);
} }
#[test] #[test]
fn test_sqlite_functions() { fn test_sqlite_functions() {
let db = checked_memory_handle(); let db = checked_memory_handle();
let result: Result<NaiveTime> = let result: Result<NaiveTime> = db.query_row("SELECT CURRENT_TIME", [], |r| r.get(0));
db.query_row("SELECT CURRENT_TIME", NO_PARAMS, |r| r.get(0));
assert!(result.is_ok()); assert!(result.is_ok());
let result: Result<NaiveDate> = let result: Result<NaiveDate> = db.query_row("SELECT CURRENT_DATE", [], |r| r.get(0));
db.query_row("SELECT CURRENT_DATE", NO_PARAMS, |r| r.get(0));
assert!(result.is_ok()); assert!(result.is_ok());
let result: Result<NaiveDateTime> = let result: Result<NaiveDateTime> =
db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); assert!(result.is_ok());
let result: Result<DateTime<Utc>> = let result: Result<DateTime<Utc>> =
db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); assert!(result.is_ok());
} }
} }

View File

@ -131,7 +131,7 @@ impl fmt::Display for Type {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::Value; use super::Value;
use crate::{params, Connection, Error, Statement, NO_PARAMS}; use crate::{params, Connection, Error, Statement};
use std::f64::EPSILON; use std::f64::EPSILON;
use std::os::raw::{c_double, c_int}; use std::os::raw::{c_double, c_int};
@ -150,9 +150,7 @@ mod test {
db.execute("INSERT INTO foo(b) VALUES (?)", &[&v1234]) db.execute("INSERT INTO foo(b) VALUES (?)", &[&v1234])
.unwrap(); .unwrap();
let v: Vec<u8> = db let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT b FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(v, v1234); assert_eq!(v, v1234);
} }
@ -164,9 +162,7 @@ mod test {
db.execute("INSERT INTO foo(b) VALUES (?)", &[&empty]) db.execute("INSERT INTO foo(b) VALUES (?)", &[&empty])
.unwrap(); .unwrap();
let v: Vec<u8> = db let v: Vec<u8> = db.query_row("SELECT b FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT b FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(v, empty); assert_eq!(v, empty);
} }
@ -177,9 +173,7 @@ mod test {
let s = "hello, world!"; let s = "hello, world!";
db.execute("INSERT INTO foo(t) VALUES (?)", &[&s]).unwrap(); db.execute("INSERT INTO foo(t) VALUES (?)", &[&s]).unwrap();
let from: String = db let from: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(from, s); assert_eq!(from, s);
} }
@ -191,9 +185,7 @@ mod test {
db.execute("INSERT INTO foo(t) VALUES (?)", [s.to_owned()]) db.execute("INSERT INTO foo(t) VALUES (?)", [s.to_owned()])
.unwrap(); .unwrap();
let from: String = db let from: String = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(from, s); assert_eq!(from, s);
} }
@ -206,7 +198,7 @@ mod test {
assert_eq!( assert_eq!(
10i64, 10i64,
db.query_row::<i64, _, _>("SELECT i FROM foo", NO_PARAMS, |r| r.get(0)) db.query_row::<i64, _, _>("SELECT i FROM foo", [], |r| r.get(0))
.unwrap() .unwrap()
); );
} }
@ -224,7 +216,7 @@ mod test {
let mut stmt = db let mut stmt = db
.prepare("SELECT t, b FROM foo ORDER BY ROWID ASC") .prepare("SELECT t, b FROM foo ORDER BY ROWID ASC")
.unwrap(); .unwrap();
let mut rows = stmt.query(NO_PARAMS).unwrap(); let mut rows = stmt.query([]).unwrap();
{ {
let row1 = rows.next().unwrap().unwrap(); let row1 = rows.next().unwrap().unwrap();
@ -254,12 +246,12 @@ mod test {
db.execute( db.execute(
"INSERT INTO foo(b, t, i, f) VALUES (X'0102', 'text', 1, 1.5)", "INSERT INTO foo(b, t, i, f) VALUES (X'0102', 'text', 1, 1.5)",
NO_PARAMS, [],
) )
.unwrap(); .unwrap();
let mut stmt = db.prepare("SELECT b, t, i, f, n FROM foo").unwrap(); let mut stmt = db.prepare("SELECT b, t, i, f, n FROM foo").unwrap();
let mut rows = stmt.query(NO_PARAMS).unwrap(); let mut rows = stmt.query([]).unwrap();
let row = rows.next().unwrap().unwrap(); let row = rows.next().unwrap().unwrap();
@ -364,12 +356,12 @@ mod test {
db.execute( db.execute(
"INSERT INTO foo(b, t, i, f) VALUES (X'0102', 'text', 1, 1.5)", "INSERT INTO foo(b, t, i, f) VALUES (X'0102', 'text', 1, 1.5)",
NO_PARAMS, [],
) )
.unwrap(); .unwrap();
let mut stmt = db.prepare("SELECT b, t, i, f, n FROM foo").unwrap(); let mut stmt = db.prepare("SELECT b, t, i, f, n FROM foo").unwrap();
let mut rows = stmt.query(NO_PARAMS).unwrap(); let mut rows = stmt.query([]).unwrap();
let row = rows.next().unwrap().unwrap(); let row = rows.next().unwrap().unwrap();
assert_eq!(Value::Blob(vec![1, 2]), row.get::<_, Value>(0).unwrap()); assert_eq!(Value::Blob(vec![1, 2]), row.get::<_, Value>(0).unwrap());
@ -393,9 +385,9 @@ mod test {
.unwrap(); .unwrap();
let res = $db_etc let res = $db_etc
.query_statement .query_statement
.query_row(NO_PARAMS, |row| row.get::<_, $get_type>(0)); .query_row([], |row| row.get::<_, $get_type>(0));
assert_eq!(res.unwrap(), $expected_value); assert_eq!(res.unwrap(), $expected_value);
$db_etc.delete_statement.execute(NO_PARAMS).unwrap(); $db_etc.delete_statement.execute([]).unwrap();
}; };
($db_etc:ident, $insert_value:expr, $get_type:ty,expect_from_sql_error) => { ($db_etc:ident, $insert_value:expr, $get_type:ty,expect_from_sql_error) => {
$db_etc $db_etc
@ -404,9 +396,9 @@ mod test {
.unwrap(); .unwrap();
let res = $db_etc let res = $db_etc
.query_statement .query_statement
.query_row(NO_PARAMS, |row| row.get::<_, $get_type>(0)); .query_row([], |row| row.get::<_, $get_type>(0));
res.unwrap_err(); res.unwrap_err();
$db_etc.delete_statement.execute(NO_PARAMS).unwrap(); $db_etc.delete_statement.execute([]).unwrap();
}; };
($db_etc:ident, $insert_value:expr, $get_type:ty,expect_to_sql_error) => { ($db_etc:ident, $insert_value:expr, $get_type:ty,expect_to_sql_error) => {
$db_etc $db_etc

View File

@ -27,7 +27,7 @@ impl FromSql for Value {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::types::ToSql; use crate::types::ToSql;
use crate::{Connection, NO_PARAMS}; use crate::Connection;
fn checked_memory_handle() -> Connection { fn checked_memory_handle() -> Connection {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
@ -48,13 +48,9 @@ mod test {
) )
.unwrap(); .unwrap();
let t: serde_json::Value = db let t: serde_json::Value = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(data, t); assert_eq!(data, t);
let b: serde_json::Value = db let b: serde_json::Value = db.query_row("SELECT b FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT b FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
assert_eq!(data, b); assert_eq!(data, b);
} }
} }

View File

@ -32,7 +32,7 @@ impl FromSql for OffsetDateTime {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{Connection, Result, NO_PARAMS}; use crate::{Connection, Result};
use std::time::Duration; use std::time::Duration;
use time::OffsetDateTime; use time::OffsetDateTime;
@ -62,11 +62,9 @@ mod test {
for ts in ts_vec { for ts in ts_vec {
db.execute("INSERT INTO foo(t) VALUES (?)", &[&ts]).unwrap(); db.execute("INSERT INTO foo(t) VALUES (?)", &[&ts]).unwrap();
let from: OffsetDateTime = db let from: OffsetDateTime = db.query_row("SELECT t FROM foo", [], |r| r.get(0)).unwrap();
.query_row("SELECT t FROM foo", NO_PARAMS, |r| r.get(0))
.unwrap();
db.execute("DELETE FROM foo", NO_PARAMS).unwrap(); db.execute("DELETE FROM foo", []).unwrap();
assert_eq!(from, ts); assert_eq!(from, ts);
} }
@ -76,7 +74,7 @@ mod test {
fn test_sqlite_functions() { fn test_sqlite_functions() {
let db = checked_memory_handle(); let db = checked_memory_handle();
let result: Result<OffsetDateTime> = let result: Result<OffsetDateTime> =
db.query_row("SELECT CURRENT_TIMESTAMP", NO_PARAMS, |r| r.get(0)); db.query_row("SELECT CURRENT_TIMESTAMP", [], |r| r.get(0));
assert!(result.is_ok()); assert!(result.is_ok());
} }
} }

View File

@ -324,7 +324,7 @@ mod test {
#[cfg(feature = "i128_blob")] #[cfg(feature = "i128_blob")]
#[test] #[test]
fn test_i128() { fn test_i128() {
use crate::{Connection, NO_PARAMS}; use crate::Connection;
use std::i128; use std::i128;
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
db.execute_batch("CREATE TABLE foo (i128 BLOB, desc TEXT)") db.execute_batch("CREATE TABLE foo (i128 BLOB, desc TEXT)")
@ -345,7 +345,7 @@ mod test {
.unwrap(); .unwrap();
let res = stmt let res = stmt
.query_map(NO_PARAMS, |row| { .query_map([], |row| {
Ok((row.get::<_, i128>(0)?, row.get::<_, String>(1)?)) Ok((row.get::<_, i128>(0)?, row.get::<_, String>(1)?))
}) })
.unwrap() .unwrap()

View File

@ -100,7 +100,7 @@ pub unsafe fn wait_for_unlock_notify(_db: *mut ffi::sqlite3) -> c_int {
#[cfg(feature = "unlock_notify")] #[cfg(feature = "unlock_notify")]
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{Connection, OpenFlags, Result, Transaction, TransactionBehavior, NO_PARAMS}; use crate::{Connection, OpenFlags, Result, Transaction, TransactionBehavior};
use std::sync::mpsc::sync_channel; use std::sync::mpsc::sync_channel;
use std::thread; use std::thread;
use std::time; use std::time;
@ -122,7 +122,7 @@ mod test {
tx2.commit().unwrap(); tx2.commit().unwrap();
}); });
assert_eq!(tx.recv().unwrap(), 1); assert_eq!(tx.recv().unwrap(), 1);
let the_answer: Result<i64> = db1.query_row("SELECT x FROM foo", NO_PARAMS, |r| r.get(0)); let the_answer: Result<i64> = db1.query_row("SELECT x FROM foo", [], |r| r.get(0));
assert_eq!(42i64, the_answer.unwrap()); assert_eq!(42i64, the_answer.unwrap());
child.join().unwrap(); child.join().unwrap();
} }

View File

@ -362,7 +362,7 @@ impl From<csv::Error> for Error {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::vtab::csvtab; use crate::vtab::csvtab;
use crate::{Connection, Result, NO_PARAMS}; use crate::{Connection, Result};
use fallible_iterator::FallibleIterator; use fallible_iterator::FallibleIterator;
#[test] #[test]
@ -380,7 +380,7 @@ mod test {
} }
let ids: Result<Vec<i32>> = s let ids: Result<Vec<i32>> = s
.query(NO_PARAMS) .query([])
.unwrap() .unwrap()
.map(|row| row.get::<_, i32>(0)) .map(|row| row.get::<_, i32>(0))
.collect(); .collect();
@ -405,7 +405,7 @@ mod test {
) )
.unwrap(); .unwrap();
let mut rows = s.query(NO_PARAMS).unwrap(); let mut rows = s.query([]).unwrap();
let row = rows.next().unwrap().unwrap(); let row = rows.next().unwrap().unwrap();
assert_eq!(row.get_unwrap::<_, i32>(0), 2); assert_eq!(row.get_unwrap::<_, i32>(0), 2);
} }

View File

@ -273,7 +273,7 @@ unsafe impl VTabCursor for SeriesTabCursor<'_> {
mod test { mod test {
use crate::ffi; use crate::ffi;
use crate::vtab::series; use crate::vtab::series;
use crate::{Connection, NO_PARAMS}; use crate::Connection;
#[test] #[test]
fn test_series_module() { fn test_series_module() {
@ -287,7 +287,7 @@ mod test {
let mut s = db.prepare("SELECT * FROM generate_series(0,20,5)").unwrap(); let mut s = db.prepare("SELECT * FROM generate_series(0,20,5)").unwrap();
let series = s.query_map(NO_PARAMS, |row| row.get::<_, i32>(0)).unwrap(); let series = s.query_map([], |row| row.get::<_, i32>(0)).unwrap();
let mut expected = 0; let mut expected = 0;
for value in series { for value in series {