mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Fix warnings from latest rustc
This commit is contained in:
parent
31d629070e
commit
ee89f8db59
@ -48,7 +48,7 @@ pub const SQLITE_NULL : c_int = 5;
|
|||||||
pub type SqliteDestructor = extern "C" fn(*mut c_void);
|
pub type SqliteDestructor = extern "C" fn(*mut c_void);
|
||||||
|
|
||||||
pub fn SQLITE_TRANSIENT() -> SqliteDestructor {
|
pub fn SQLITE_TRANSIENT() -> SqliteDestructor {
|
||||||
unsafe { mem::transmute(-1is) }
|
unsafe { mem::transmute(-1isize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn code_to_str(code: c_int) -> &'static str {
|
pub fn code_to_str(code: c_int) -> &'static str {
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
#![feature(unsafe_destructor, core, std_misc, path, libc, rustc_private, collections, hash)]
|
#![feature(unsafe_destructor, core, std_misc, path, libc, rustc_private, collections)]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
@ -425,7 +425,7 @@ bitflags! {
|
|||||||
|
|
||||||
impl InnerSqliteConnection {
|
impl InnerSqliteConnection {
|
||||||
fn open_with_flags(path: &str, flags: SqliteOpenFlags) -> SqliteResult<InnerSqliteConnection> {
|
fn open_with_flags(path: &str, flags: SqliteOpenFlags) -> SqliteResult<InnerSqliteConnection> {
|
||||||
let c_path = CString::from_slice(path.as_bytes());
|
let c_path = try!(str_to_cstring(path));
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut db: *mut ffi::sqlite3 = mem::uninitialized();
|
let mut db: *mut ffi::sqlite3 = mem::uninitialized();
|
||||||
let r = ffi::sqlite3_open_v2(c_path.as_ptr(), &mut db, flags.bits(), ptr::null());
|
let r = ffi::sqlite3_open_v2(c_path.as_ptr(), &mut db, flags.bits(), ptr::null());
|
||||||
@ -476,7 +476,7 @@ impl InnerSqliteConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn execute_batch(&mut self, sql: &str) -> SqliteResult<()> {
|
fn execute_batch(&mut self, sql: &str) -> SqliteResult<()> {
|
||||||
let c_sql = CString::from_slice(sql.as_bytes());
|
let c_sql = try!(str_to_cstring(sql));
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut errmsg: *mut c_char = mem::uninitialized();
|
let mut errmsg: *mut c_char = mem::uninitialized();
|
||||||
let r = ffi::sqlite3_exec(self.db, c_sql.as_ptr(), None, ptr::null_mut(), &mut errmsg);
|
let r = ffi::sqlite3_exec(self.db, c_sql.as_ptr(), None, ptr::null_mut(), &mut errmsg);
|
||||||
@ -515,7 +515,7 @@ impl InnerSqliteConnection {
|
|||||||
conn: &'a SqliteConnection,
|
conn: &'a SqliteConnection,
|
||||||
sql: &str) -> SqliteResult<SqliteStatement<'a>> {
|
sql: &str) -> SqliteResult<SqliteStatement<'a>> {
|
||||||
let mut c_stmt: *mut ffi::sqlite3_stmt = unsafe { mem::uninitialized() };
|
let mut c_stmt: *mut ffi::sqlite3_stmt = unsafe { mem::uninitialized() };
|
||||||
let c_sql = CString::from_slice(sql.as_bytes());
|
let c_sql = try!(str_to_cstring(sql));
|
||||||
let r = unsafe {
|
let r = unsafe {
|
||||||
let len_with_nul = (sql.len() + 1) as c_int;
|
let len_with_nul = (sql.len() + 1) as c_int;
|
||||||
ffi::sqlite3_prepare_v2(self.db, c_sql.as_ptr(), len_with_nul, &mut c_stmt,
|
ffi::sqlite3_prepare_v2(self.db, c_sql.as_ptr(), len_with_nul, &mut c_stmt,
|
||||||
|
13
src/types.rs
13
src/types.rs
@ -55,12 +55,11 @@
|
|||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use libc::{c_int, c_double, c_char};
|
use libc::{c_int, c_double, c_char};
|
||||||
use std::ffi as std_ffi;
|
use std::ffi::{CStr};
|
||||||
use std::ffi::{CString};
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::str;
|
use std::str;
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
use super::{SqliteResult, SqliteError};
|
use super::{SqliteResult, SqliteError, str_to_cstring};
|
||||||
|
|
||||||
const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S";
|
const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S";
|
||||||
|
|
||||||
@ -90,8 +89,11 @@ raw_to_impl!(c_double, sqlite3_bind_double);
|
|||||||
|
|
||||||
impl<'a> ToSql for &'a str {
|
impl<'a> ToSql for &'a str {
|
||||||
unsafe fn bind_parameter(&self, stmt: *mut ffi::sqlite3_stmt, col: c_int) -> c_int {
|
unsafe fn bind_parameter(&self, stmt: *mut ffi::sqlite3_stmt, col: c_int) -> c_int {
|
||||||
let c_str = CString::from_slice(self.as_bytes());
|
if let Ok(c_str) = str_to_cstring(self) {
|
||||||
ffi::sqlite3_bind_text(stmt, col, c_str.as_ptr(), -1, Some(ffi::SQLITE_TRANSIENT()))
|
ffi::sqlite3_bind_text(stmt, col, c_str.as_ptr(), -1, Some(ffi::SQLITE_TRANSIENT()))
|
||||||
|
} else {
|
||||||
|
ffi::SQLITE_MISUSE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,8 +179,7 @@ impl FromSql for String {
|
|||||||
if c_text.is_null() {
|
if c_text.is_null() {
|
||||||
Ok("".to_string())
|
Ok("".to_string())
|
||||||
} else {
|
} else {
|
||||||
let c_text = c_text as *const c_char;
|
let c_slice = CStr::from_ptr(c_text as *const c_char).to_bytes();
|
||||||
let c_slice = std_ffi::c_str_to_bytes(&c_text);
|
|
||||||
let utf8_str = str::from_utf8(c_slice);
|
let utf8_str = str::from_utf8(c_slice);
|
||||||
utf8_str
|
utf8_str
|
||||||
.map(|s| { s.to_string() })
|
.map(|s| { s.to_string() })
|
||||||
|
Loading…
Reference in New Issue
Block a user