Skip to content

Commit 330327a

Browse files
committed
Do not make use of globs feature
`pub use` globs will be removed from the language, but non-public globs are still buggy, see: rust-lang/rust#3352
1 parent e4c900d commit 330327a

File tree

4 files changed

+92
-54
lines changed

4 files changed

+92
-54
lines changed

src/sqlite3/database.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@
2929
** POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32-
use statement::*;
33-
use ffi::*;
32+
use types::{ResultCode,
33+
SQLITE_OK,
34+
SQLITE_ERROR};
35+
36+
use types::{dbh,
37+
SqliteResult};
38+
39+
use statement::Statement;
40+
use ffi;
41+
3442
use libc::c_int;
3543
use std::ptr;
3644
use std::str;
37-
use types::*;
3845

3946
/// The database connection.
4047
pub struct Database {
@@ -51,19 +58,17 @@ impl Drop for Database {
5158
fn drop(&mut self) {
5259
debug!("`Database.drop()`: dbh={:?}", self.dbh);
5360
unsafe {
54-
sqlite3_close(self.dbh);
61+
ffi::sqlite3_close(self.dbh);
5562
}
5663
}
5764
}
5865

5966
impl Database {
60-
6167
/// Returns the error message of the the most recent call.
6268
/// See http://www.sqlite.org/c3ref/errcode.html
6369
pub fn get_errmsg(&self) -> ~str {
6470
unsafe {
65-
str::raw::from_c_str(sqlite3_errmsg(self.dbh))
66-
}
71+
str::raw::from_c_str(ffi::sqlite3_errmsg(self.dbh)) }
6772
}
6873

6974
/// Prepares/compiles an SQL statement.
@@ -72,7 +77,7 @@ impl Database {
7277
let new_stmt = ptr::null();
7378
let r = sql.with_c_str( |_sql| {
7479
unsafe {
75-
sqlite3_prepare_v2(self.dbh, _sql, sql.len() as c_int, &new_stmt, ptr::null())
80+
ffi::sqlite3_prepare_v2(self.dbh, _sql, sql.len() as c_int, &new_stmt, ptr::null())
7681
}
7782
});
7883
if r == SQLITE_OK {
@@ -89,7 +94,7 @@ impl Database {
8994
let mut r = SQLITE_ERROR;
9095
sql.with_c_str( |_sql| {
9196
unsafe {
92-
r = sqlite3_exec(self.dbh, _sql, ptr::null(), ptr::null(), ptr::null())
97+
r = ffi::sqlite3_exec(self.dbh, _sql, ptr::null(), ptr::null(), ptr::null())
9398
}
9499
});
95100

@@ -101,23 +106,23 @@ impl Database {
101106
/// See http://www.sqlite.org/c3ref/changes.html
102107
pub fn get_changes(&self) -> int {
103108
unsafe {
104-
sqlite3_changes(self.dbh) as int
109+
ffi::sqlite3_changes(self.dbh) as int
105110
}
106111
}
107112

108113
/// Returns the ID of the last inserted row.
109114
/// See http://www.sqlite.org/c3ref/last_insert_rowid.html
110115
pub fn get_last_insert_rowid(&self) -> i64 {
111116
unsafe {
112-
sqlite3_last_insert_rowid(self.dbh)
117+
ffi::sqlite3_last_insert_rowid(self.dbh)
113118
}
114119
}
115120

116121
/// Sets a busy timeout.
117122
/// See http://www.sqlite.org/c3ref/busy_timeout.html
118123
pub fn set_busy_timeout(&self, ms: int) -> ResultCode {
119124
unsafe {
120-
sqlite3_busy_timeout(self.dbh, ms as c_int)
125+
ffi::sqlite3_busy_timeout(self.dbh, ms as c_int)
121126
}
122127
}
123128
}

src/sqlite3/ffi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
** POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32-
use libc::*;
33-
use types::*;
32+
use libc::{c_char,c_int,c_void};
33+
use types::{ResultCode,stmt,dbh,_notused};
3434

3535
#[link(name = "sqlite3")]
3636
extern {

src/sqlite3/lib.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![crate_id="sqlite3#0.1"]
22
#![crate_type = "lib"]
3-
#![feature(globs, phase)]
3+
#![feature(phase)]
44
#[phase(syntax, link)] extern crate log;
55

66
/*
@@ -37,15 +37,18 @@
3737
extern crate libc;
3838
extern crate collections;
3939

40-
pub use statement::*;
41-
pub use database::*;
42-
use ffi::*;
43-
pub use types::*;
40+
pub use database::Database;
41+
pub use statement::Statement;
42+
pub use types::SqliteResult;
43+
44+
use types::{SQLITE_OK,SQLITE_NOMEM};
45+
use ffi::{sqlite3_complete};
46+
4447
use std::ptr;
4548

46-
pub mod statement;
47-
pub mod database;
4849
mod ffi;
50+
mod database;
51+
mod statement;
4952

5053
#[allow(non_camel_case_types)]
5154
pub mod types;
@@ -79,26 +82,27 @@ pub fn open(path: &str) -> SqliteResult<Database> {
7982
let dbh = ptr::null();
8083
let r = path.with_c_str( |_path| {
8184
unsafe {
82-
sqlite3_open(_path, &dbh)
85+
ffi::sqlite3_open(_path, &dbh)
8386
}
8487
});
8588
if r != SQLITE_OK {
8689
unsafe {
87-
sqlite3_close(dbh);
90+
ffi::sqlite3_close(dbh);
8891
}
8992
Err(r)
9093
} else {
9194
debug!("`open()`: dbh={:?}", dbh);
92-
Ok(database_with_handle(dbh))
95+
Ok(database::database_with_handle(dbh))
9396
}
9497
}
9598

9699
#[cfg(test)]
97100
mod tests {
98-
use statement::*;
99-
use database::*;
100-
use super::*;
101-
use types::*;
101+
use types::{Integer,Integer64,Text,Float64,StaticText};
102+
use types::{SQLITE_DONE,SQLITE_ROW,SQLITE_OK};
103+
use types::{SqliteResult};
104+
use statement::Statement;
105+
use database::Database;
102106

103107
fn checked_prepare<'db>(database: &'db Database, sql: &str) -> Statement<'db> {
104108
match database.prepare(sql, &None) {
@@ -108,7 +112,7 @@ mod tests {
108112
}
109113

110114
fn checked_open() -> Database {
111-
match open(":memory:") {
115+
match super::open(":memory:") {
112116
Ok(database) => database,
113117
Err(ref e) => fail!(e.to_str()),
114118
}
@@ -323,8 +327,8 @@ mod tests {
323327
324328
#[test]
325329
fn check_complete_sql() {
326-
let r1 = sqlite_complete("SELECT * FROM");
327-
let r2 = sqlite_complete("SELECT * FROM bob;");
330+
let r1 = super::sqlite_complete("SELECT * FROM");
331+
let r2 = super::sqlite_complete("SELECT * FROM bob;");
328332
assert!(is_ok_and(r1, false));
329333
assert!(is_ok_and(r2, true));
330334

0 commit comments

Comments
 (0)