From 5c44ed79d3eecf616c7b68c59cdc34cb3f693d44 Mon Sep 17 00:00:00 2001 From: gwenn Date: Wed, 23 May 2018 20:18:18 +0200 Subject: [PATCH 1/3] Fix tests --- src/cache.rs | 16 +++++----- src/types/mod.rs | 76 ++++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 86db9e3..cef1aca 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -177,14 +177,14 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(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(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); } assert_eq!(1, cache.len()); @@ -202,7 +202,7 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); } assert_eq!(1, cache.len()); @@ -212,7 +212,7 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); } assert_eq!(0, cache.len()); @@ -220,7 +220,7 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); } assert_eq!(1, cache.len()); } @@ -234,7 +234,7 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); stmt.discard(); } assert_eq!(0, cache.len()); @@ -298,14 +298,14 @@ mod test { { let mut stmt = db.prepare_cached(sql).unwrap(); assert_eq!(0, cache.len()); - assert_eq!(0, stmt.query_row(&[], |r| r.get::(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(&[], |r| r.get::(0)).unwrap()); + assert_eq!(0, stmt.query_row(&[], |r| r.get::<_, i64>(0)).unwrap()); } assert_eq!(1, cache.len()); } diff --git a/src/types/mod.rs b/src/types/mod.rs index 74757cb..8aa399e 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -243,57 +243,57 @@ mod test { let row = rows.next().unwrap().unwrap(); // check the correct types come back as expected - assert_eq!(vec![1, 2], row.get_checked::>(0).unwrap()); - assert_eq!("text", row.get_checked::(1).unwrap()); - assert_eq!(1, row.get_checked::(2).unwrap()); - assert!((1.5 - row.get_checked::(3).unwrap()).abs() < EPSILON); - assert!(row.get_checked::>(4) + assert_eq!(vec![1, 2], row.get_checked::<_, Vec>(0).unwrap()); + assert_eq!("text", row.get_checked::<_, String>(1).unwrap()); + assert_eq!(1, row.get_checked::<_, c_int>(2).unwrap()); + assert!((1.5 - row.get_checked::<_, c_double>(3).unwrap()).abs() < EPSILON); + assert!(row.get_checked::<_, Option>(4) .unwrap() .is_none()); - assert!(row.get_checked::>(4) + assert!(row.get_checked::<_, Option>(4) .unwrap() .is_none()); - assert!(row.get_checked::>(4) + assert!(row.get_checked::<_, Option>(4) .unwrap() .is_none()); // check some invalid types // 0 is actually a blob (Vec) - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(0).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(0).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, 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::<_, i64>(0).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_double>(0).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, String>(0).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, time::Timespec>(0).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Option>(0).err().unwrap())); // 1 is actually a text (String) - assert!(is_invalid_column_type(row.get_checked::(1).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(1).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(1).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(1).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(1).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_int>(1).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, i64>(1).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_double>(1).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Vec>(1).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Option>(1).err().unwrap())); // 2 is actually an integer - assert!(is_invalid_column_type(row.get_checked::(2).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(2).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(2).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, String>(2).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Vec>(2).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Option>(2).err().unwrap())); // 3 is actually a float (c_double) - assert!(is_invalid_column_type(row.get_checked::(3).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(3).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(3).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(3).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(3).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_int>(3).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, i64>(3).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, String>(3).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Vec>(3).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Option>(3).err().unwrap())); // 4 is actually NULL - assert!(is_invalid_column_type(row.get_checked::(4).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(4).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(4).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(4).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::>(4).err().unwrap())); - assert!(is_invalid_column_type(row.get_checked::(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_int>(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, i64>(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, c_double>(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, String>(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, Vec>(4).err().unwrap())); + assert!(is_invalid_column_type(row.get_checked::<_, time::Timespec>(4).err().unwrap())); } #[test] @@ -310,14 +310,14 @@ mod test { let row = rows.next().unwrap().unwrap(); assert_eq!(Value::Blob(vec![1, 2]), - row.get_checked::(0).unwrap()); + row.get_checked::<_, Value>(0).unwrap()); assert_eq!(Value::Text(String::from("text")), - row.get_checked::(1).unwrap()); - assert_eq!(Value::Integer(1), row.get_checked::(2).unwrap()); - match row.get_checked::(3).unwrap() { + row.get_checked::<_, Value>(1).unwrap()); + assert_eq!(Value::Integer(1), row.get_checked::<_, Value>(2).unwrap()); + match row.get_checked::<_, Value>(3).unwrap() { Value::Real(val) => assert!((1.5 - val).abs() < EPSILON), x => panic!("Invalid Value {:?}", x), } - assert_eq!(Value::Null, row.get_checked::(4).unwrap()); + assert_eq!(Value::Null, row.get_checked::<_, Value>(4).unwrap()); } } From c6f4ae632a84eb1d8197cfbd418b27643a73c0fa Mon Sep 17 00:00:00 2001 From: gwenn Date: Wed, 23 May 2018 21:04:13 +0200 Subject: [PATCH 2/3] Replace column index/count type (i32) with usize Breaking change --- src/error.rs | 8 ++++---- src/functions.rs | 2 +- src/lib.rs | 2 +- src/raw_statement.rs | 20 ++++++++++---------- src/row.rs | 12 ++++++------ src/statement.rs | 38 +++++++++++++++++++------------------- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7bfe057..09e2e1d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -26,9 +26,9 @@ pub enum Error { FromSqlConversionFailure(usize, Type, Box), /// 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. - IntegralValueOutOfRange(c_int, i64), + IntegralValueOutOfRange(usize, i64), /// Error converting a string to UTF-8. 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 /// for the statement. - InvalidColumnIndex(c_int), + InvalidColumnIndex(usize), /// Error when the value of a named column is requested, but no column matches the name /// for the statement. @@ -59,7 +59,7 @@ pub enum Error { /// 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. - 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. StatementChangedRows(c_int), diff --git a/src/functions.rs b/src/functions.rs index a79b3e6..91aecf2 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -216,7 +216,7 @@ impl<'a> Context<'a> { Error::InvalidFunctionParameterType(idx, value.data_type()) } FromSqlError::OutOfRange(i) => { - Error::IntegralValueOutOfRange(idx as c_int, + Error::IntegralValueOutOfRange(idx, i) } FromSqlError::Other(err) => { diff --git a/src/lib.rs b/src/lib.rs index 21cfa15..ee8cd63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -931,7 +931,7 @@ impl InnerConnection { stmt = ffi::sqlite3_next_stmt(db, stmt); } } - return false; + false } #[cfg(not(feature = "hooks"))] diff --git a/src/raw_statement.rs b/src/raw_statement.rs index 3c33ea3..5b99b8c 100644 --- a/src/raw_statement.rs +++ b/src/raw_statement.rs @@ -17,16 +17,16 @@ impl RawStatement { self.0 } - pub fn column_count(&self) -> c_int { - unsafe { ffi::sqlite3_column_count(self.0) } + pub fn column_count(&self) -> usize { + unsafe { ffi::sqlite3_column_count(self.0) as usize } } - pub fn column_type(&self, idx: c_int) -> c_int { - unsafe { ffi::sqlite3_column_type(self.0, idx) } + pub fn column_type(&self, idx: usize) -> c_int { + unsafe { ffi::sqlite3_column_type(self.0, idx as c_int) } } - pub fn column_name(&self, idx: c_int) -> &CStr { - unsafe { CStr::from_ptr(ffi::sqlite3_column_name(self.0, idx)) } + pub fn column_name(&self, idx: usize) -> &CStr { + unsafe { CStr::from_ptr(ffi::sqlite3_column_name(self.0, idx as c_int)) } } pub fn step(&self) -> c_int { @@ -54,15 +54,15 @@ impl RawStatement { unsafe { ffi::sqlite3_reset(self.0) } } - pub fn bind_parameter_count(&self) -> c_int { - unsafe { ffi::sqlite3_bind_parameter_count(self.0) } + pub fn bind_parameter_count(&self) -> usize { + unsafe { ffi::sqlite3_bind_parameter_count(self.0) as usize } } - pub fn bind_parameter_index(&self, name: &CStr) -> Option { + pub fn bind_parameter_index(&self, name: &CStr) -> Option { let r = unsafe { ffi::sqlite3_bind_parameter_index(self.0, name.as_ptr()) }; match r { 0 => None, - i => Some(i), + i => Some(i as usize), } } diff --git a/src/row.rs b/src/row.rs index 2042616..775e69a 100644 --- a/src/row.rs +++ b/src/row.rs @@ -192,7 +192,7 @@ impl<'a, 'stmt> Row<'a, 'stmt> { } /// 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() } } @@ -201,13 +201,13 @@ impl<'a, 'stmt> Row<'a, 'stmt> { pub trait RowIndex { /// Returns the index of the appropriate column, or `None` if no such /// column exists. - fn idx(&self, stmt: &Statement) -> Result; + fn idx(&self, stmt: &Statement) -> Result; } -impl RowIndex for i32 { +impl RowIndex for usize { #[inline] - fn idx(&self, stmt: &Statement) -> Result { - if *self < 0 || *self >= stmt.column_count() { + fn idx(&self, stmt: &Statement) -> Result { + if *self >= stmt.column_count() { Err(Error::InvalidColumnIndex(*self)) } else { Ok(*self) @@ -217,7 +217,7 @@ impl RowIndex for i32 { impl<'a> RowIndex for &'a str { #[inline] - fn idx(&self, stmt: &Statement) -> Result { + fn idx(&self, stmt: &Statement) -> Result { stmt.column_index(*self) } } diff --git a/src/statement.rs b/src/statement.rs index c867ad4..4f194a6 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -29,7 +29,7 @@ impl<'conn> Statement<'conn> { } /// 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() } @@ -41,7 +41,7 @@ impl<'conn> Statement<'conn> { /// # Failure /// /// Will return an `Error::InvalidColumnName` when there is no column with the specified `name`. - pub fn column_index(&self, name: &str) -> Result { + pub fn column_index(&self, name: &str) -> Result { let bytes = name.as_bytes(); let n = self.column_count(); for i in 0..n { @@ -362,19 +362,19 @@ impl<'conn> Statement<'conn> { /// /// Will return Err if `name` is invalid. Will return Ok(None) if the name /// is valid but not a bound parameter of this statement. - pub fn parameter_index(&self, name: &str) -> Result> { + pub fn parameter_index(&self, name: &str) -> Result> { let c_name = try!(str_to_cstring(name)); Ok(self.stmt.bind_parameter_index(&c_name)) } 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 {}", self.stmt.bind_parameter_count(), params.len()); 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(()) @@ -391,7 +391,7 @@ impl<'conn> Statement<'conn> { 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 ptr = unsafe { self.stmt.ptr() }; @@ -402,17 +402,17 @@ impl<'conn> Statement<'conn> { #[cfg(feature = "blob")] ToSqlOutput::ZeroBlob(len) => { 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) }); } }; self.conn .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 { - ffi::sqlite3_bind_int64(ptr, col, i) + ffi::sqlite3_bind_int64(ptr, col as c_int, i) }, 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 { let length = s.len(); @@ -425,7 +425,7 @@ impl<'conn> Statement<'conn> { } else { 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 { @@ -433,10 +433,10 @@ impl<'conn> Statement<'conn> { if length > ::std::i32::MAX as usize { ffi::SQLITE_TOOBIG } else if length == 0 { - ffi::sqlite3_bind_zeroblob(ptr, col, 0) + ffi::sqlite3_bind_zeroblob(ptr, col as c_int, 0) } else { ffi::sqlite3_bind_blob(ptr, - col, + col as c_int, b.as_ptr() as *const c_void, length as c_int, ffi::SQLITE_TRANSIENT()) @@ -498,7 +498,7 @@ impl<'conn> Drop for Statement<'conn> { // once pub(crate) is stable. pub trait StatementCrateImpl<'conn> { 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; fn reset(&self) -> c_int; } @@ -511,18 +511,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() }; match self.stmt.column_type(col) { ffi::SQLITE_NULL => ValueRef::Null, 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 => { 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(), "unexpected SQLITE_TEXT column type with NULL data"); CStr::from_ptr(text as *const c_char) @@ -535,7 +535,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { } ffi::SQLITE_BLOB => { 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, From 0d0a7bf81f551b8c7f0b269d3839eb100c43f4ce Mon Sep 17 00:00:00 2001 From: gwenn Date: Wed, 23 May 2018 21:23:28 +0200 Subject: [PATCH 3/3] Replace row changes/count type (i32) with usize Breaking change --- src/error.rs | 2 +- src/lib.rs | 12 ++++++------ src/statement.rs | 8 ++++---- src/types/mod.rs | 3 +-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/error.rs b/src/error.rs index 09e2e1d..adca04d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -62,7 +62,7 @@ pub enum Error { InvalidColumnType(usize, Type), /// 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 /// to the requested type. diff --git a/src/lib.rs b/src/lib.rs index ee8cd63..fadfbdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -305,7 +305,7 @@ impl Connection { /// /// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the /// underlying SQLite call fails. - pub fn execute(&self, sql: &str, params: &[&ToSql]) -> Result { + pub fn execute(&self, sql: &str, params: &[&ToSql]) -> Result { self.prepare(sql) .and_then(|mut stmt| stmt.execute(params)) } @@ -319,7 +319,7 @@ impl Connection { /// /// ```rust,no_run /// # use rusqlite::{Connection, Result}; - /// fn insert(conn: &Connection) -> Result { + /// fn insert(conn: &Connection) -> Result { /// conn.execute_named("INSERT INTO test (name) VALUES (:name)", &[(":name", &"one")]) /// } /// ``` @@ -328,7 +328,7 @@ impl Connection { /// /// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the /// underlying SQLite call fails. - pub fn execute_named(&self, sql: &str, params: &[(&str, &ToSql)]) -> Result { + pub fn execute_named(&self, sql: &str, params: &[(&str, &ToSql)]) -> Result { self.prepare(sql) .and_then(|mut stmt| stmt.execute_named(params)) } @@ -570,7 +570,7 @@ impl Connection { self.db.borrow_mut().decode_result(code) } - fn changes(&self) -> c_int { + fn changes(&self) -> usize { self.db.borrow_mut().changes() } @@ -911,8 +911,8 @@ impl InnerConnection { }) } - fn changes(&mut self) -> c_int { - unsafe { ffi::sqlite3_changes(self.db()) } + fn changes(&mut self) -> usize { + unsafe { ffi::sqlite3_changes(self.db()) as usize } } fn is_autocommit(&self) -> bool { diff --git a/src/statement.rs b/src/statement.rs index 4f194a6..2d44a57 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -75,7 +75,7 @@ impl<'conn> Statement<'conn> { /// /// 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. - pub fn execute(&mut self, params: &[&ToSql]) -> Result { + pub fn execute(&mut self, params: &[&ToSql]) -> Result { try!(self.bind_parameters(params)); self.execute_with_bound_parameters() } @@ -92,7 +92,7 @@ impl<'conn> Statement<'conn> { /// /// ```rust,no_run /// # use rusqlite::{Connection, Result}; - /// fn insert(conn: &Connection) -> Result { + /// fn insert(conn: &Connection) -> Result { /// let mut stmt = try!(conn.prepare("INSERT INTO test (name) VALUES (:name)")); /// stmt.execute_named(&[(":name", &"one")]) /// } @@ -102,7 +102,7 @@ impl<'conn> Statement<'conn> { /// /// 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. - pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result { + pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result { try!(self.bind_parameters_named(params)); self.execute_with_bound_parameters() } @@ -445,7 +445,7 @@ impl<'conn> Statement<'conn> { }) } - fn execute_with_bound_parameters(&mut self) -> Result { + fn execute_with_bound_parameters(&mut self) -> Result { let r = self.stmt.step(); self.stmt.reset(); match r { diff --git a/src/types/mod.rs b/src/types/mod.rs index 8aa399e..459c057 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -77,10 +77,9 @@ mod serde_json; /// # extern crate rusqlite; /// # use rusqlite::{Connection, Result}; /// # use rusqlite::types::{Null}; -/// # use std::os::raw::{c_int}; /// fn main() { /// } -/// fn insert_null(conn: &Connection) -> Result { +/// fn insert_null(conn: &Connection) -> Result { /// conn.execute("INSERT INTO people (name) VALUES (?)", &[&Null]) /// } /// ```