Merge pull request #239 from gwenn/clippy

Fix clippy warnings
This commit is contained in:
John Gallagher 2017-02-28 09:33:21 -05:00 committed by GitHub
commit e536ce02e8
5 changed files with 18 additions and 17 deletions

View File

@ -4,12 +4,12 @@ extern crate test;
extern crate rusqlite; extern crate rusqlite;
use rusqlite::Connection; use rusqlite::Connection;
use rusqlite::cache::StatementCache;
use test::Bencher; use test::Bencher;
#[bench] #[bench]
fn bench_no_cache(b: &mut Bencher) { fn bench_no_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
db.set_prepared_statement_cache_capacity(0);
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71"; let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| db.prepare(sql).unwrap()); b.iter(|| db.prepare(sql).unwrap());
} }
@ -17,7 +17,6 @@ fn bench_no_cache(b: &mut Bencher) {
#[bench] #[bench]
fn bench_cache(b: &mut Bencher) { fn bench_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
let cache = StatementCache::new(&db, 15);
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71"; let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| cache.get(sql).unwrap()); b.iter(|| db.prepare_cached(sql).unwrap());
} }

View File

@ -79,7 +79,7 @@ fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
ValueRef::Null => unsafe { ffi::sqlite3_result_null(ctx) }, ValueRef::Null => unsafe { ffi::sqlite3_result_null(ctx) },
ValueRef::Integer(i) => unsafe { ffi::sqlite3_result_int64(ctx, i) }, ValueRef::Integer(i) => unsafe { ffi::sqlite3_result_int64(ctx, i) },
ValueRef::Real(r) => unsafe { ffi::sqlite3_result_double(ctx, r) }, ValueRef::Real(r) => unsafe { ffi::sqlite3_result_double(ctx, r) },
ValueRef::Text(ref s) => unsafe { ValueRef::Text(s) => unsafe {
let length = s.len(); let length = s.len();
if length > ::std::i32::MAX as usize { if length > ::std::i32::MAX as usize {
ffi::sqlite3_result_error_toobig(ctx); ffi::sqlite3_result_error_toobig(ctx);
@ -97,7 +97,7 @@ fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
ffi::sqlite3_result_text(ctx, c_str.as_ptr(), length as c_int, destructor); ffi::sqlite3_result_text(ctx, c_str.as_ptr(), length as c_int, destructor);
} }
}, },
ValueRef::Blob(ref b) => unsafe { ValueRef::Blob(b) => unsafe {
let length = b.len(); let length = b.len();
if length > ::std::i32::MAX as usize { if length > ::std::i32::MAX as usize {
ffi::sqlite3_result_error_toobig(ctx); ffi::sqlite3_result_error_toobig(ctx);
@ -114,8 +114,8 @@ fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
} }
unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) { unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) {
match err { match *err {
&Error::SqliteFailure(ref err, ref s) => { Error::SqliteFailure(ref err, ref s) => {
ffi::sqlite3_result_error_code(ctx, err.extended_code); ffi::sqlite3_result_error_code(ctx, err.extended_code);
if let Some(Ok(cstr)) = s.as_ref().map(|s| str_to_cstring(s)) { if let Some(Ok(cstr)) = s.as_ref().map(|s| str_to_cstring(s)) {
ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1); ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1);

View File

@ -596,7 +596,8 @@ fn ensure_valid_sqlite_version() {
let runtime_major = version_number / 1_000_000; let runtime_major = version_number / 1_000_000;
if buildtime_major != runtime_major { if buildtime_major != runtime_major {
panic!("rusqlite was built against SQLite {} but is running with SQLite {}", panic!("rusqlite was built against SQLite {} but is running with SQLite {}",
str::from_utf8(ffi::SQLITE_VERSION).unwrap(), version()); str::from_utf8(ffi::SQLITE_VERSION).unwrap(),
version());
} }
if BYPASS_VERSION_CHECK.load(Ordering::Relaxed) { if BYPASS_VERSION_CHECK.load(Ordering::Relaxed) {
@ -611,7 +612,9 @@ rusqlite was built against SQLite {} but the runtime SQLite version is {}. To fi
* Recompile rusqlite and link against the SQLite version you are using at runtime, or * Recompile rusqlite and link against the SQLite version you are using at runtime, or
* Call rusqlite::bypass_sqlite_version_check() prior to your first connection attempt. Doing this * Call rusqlite::bypass_sqlite_version_check() prior to your first connection attempt. Doing this
means you're sure everything will work correctly even though the runtime version is older than means you're sure everything will work correctly even though the runtime version is older than
the version we found at build time.", str::from_utf8(ffi::SQLITE_VERSION).unwrap(), version()); the version we found at build time.",
str::from_utf8(ffi::SQLITE_VERSION).unwrap(),
version());
} }
}); });
} }
@ -683,9 +686,9 @@ impl InnerConnection {
// Replicate the check for sane open flags from SQLite, because the check in SQLite itself // Replicate the check for sane open flags from SQLite, because the check in SQLite itself
// wasn't added until version 3.7.3. // wasn't added until version 3.7.3.
debug_assert!(1 << SQLITE_OPEN_READ_ONLY.bits == 0x02); debug_assert!(1 << SQLITE_OPEN_READ_ONLY.bits == 0x02);
debug_assert!(1 << SQLITE_OPEN_READ_WRITE.bits == 0x04); debug_assert!(1 << SQLITE_OPEN_READ_WRITE.bits == 0x04);
debug_assert!(1 << (SQLITE_OPEN_READ_WRITE|SQLITE_OPEN_CREATE).bits == 0x40); debug_assert!(1 << (SQLITE_OPEN_READ_WRITE | SQLITE_OPEN_CREATE).bits == 0x40);
if (1 << (flags.bits & 0x7)) & 0x46 == 0 { if (1 << (flags.bits & 0x7)) & 0x46 == 0 {
return Err(Error::SqliteFailure(ffi::Error::new(ffi::SQLITE_MISUSE), None)); return Err(Error::SqliteFailure(ffi::Error::new(ffi::SQLITE_MISUSE), None));
} }

View File

@ -104,9 +104,8 @@ impl FromSql for DateTime<UTC> {
Cow::Borrowed(s) Cow::Borrowed(s)
}; };
match DateTime::parse_from_rfc3339(&s) { if let Ok(dt) = DateTime::parse_from_rfc3339(&s) {
Ok(dt) => return Ok(dt.with_timezone(&UTC)), return Ok(dt.with_timezone(&UTC));
Err(_) => (),
} }
} }

View File

@ -17,8 +17,8 @@ impl ToSql for Value {
impl FromSql for Value { impl FromSql for Value {
fn column_result(value: ValueRef) -> FromSqlResult<Self> { fn column_result(value: ValueRef) -> FromSqlResult<Self> {
match value { match value {
ValueRef::Text(ref s) => serde_json::from_str(s), ValueRef::Text(s) => serde_json::from_str(s),
ValueRef::Blob(ref b) => serde_json::from_slice(b), ValueRef::Blob(b) => serde_json::from_slice(b),
_ => return Err(FromSqlError::InvalidType), _ => return Err(FromSqlError::InvalidType),
} }
.map_err(|err| FromSqlError::Other(Box::new(err))) .map_err(|err| FromSqlError::Other(Box::new(err)))