mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Merge branch 'stable' into 'master'
This commit is contained in:
commit
55c173a465
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rusqlite"
|
name = "rusqlite"
|
||||||
version = "0.0.16"
|
version = "0.0.17"
|
||||||
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
||||||
description = "Ergonomic wrapper for SQLite"
|
description = "Ergonomic wrapper for SQLite"
|
||||||
repository = "https://github.com/jgallagher/rusqlite"
|
repository = "https://github.com/jgallagher/rusqlite"
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# Version 0.0.17 (2015-04-03)
|
||||||
|
|
||||||
|
* Publish version that builds on stable rust (beta). This version lives on the
|
||||||
|
`stable` branch. Development continues on `master` and still requires a nightly
|
||||||
|
version of Rust.
|
||||||
|
|
||||||
# Version 0.0.16
|
# Version 0.0.16
|
||||||
|
|
||||||
* Updates to track rustc nightly.
|
* Updates to track rustc nightly.
|
||||||
|
15
src/lib.rs
15
src/lib.rs
@ -47,15 +47,12 @@
|
|||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
#![feature(unique)]
|
|
||||||
#![cfg_attr(test, feature(test))]
|
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate libsqlite3_sys as ffi;
|
extern crate libsqlite3_sys as ffi;
|
||||||
#[macro_use] extern crate bitflags;
|
#[macro_use] extern crate bitflags;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr::{self, Unique};
|
use std::ptr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::{Path};
|
use std::path::{Path};
|
||||||
use std::error;
|
use std::error;
|
||||||
@ -152,6 +149,8 @@ pub struct SqliteConnection {
|
|||||||
db: RefCell<InnerSqliteConnection>,
|
db: RefCell<InnerSqliteConnection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for SqliteConnection {}
|
||||||
|
|
||||||
impl SqliteConnection {
|
impl SqliteConnection {
|
||||||
/// Open a new connection to a SQLite database.
|
/// Open a new connection to a SQLite database.
|
||||||
///
|
///
|
||||||
@ -418,7 +417,7 @@ impl fmt::Debug for SqliteConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct InnerSqliteConnection {
|
struct InnerSqliteConnection {
|
||||||
db: Unique<ffi::Struct_sqlite3>,
|
db: *mut ffi::Struct_sqlite3,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
@ -462,12 +461,12 @@ impl InnerSqliteConnection {
|
|||||||
ffi::sqlite3_close(db);
|
ffi::sqlite3_close(db);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
Ok(InnerSqliteConnection{ db: Unique::new(db) })
|
Ok(InnerSqliteConnection{ db: db })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn db(&self) -> *mut ffi::Struct_sqlite3 {
|
fn db(&self) -> *mut ffi::Struct_sqlite3 {
|
||||||
unsafe {self.db.get() as *const _ as *mut _}
|
self.db
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_result(&mut self, code: c_int) -> SqliteResult<()> {
|
fn decode_result(&mut self, code: c_int) -> SqliteResult<()> {
|
||||||
@ -491,7 +490,7 @@ impl InnerSqliteConnection {
|
|||||||
fn close(&mut self) -> SqliteResult<()> {
|
fn close(&mut self) -> SqliteResult<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let r = ffi::sqlite3_close(self.db());
|
let r = ffi::sqlite3_close(self.db());
|
||||||
self.db = Unique::new(ptr::null_mut());
|
self.db = ptr::null_mut();
|
||||||
self.decode_result(r)
|
self.decode_result(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,6 @@ impl<'conn> Drop for SqliteTransaction<'conn> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
extern crate test;
|
|
||||||
use SqliteConnection;
|
use SqliteConnection;
|
||||||
|
|
||||||
fn checked_memory_handle() -> SqliteConnection {
|
fn checked_memory_handle() -> SqliteConnection {
|
||||||
@ -231,32 +230,4 @@ mod test {
|
|||||||
}
|
}
|
||||||
assert_eq!(3i32, db.query_row("SELECT SUM(x) FROM foo", &[], |r| r.get(0)));
|
assert_eq!(3i32, db.query_row("SELECT SUM(x) FROM foo", &[], |r| r.get(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn test_no_transaction_insert(bencher: &mut test::Bencher) {
|
|
||||||
let db = checked_memory_handle();
|
|
||||||
|
|
||||||
let mut stmt = db.prepare("INSERT INTO foo VALUES(1)").unwrap();
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
|
||||||
for _ in 0i32 .. 1000 {
|
|
||||||
stmt.execute(&[]).unwrap();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[bench]
|
|
||||||
fn test_transaction_insert(bencher: &mut test::Bencher) {
|
|
||||||
let db = checked_memory_handle();
|
|
||||||
|
|
||||||
let mut stmt = db.prepare("INSERT INTO foo VALUES(1)").unwrap();
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
|
||||||
let mut tx = db.transaction().unwrap();
|
|
||||||
tx.set_commit();
|
|
||||||
for _ in 0i32 .. 1000 {
|
|
||||||
stmt.execute(&[]).unwrap();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user