mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
Merge remote-tracking branch 'jgallagher/master' into vtab
This commit is contained in:
commit
d72c4582d9
@ -26,7 +26,7 @@ min_sqlite_version_3_7_16 = ["pkg-config", "vcpkg"]
|
|||||||
unlock_notify = []
|
unlock_notify = []
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = { version = "0.36", optional = true }
|
bindgen = { version = "0.37", optional = true }
|
||||||
pkg-config = { version = "0.3", optional = true }
|
pkg-config = { version = "0.3", optional = true }
|
||||||
cc = { version = "1.0", optional = true }
|
cc = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
16
src/cache.rs
16
src/cache.rs
@ -177,14 +177,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
}
|
}
|
||||||
assert_eq!(1, cache.len());
|
assert_eq!(1, cache.len());
|
||||||
|
|
||||||
@ -202,7 +202,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
}
|
}
|
||||||
assert_eq!(1, cache.len());
|
assert_eq!(1, cache.len());
|
||||||
|
|
||||||
@ -212,7 +212,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
}
|
}
|
||||||
assert_eq!(0, cache.len());
|
assert_eq!(0, cache.len());
|
||||||
|
|
||||||
@ -220,7 +220,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
}
|
}
|
||||||
assert_eq!(1, cache.len());
|
assert_eq!(1, cache.len());
|
||||||
}
|
}
|
||||||
@ -234,7 +234,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
stmt.discard();
|
stmt.discard();
|
||||||
}
|
}
|
||||||
assert_eq!(0, cache.len());
|
assert_eq!(0, cache.len());
|
||||||
@ -298,14 +298,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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |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!(0, stmt.query_row(&[], |r| r.get::<i32, i64>(0)).unwrap());
|
assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap());
|
||||||
}
|
}
|
||||||
assert_eq!(1, cache.len());
|
assert_eq!(1, cache.len());
|
||||||
}
|
}
|
||||||
|
10
src/error.rs
10
src/error.rs
@ -26,9 +26,9 @@ pub enum Error {
|
|||||||
FromSqlConversionFailure(usize, Type, Box<error::Error + Send + Sync>),
|
FromSqlConversionFailure(usize, Type, Box<error::Error + Send + Sync>),
|
||||||
|
|
||||||
/// Error when SQLite gives us an integral value outside the range of the requested type (e.g.,
|
/// Error when SQLite gives us an integral value outside the range of the requested type (e.g.,
|
||||||
/// trying to get the value 1000 into a `u8`). The associated `c_int` is the column index, and
|
/// trying to get the value 1000 into a `u8`). The associated `usize` is the column index, and
|
||||||
/// the associated `i64` is the value returned by SQLite.
|
/// the associated `i64` is the value returned by SQLite.
|
||||||
IntegralValueOutOfRange(c_int, i64),
|
IntegralValueOutOfRange(usize, i64),
|
||||||
|
|
||||||
/// Error converting a string to UTF-8.
|
/// Error converting a string to UTF-8.
|
||||||
Utf8Error(str::Utf8Error),
|
Utf8Error(str::Utf8Error),
|
||||||
@ -51,7 +51,7 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Error when the value of a particular column is requested, but the index is out of range
|
/// Error when the value of a particular column is requested, but the index is out of range
|
||||||
/// for the statement.
|
/// for the statement.
|
||||||
InvalidColumnIndex(c_int),
|
InvalidColumnIndex(usize),
|
||||||
|
|
||||||
/// Error when the value of a named column is requested, but no column matches the name
|
/// Error when the value of a named column is requested, but no column matches the name
|
||||||
/// for the statement.
|
/// for the statement.
|
||||||
@ -59,10 +59,10 @@ pub enum Error {
|
|||||||
|
|
||||||
/// Error when the value of a particular column is requested, but the type of the result in
|
/// Error when the value of a particular column is requested, but the type of the result in
|
||||||
/// that column cannot be converted to the requested Rust type.
|
/// that column cannot be converted to the requested Rust type.
|
||||||
InvalidColumnType(c_int, Type),
|
InvalidColumnType(usize, Type),
|
||||||
|
|
||||||
/// Error when a query that was expected to insert one row did not insert any or insert many.
|
/// Error when a query that was expected to insert one row did not insert any or insert many.
|
||||||
StatementChangedRows(c_int),
|
StatementChangedRows(usize),
|
||||||
|
|
||||||
/// Error returned by `functions::Context::get` when the function argument cannot be converted
|
/// Error returned by `functions::Context::get` when the function argument cannot be converted
|
||||||
/// to the requested type.
|
/// to the requested type.
|
||||||
|
@ -128,7 +128,7 @@ impl<'a> Context<'a> {
|
|||||||
Error::InvalidFunctionParameterType(idx, value.data_type())
|
Error::InvalidFunctionParameterType(idx, value.data_type())
|
||||||
}
|
}
|
||||||
FromSqlError::OutOfRange(i) => {
|
FromSqlError::OutOfRange(i) => {
|
||||||
Error::IntegralValueOutOfRange(idx as c_int,
|
Error::IntegralValueOutOfRange(idx,
|
||||||
i)
|
i)
|
||||||
}
|
}
|
||||||
FromSqlError::Other(err) => {
|
FromSqlError::Other(err) => {
|
||||||
|
14
src/lib.rs
14
src/lib.rs
@ -309,7 +309,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
|
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
|
||||||
/// underlying SQLite call fails.
|
/// underlying SQLite call fails.
|
||||||
pub fn execute(&self, sql: &str, params: &[&ToSql]) -> Result<c_int> {
|
pub fn execute(&self, sql: &str, params: &[&ToSql]) -> Result<usize> {
|
||||||
self.prepare(sql)
|
self.prepare(sql)
|
||||||
.and_then(|mut stmt| stmt.execute(params))
|
.and_then(|mut stmt| stmt.execute(params))
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use rusqlite::{Connection, Result};
|
/// # use rusqlite::{Connection, Result};
|
||||||
/// fn insert(conn: &Connection) -> Result<i32> {
|
/// fn insert(conn: &Connection) -> Result<usize> {
|
||||||
/// conn.execute_named("INSERT INTO test (name) VALUES (:name)", &[(":name", &"one")])
|
/// conn.execute_named("INSERT INTO test (name) VALUES (:name)", &[(":name", &"one")])
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -332,7 +332,7 @@ impl Connection {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
|
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
|
||||||
/// underlying SQLite call fails.
|
/// underlying SQLite call fails.
|
||||||
pub fn execute_named(&self, sql: &str, params: &[(&str, &ToSql)]) -> Result<c_int> {
|
pub fn execute_named(&self, sql: &str, params: &[(&str, &ToSql)]) -> Result<usize> {
|
||||||
self.prepare(sql)
|
self.prepare(sql)
|
||||||
.and_then(|mut stmt| stmt.execute_named(params))
|
.and_then(|mut stmt| stmt.execute_named(params))
|
||||||
}
|
}
|
||||||
@ -574,7 +574,7 @@ impl Connection {
|
|||||||
self.db.borrow_mut().decode_result(code)
|
self.db.borrow_mut().decode_result(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn changes(&self) -> c_int {
|
fn changes(&self) -> usize {
|
||||||
self.db.borrow_mut().changes()
|
self.db.borrow_mut().changes()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -915,8 +915,8 @@ impl InnerConnection {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn changes(&mut self) -> c_int {
|
fn changes(&mut self) -> usize {
|
||||||
unsafe { ffi::sqlite3_changes(self.db()) }
|
unsafe { ffi::sqlite3_changes(self.db()) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_autocommit(&self) -> bool {
|
fn is_autocommit(&self) -> bool {
|
||||||
@ -935,7 +935,7 @@ impl InnerConnection {
|
|||||||
stmt = ffi::sqlite3_next_stmt(db, stmt);
|
stmt = ffi::sqlite3_next_stmt(db, stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "hooks"))]
|
#[cfg(not(feature = "hooks"))]
|
||||||
|
@ -17,16 +17,16 @@ impl RawStatement {
|
|||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column_count(&self) -> c_int {
|
pub fn column_count(&self) -> usize {
|
||||||
unsafe { ffi::sqlite3_column_count(self.0) }
|
unsafe { ffi::sqlite3_column_count(self.0) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column_type(&self, idx: c_int) -> c_int {
|
pub fn column_type(&self, idx: usize) -> c_int {
|
||||||
unsafe { ffi::sqlite3_column_type(self.0, idx) }
|
unsafe { ffi::sqlite3_column_type(self.0, idx as c_int) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn column_name(&self, idx: c_int) -> &CStr {
|
pub fn column_name(&self, idx: usize) -> &CStr {
|
||||||
unsafe { CStr::from_ptr(ffi::sqlite3_column_name(self.0, idx)) }
|
unsafe { CStr::from_ptr(ffi::sqlite3_column_name(self.0, idx as c_int)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&self) -> c_int {
|
pub fn step(&self) -> c_int {
|
||||||
@ -54,15 +54,15 @@ impl RawStatement {
|
|||||||
unsafe { ffi::sqlite3_reset(self.0) }
|
unsafe { ffi::sqlite3_reset(self.0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_parameter_count(&self) -> c_int {
|
pub fn bind_parameter_count(&self) -> usize {
|
||||||
unsafe { ffi::sqlite3_bind_parameter_count(self.0) }
|
unsafe { ffi::sqlite3_bind_parameter_count(self.0) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_parameter_index(&self, name: &CStr) -> Option<c_int> {
|
pub fn bind_parameter_index(&self, name: &CStr) -> Option<usize> {
|
||||||
let r = unsafe { ffi::sqlite3_bind_parameter_index(self.0, name.as_ptr()) };
|
let r = unsafe { ffi::sqlite3_bind_parameter_index(self.0, name.as_ptr()) };
|
||||||
match r {
|
match r {
|
||||||
0 => None,
|
0 => None,
|
||||||
i => Some(i),
|
i => Some(i as usize),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
src/row.rs
12
src/row.rs
@ -192,7 +192,7 @@ impl<'a, 'stmt> Row<'a, 'stmt> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of columns in the current row.
|
/// Return the number of columns in the current row.
|
||||||
pub fn column_count(&self) -> i32 {
|
pub fn column_count(&self) -> usize {
|
||||||
self.stmt.column_count()
|
self.stmt.column_count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,13 +201,13 @@ impl<'a, 'stmt> Row<'a, 'stmt> {
|
|||||||
pub trait RowIndex {
|
pub trait RowIndex {
|
||||||
/// Returns the index of the appropriate column, or `None` if no such
|
/// Returns the index of the appropriate column, or `None` if no such
|
||||||
/// column exists.
|
/// column exists.
|
||||||
fn idx(&self, stmt: &Statement) -> Result<i32>;
|
fn idx(&self, stmt: &Statement) -> Result<usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RowIndex for i32 {
|
impl RowIndex for usize {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, stmt: &Statement) -> Result<i32> {
|
fn idx(&self, stmt: &Statement) -> Result<usize> {
|
||||||
if *self < 0 || *self >= stmt.column_count() {
|
if *self >= stmt.column_count() {
|
||||||
Err(Error::InvalidColumnIndex(*self))
|
Err(Error::InvalidColumnIndex(*self))
|
||||||
} else {
|
} else {
|
||||||
Ok(*self)
|
Ok(*self)
|
||||||
@ -217,7 +217,7 @@ impl RowIndex for i32 {
|
|||||||
|
|
||||||
impl<'a> RowIndex for &'a str {
|
impl<'a> RowIndex for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, stmt: &Statement) -> Result<i32> {
|
fn idx(&self, stmt: &Statement) -> Result<usize> {
|
||||||
stmt.column_index(*self)
|
stmt.column_index(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of columns in the result set returned by the prepared statement.
|
/// Return the number of columns in the result set returned by the prepared statement.
|
||||||
pub fn column_count(&self) -> i32 {
|
pub fn column_count(&self) -> usize {
|
||||||
self.stmt.column_count()
|
self.stmt.column_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
/// Will return an `Error::InvalidColumnName` when there is no column with the specified `name`.
|
/// Will return an `Error::InvalidColumnName` when there is no column with the specified `name`.
|
||||||
pub fn column_index(&self, name: &str) -> Result<i32> {
|
pub fn column_index(&self, name: &str) -> Result<usize> {
|
||||||
let bytes = name.as_bytes();
|
let bytes = name.as_bytes();
|
||||||
let n = self.column_count();
|
let n = self.column_count();
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
@ -79,7 +79,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if binding parameters fails, the executed statement returns rows (in
|
/// Will return `Err` if binding parameters fails, the executed statement returns rows (in
|
||||||
/// which case `query` should be used instead), or the underling SQLite call fails.
|
/// which case `query` should be used instead), or the underling SQLite call fails.
|
||||||
pub fn execute(&mut self, params: &[&ToSql]) -> Result<c_int> {
|
pub fn execute(&mut self, params: &[&ToSql]) -> Result<usize> {
|
||||||
try!(self.bind_parameters(params));
|
try!(self.bind_parameters(params));
|
||||||
self.execute_with_bound_parameters()
|
self.execute_with_bound_parameters()
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use rusqlite::{Connection, Result};
|
/// # use rusqlite::{Connection, Result};
|
||||||
/// fn insert(conn: &Connection) -> Result<i32> {
|
/// fn insert(conn: &Connection) -> Result<usize> {
|
||||||
/// let mut stmt = try!(conn.prepare("INSERT INTO test (name) VALUES (:name)"));
|
/// let mut stmt = try!(conn.prepare("INSERT INTO test (name) VALUES (:name)"));
|
||||||
/// stmt.execute_named(&[(":name", &"one")])
|
/// stmt.execute_named(&[(":name", &"one")])
|
||||||
/// }
|
/// }
|
||||||
@ -106,7 +106,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
///
|
///
|
||||||
/// Will return `Err` if binding parameters fails, the executed statement returns rows (in
|
/// Will return `Err` if binding parameters fails, the executed statement returns rows (in
|
||||||
/// which case `query` should be used instead), or the underling SQLite call fails.
|
/// which case `query` should be used instead), or the underling SQLite call fails.
|
||||||
pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result<c_int> {
|
pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result<usize> {
|
||||||
try!(self.bind_parameters_named(params));
|
try!(self.bind_parameters_named(params));
|
||||||
self.execute_with_bound_parameters()
|
self.execute_with_bound_parameters()
|
||||||
}
|
}
|
||||||
@ -366,19 +366,19 @@ impl<'conn> Statement<'conn> {
|
|||||||
///
|
///
|
||||||
/// Will return Err if `name` is invalid. Will return Ok(None) if the name
|
/// Will return Err if `name` is invalid. Will return Ok(None) if the name
|
||||||
/// is valid but not a bound parameter of this statement.
|
/// is valid but not a bound parameter of this statement.
|
||||||
pub fn parameter_index(&self, name: &str) -> Result<Option<i32>> {
|
pub fn parameter_index(&self, name: &str) -> Result<Option<usize>> {
|
||||||
let c_name = try!(str_to_cstring(name));
|
let c_name = try!(str_to_cstring(name));
|
||||||
Ok(self.stmt.bind_parameter_index(&c_name))
|
Ok(self.stmt.bind_parameter_index(&c_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bind_parameters(&mut self, params: &[&ToSql]) -> Result<()> {
|
fn bind_parameters(&mut self, params: &[&ToSql]) -> Result<()> {
|
||||||
assert_eq!(params.len() as c_int, self.stmt.bind_parameter_count(),
|
assert_eq!(params.len(), self.stmt.bind_parameter_count(),
|
||||||
"incorrect number of parameters to query(): expected {}, got {}",
|
"incorrect number of parameters to query(): expected {}, got {}",
|
||||||
self.stmt.bind_parameter_count(),
|
self.stmt.bind_parameter_count(),
|
||||||
params.len());
|
params.len());
|
||||||
|
|
||||||
for (i, p) in params.iter().enumerate() {
|
for (i, p) in params.iter().enumerate() {
|
||||||
try!(self.bind_parameter(*p, (i + 1) as c_int));
|
try!(self.bind_parameter(*p, i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -395,7 +395,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bind_parameter(&self, param: &ToSql, col: c_int) -> Result<()> {
|
fn bind_parameter(&self, param: &ToSql, col: usize) -> Result<()> {
|
||||||
let value = try!(param.to_sql());
|
let value = try!(param.to_sql());
|
||||||
|
|
||||||
let ptr = unsafe { self.stmt.ptr() };
|
let ptr = unsafe { self.stmt.ptr() };
|
||||||
@ -406,7 +406,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
#[cfg(feature = "blob")]
|
#[cfg(feature = "blob")]
|
||||||
ToSqlOutput::ZeroBlob(len) => {
|
ToSqlOutput::ZeroBlob(len) => {
|
||||||
return self.conn
|
return self.conn
|
||||||
.decode_result(unsafe { ffi::sqlite3_bind_zeroblob(ptr, col, len) });
|
.decode_result(unsafe { ffi::sqlite3_bind_zeroblob(ptr, col as c_int, len) });
|
||||||
}
|
}
|
||||||
#[cfg(feature = "array")]
|
#[cfg(feature = "array")]
|
||||||
ToSqlOutput::Array(a) => {
|
ToSqlOutput::Array(a) => {
|
||||||
@ -416,12 +416,12 @@ impl<'conn> Statement<'conn> {
|
|||||||
};
|
};
|
||||||
self.conn
|
self.conn
|
||||||
.decode_result(match value {
|
.decode_result(match value {
|
||||||
ValueRef::Null => unsafe { ffi::sqlite3_bind_null(ptr, col) },
|
ValueRef::Null => unsafe { ffi::sqlite3_bind_null(ptr, col as c_int) },
|
||||||
ValueRef::Integer(i) => unsafe {
|
ValueRef::Integer(i) => unsafe {
|
||||||
ffi::sqlite3_bind_int64(ptr, col, i)
|
ffi::sqlite3_bind_int64(ptr, col as c_int, i)
|
||||||
},
|
},
|
||||||
ValueRef::Real(r) => unsafe {
|
ValueRef::Real(r) => unsafe {
|
||||||
ffi::sqlite3_bind_double(ptr, col, r)
|
ffi::sqlite3_bind_double(ptr, col as c_int, r)
|
||||||
},
|
},
|
||||||
ValueRef::Text(s) => unsafe {
|
ValueRef::Text(s) => unsafe {
|
||||||
let length = s.len();
|
let length = s.len();
|
||||||
@ -434,7 +434,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
} else {
|
} else {
|
||||||
ffi::SQLITE_STATIC()
|
ffi::SQLITE_STATIC()
|
||||||
};
|
};
|
||||||
ffi::sqlite3_bind_text(ptr, col, c_str.as_ptr(), length as c_int, destructor)
|
ffi::sqlite3_bind_text(ptr, col as c_int, c_str.as_ptr(), length as c_int, destructor)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ValueRef::Blob(b) => unsafe {
|
ValueRef::Blob(b) => unsafe {
|
||||||
@ -442,10 +442,10 @@ impl<'conn> Statement<'conn> {
|
|||||||
if length > ::std::i32::MAX as usize {
|
if length > ::std::i32::MAX as usize {
|
||||||
ffi::SQLITE_TOOBIG
|
ffi::SQLITE_TOOBIG
|
||||||
} else if length == 0 {
|
} else if length == 0 {
|
||||||
ffi::sqlite3_bind_zeroblob(ptr, col, 0)
|
ffi::sqlite3_bind_zeroblob(ptr, col as c_int, 0)
|
||||||
} else {
|
} else {
|
||||||
ffi::sqlite3_bind_blob(ptr,
|
ffi::sqlite3_bind_blob(ptr,
|
||||||
col,
|
col as c_int,
|
||||||
b.as_ptr() as *const c_void,
|
b.as_ptr() as *const c_void,
|
||||||
length as c_int,
|
length as c_int,
|
||||||
ffi::SQLITE_TRANSIENT())
|
ffi::SQLITE_TRANSIENT())
|
||||||
@ -454,7 +454,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_with_bound_parameters(&mut self) -> Result<c_int> {
|
fn execute_with_bound_parameters(&mut self) -> Result<usize> {
|
||||||
let r = self.stmt.step();
|
let r = self.stmt.step();
|
||||||
self.stmt.reset();
|
self.stmt.reset();
|
||||||
match r {
|
match r {
|
||||||
@ -507,7 +507,7 @@ impl<'conn> Drop for Statement<'conn> {
|
|||||||
// once pub(crate) is stable.
|
// once pub(crate) is stable.
|
||||||
pub trait StatementCrateImpl<'conn> {
|
pub trait StatementCrateImpl<'conn> {
|
||||||
fn new(conn: &'conn Connection, stmt: RawStatement) -> Self;
|
fn new(conn: &'conn Connection, stmt: RawStatement) -> Self;
|
||||||
fn value_ref(&self, col: c_int) -> ValueRef;
|
fn value_ref(&self, col: usize) -> ValueRef;
|
||||||
fn step(&self) -> Result<bool>;
|
fn step(&self) -> Result<bool>;
|
||||||
fn reset(&self) -> c_int;
|
fn reset(&self) -> c_int;
|
||||||
}
|
}
|
||||||
@ -520,18 +520,18 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_ref(&self, col: c_int) -> ValueRef {
|
fn value_ref(&self, col: usize) -> ValueRef {
|
||||||
let raw = unsafe { self.stmt.ptr() };
|
let raw = unsafe { self.stmt.ptr() };
|
||||||
|
|
||||||
match self.stmt.column_type(col) {
|
match self.stmt.column_type(col) {
|
||||||
ffi::SQLITE_NULL => ValueRef::Null,
|
ffi::SQLITE_NULL => ValueRef::Null,
|
||||||
ffi::SQLITE_INTEGER => {
|
ffi::SQLITE_INTEGER => {
|
||||||
ValueRef::Integer(unsafe { ffi::sqlite3_column_int64(raw, col) })
|
ValueRef::Integer(unsafe { ffi::sqlite3_column_int64(raw, col as c_int) })
|
||||||
}
|
}
|
||||||
ffi::SQLITE_FLOAT => ValueRef::Real(unsafe { ffi::sqlite3_column_double(raw, col) }),
|
ffi::SQLITE_FLOAT => ValueRef::Real(unsafe { ffi::sqlite3_column_double(raw, col as c_int) }),
|
||||||
ffi::SQLITE_TEXT => {
|
ffi::SQLITE_TEXT => {
|
||||||
let s = unsafe {
|
let s = unsafe {
|
||||||
let text = ffi::sqlite3_column_text(raw, col);
|
let text = ffi::sqlite3_column_text(raw, col as c_int);
|
||||||
assert!(!text.is_null(),
|
assert!(!text.is_null(),
|
||||||
"unexpected SQLITE_TEXT column type with NULL data");
|
"unexpected SQLITE_TEXT column type with NULL data");
|
||||||
CStr::from_ptr(text as *const c_char)
|
CStr::from_ptr(text as *const c_char)
|
||||||
@ -544,7 +544,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> {
|
|||||||
}
|
}
|
||||||
ffi::SQLITE_BLOB => {
|
ffi::SQLITE_BLOB => {
|
||||||
let (blob, len) = unsafe {
|
let (blob, len) = unsafe {
|
||||||
(ffi::sqlite3_column_blob(raw, col), ffi::sqlite3_column_bytes(raw, col))
|
(ffi::sqlite3_column_blob(raw, col as c_int), ffi::sqlite3_column_bytes(raw, col as c_int))
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(len >= 0,
|
assert!(len >= 0,
|
||||||
|
@ -77,10 +77,9 @@ mod serde_json;
|
|||||||
/// # extern crate rusqlite;
|
/// # extern crate rusqlite;
|
||||||
/// # use rusqlite::{Connection, Result};
|
/// # use rusqlite::{Connection, Result};
|
||||||
/// # use rusqlite::types::{Null};
|
/// # use rusqlite::types::{Null};
|
||||||
/// # use std::os::raw::{c_int};
|
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// }
|
/// }
|
||||||
/// fn insert_null(conn: &Connection) -> Result<c_int> {
|
/// fn insert_null(conn: &Connection) -> Result<usize> {
|
||||||
/// conn.execute("INSERT INTO people (name) VALUES (?)", &[&Null])
|
/// conn.execute("INSERT INTO people (name) VALUES (?)", &[&Null])
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -243,57 +242,57 @@ mod test {
|
|||||||
let row = rows.next().unwrap().unwrap();
|
let row = rows.next().unwrap().unwrap();
|
||||||
|
|
||||||
// check the correct types come back as expected
|
// check the correct types come back as expected
|
||||||
assert_eq!(vec![1, 2], row.get_checked::<i32, Vec<u8>>(0).unwrap());
|
assert_eq!(vec![1, 2], row.get_checked::<_, Vec<u8>>(0).unwrap());
|
||||||
assert_eq!("text", row.get_checked::<i32, String>(1).unwrap());
|
assert_eq!("text", row.get_checked::<_, String>(1).unwrap());
|
||||||
assert_eq!(1, row.get_checked::<i32, c_int>(2).unwrap());
|
assert_eq!(1, row.get_checked::<_, c_int>(2).unwrap());
|
||||||
assert!((1.5 - row.get_checked::<i32, c_double>(3).unwrap()).abs() < EPSILON);
|
assert!((1.5 - row.get_checked::<_, c_double>(3).unwrap()).abs() < EPSILON);
|
||||||
assert!(row.get_checked::<i32, Option<c_int>>(4)
|
assert!(row.get_checked::<_, Option<c_int>>(4)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_none());
|
.is_none());
|
||||||
assert!(row.get_checked::<i32, Option<c_double>>(4)
|
assert!(row.get_checked::<_, Option<c_double>>(4)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_none());
|
.is_none());
|
||||||
assert!(row.get_checked::<i32, Option<String>>(4)
|
assert!(row.get_checked::<_, Option<String>>(4)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_none());
|
.is_none());
|
||||||
|
|
||||||
// check some invalid types
|
// check some invalid types
|
||||||
|
|
||||||
// 0 is actually a blob (Vec<u8>)
|
// 0 is actually a blob (Vec<u8>)
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_int>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_int>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, i64>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, i64>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_double>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_double>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, String>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, String>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, time::Timespec>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, time::Timespec>(0).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<c_int>>(0).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Option<c_int>>(0).err().unwrap()));
|
||||||
|
|
||||||
// 1 is actually a text (String)
|
// 1 is actually a text (String)
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(1).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_int>(1).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, i64>(1).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, i64>(1).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_double>(1).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_double>(1).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Vec<u8>>(1).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Vec<u8>>(1).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<c_int>>(1).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Option<c_int>>(1).err().unwrap()));
|
||||||
|
|
||||||
// 2 is actually an integer
|
// 2 is actually an integer
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, String>(2).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, String>(2).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Vec<u8>>(2).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Vec<u8>>(2).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<String>>(2).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Option<String>>(2).err().unwrap()));
|
||||||
|
|
||||||
// 3 is actually a float (c_double)
|
// 3 is actually a float (c_double)
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(3).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_int>(3).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, i64>(3).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, i64>(3).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, String>(3).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, String>(3).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Vec<u8>>(3).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Vec<u8>>(3).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Option<c_int>>(3).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Option<c_int>>(3).err().unwrap()));
|
||||||
|
|
||||||
// 4 is actually NULL
|
// 4 is actually NULL
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_int>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_int>(4).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, i64>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, i64>(4).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, c_double>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, c_double>(4).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, String>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, String>(4).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, Vec<u8>>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, Vec<u8>>(4).err().unwrap()));
|
||||||
assert!(is_invalid_column_type(row.get_checked::<i32, time::Timespec>(4).err().unwrap()));
|
assert!(is_invalid_column_type(row.get_checked::<_, time::Timespec>(4).err().unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -310,14 +309,14 @@ mod test {
|
|||||||
|
|
||||||
let row = rows.next().unwrap().unwrap();
|
let row = rows.next().unwrap().unwrap();
|
||||||
assert_eq!(Value::Blob(vec![1, 2]),
|
assert_eq!(Value::Blob(vec![1, 2]),
|
||||||
row.get_checked::<i32, Value>(0).unwrap());
|
row.get_checked::<_, Value>(0).unwrap());
|
||||||
assert_eq!(Value::Text(String::from("text")),
|
assert_eq!(Value::Text(String::from("text")),
|
||||||
row.get_checked::<i32, Value>(1).unwrap());
|
row.get_checked::<_, Value>(1).unwrap());
|
||||||
assert_eq!(Value::Integer(1), row.get_checked::<i32, Value>(2).unwrap());
|
assert_eq!(Value::Integer(1), row.get_checked::<_, Value>(2).unwrap());
|
||||||
match row.get_checked::<i32, Value>(3).unwrap() {
|
match row.get_checked::<_, Value>(3).unwrap() {
|
||||||
Value::Real(val) => assert!((1.5 - val).abs() < EPSILON),
|
Value::Real(val) => assert!((1.5 - val).abs() < EPSILON),
|
||||||
x => panic!("Invalid Value {:?}", x),
|
x => panic!("Invalid Value {:?}", x),
|
||||||
}
|
}
|
||||||
assert_eq!(Value::Null, row.get_checked::<i32, Value>(4).unwrap());
|
assert_eq!(Value::Null, row.get_checked::<_, Value>(4).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user