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 rusqlite::{Connection, NO_PARAMS};
use rusqlite::Connection;
fn bench_execute(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap();
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) {

View File

@ -306,7 +306,7 @@ impl Drop for Backup<'_, '_> {
#[cfg(test)]
mod test {
use super::Backup;
use crate::{Connection, DatabaseName, NO_PARAMS};
use crate::{Connection, DatabaseName};
use std::time::Duration;
#[test]
@ -326,7 +326,7 @@ mod test {
}
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();
assert_eq!(42, the_answer);
@ -340,7 +340,7 @@ mod test {
}
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();
assert_eq!(42 + 43, the_answer);
}
@ -364,7 +364,7 @@ mod test {
}
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();
assert_eq!(42, the_answer);
@ -380,7 +380,7 @@ mod test {
}
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();
assert_eq!(42 + 43, the_answer);
}
@ -409,7 +409,7 @@ mod test {
}
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();
assert_eq!(42, the_answer);
@ -429,7 +429,7 @@ mod test {
}
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();
assert_eq!(42 + 43, the_answer);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -194,7 +194,7 @@ mod test {
)
.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();
match row.get::<_, String>(0).unwrap_err() {
Error::InvalidColumnType(idx, name, ty) => {

View File

@ -11,7 +11,7 @@
//! ```rust
//! use regex::Regex;
//! use rusqlite::functions::FunctionFlags;
//! use rusqlite::{Connection, Error, Result, NO_PARAMS};
//! use rusqlite::{Connection, Error, Result};
//! use std::sync::Arc;
//! type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
@ -745,7 +745,7 @@ mod test {
#[cfg(feature = "window")]
use crate::functions::WindowAggregate;
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> {
assert_eq!(ctx.len(), 1, "called with unexpected number of arguments");
@ -763,7 +763,7 @@ mod test {
half,
)
.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);
}
@ -778,11 +778,11 @@ mod test {
half,
)
.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);
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());
}
@ -830,15 +830,13 @@ mod test {
.unwrap();
let result: Result<bool> =
db.query_row("SELECT regexp('l.s[aeiouy]', 'lisa')", NO_PARAMS, |r| {
r.get(0)
});
db.query_row("SELECT regexp('l.s[aeiouy]', 'lisa')", [], |r| r.get(0));
assert_eq!(true, result.unwrap());
let result: Result<i64> = db.query_row(
"SELECT COUNT(*) FROM foo WHERE regexp('l.s[aeiouy]', x) == 1",
NO_PARAMS,
[],
|r| r.get(0),
);
@ -870,7 +868,7 @@ mod test {
("onetwo", "SELECT my_concat('one', 'two')"),
("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);
}
}
@ -892,7 +890,7 @@ mod test {
let res: bool = db
.query_row(
"SELECT example(0, i) FROM (SELECT 0 as i UNION SELECT 1)",
NO_PARAMS,
[],
|r| r.get(0),
)
.unwrap();
@ -946,17 +944,17 @@ mod test {
// 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 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());
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);
let dual_sum = "SELECT my_sum(i), my_sum(j) FROM (SELECT 2 AS i, 1 AS j UNION ALL SELECT \
2, 1)";
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();
assert_eq!((4, 2), result);
}
@ -974,11 +972,11 @@ mod test {
// 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 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);
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);
}
@ -1027,7 +1025,7 @@ mod test {
.unwrap();
let results: Vec<(String, i64)> = stmt
.query(NO_PARAMS)
.query([])
.unwrap()
.map(|row| Ok((row.get("x")?, row.get("sum_y")?)))
.collect()

View File

@ -133,12 +133,8 @@ const STATEMENT_CACHE_DEFAULT_CAPACITY: usize = 16;
///
/// [sqlite-varparam]: https://sqlite.org/lang_expr.html#varparam
///
/// Note that for most uses this is no longer necessary, and an empty array
/// should be used instead.
///
/// 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.
/// This is deprecated in favor of using an empty array literal.
#[deprecated = "Use an empty array instead; `stmt.execute(NO_PARAMS)` => `stmt.execute([])`"]
pub const NO_PARAMS: &[&dyn ToSql] = &[];
/// 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_rules! params {
() => {
$crate::NO_PARAMS
(&[] as &[&dyn $crate::ToSql])
};
($($param:expr),+ $(,)?) => {
&[$(&$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
/// `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)
///

View File

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

View File

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

View File

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

View File

@ -467,7 +467,7 @@ impl Connection {
#[cfg(test)]
mod test {
use super::DropBehavior;
use crate::{Connection, Error, NO_PARAMS};
use crate::{Connection, Error};
fn checked_memory_handle() -> Connection {
let db = Connection::open_in_memory().unwrap();
@ -492,7 +492,7 @@ mod test {
let tx = db.transaction().unwrap();
assert_eq!(
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()
);
}
@ -531,7 +531,7 @@ mod test {
assert_eq!(
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()
);
}
@ -559,7 +559,7 @@ mod test {
let tx = db.transaction().unwrap();
assert_eq!(
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()
);
}
@ -666,7 +666,7 @@ mod test {
fn assert_current_sum(x: i32, conn: &Connection) {
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();
assert_eq!(x, i);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -273,7 +273,7 @@ unsafe impl VTabCursor for SeriesTabCursor<'_> {
mod test {
use crate::ffi;
use crate::vtab::series;
use crate::{Connection, NO_PARAMS};
use crate::Connection;
#[test]
fn test_series_module() {
@ -287,7 +287,7 @@ mod test {
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;
for value in series {