Merge pull request #255 from jgallagher/fix-duplicated-constants

Avoid publicly exporting constants from libsqlite3-sys multiple times.
This commit is contained in:
John Gallagher 2017-04-05 14:31:31 -04:00 committed by GitHub
commit 401d1f81e1
5 changed files with 110 additions and 93 deletions

View File

@ -1,5 +1,6 @@
# Version 0.10.2 (UPCOMING)
* Avoid publicly exporting SQLite constants multiple times from libsqlite3-sys.
* Adds `FromSql` and `ToSql` impls for `isize`. Documents why `usize` and `u64` are not included.
# Version 0.10.1 (2017-03-03)

View File

@ -1,6 +1,6 @@
[package]
name = "libsqlite3-sys"
version = "0.7.1"
version = "0.7.2"
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
repository = "https://github.com/jgallagher/rusqlite"
description = "Native bindings to the libsqlite3 library"

View File

@ -110,95 +110,98 @@ impl error::Error for Error {
}
// Result codes.
// Note: These are not public because our bindgen bindings export whichever constants are present
// in the current version of SQLite. We repeat them here so we don't have to worry about which
// version of SQLite added which constants, and we only use them to implement code_to_str below.
pub const SQLITE_OK : c_int = 0;
pub const SQLITE_ERROR : c_int = 1;
pub const SQLITE_INTERNAL : c_int = 2;
pub const SQLITE_PERM : c_int = 3;
pub const SQLITE_ABORT : c_int = 4;
pub const SQLITE_BUSY : c_int = 5;
pub const SQLITE_LOCKED : c_int = 6;
pub const SQLITE_NOMEM : c_int = 7;
pub const SQLITE_READONLY : c_int = 8;
pub const SQLITE_INTERRUPT : c_int = 9;
pub const SQLITE_IOERR : c_int = 10;
pub const SQLITE_CORRUPT : c_int = 11;
pub const SQLITE_NOTFOUND : c_int = 12;
pub const SQLITE_FULL : c_int = 13;
pub const SQLITE_CANTOPEN : c_int = 14;
pub const SQLITE_PROTOCOL : c_int = 15;
pub const SQLITE_EMPTY : c_int = 16;
pub const SQLITE_SCHEMA : c_int = 17;
pub const SQLITE_TOOBIG : c_int = 18;
pub const SQLITE_CONSTRAINT: c_int = 19;
pub const SQLITE_MISMATCH : c_int = 20;
pub const SQLITE_MISUSE : c_int = 21;
pub const SQLITE_NOLFS : c_int = 22;
pub const SQLITE_AUTH : c_int = 23;
pub const SQLITE_FORMAT : c_int = 24;
pub const SQLITE_RANGE : c_int = 25;
pub const SQLITE_NOTADB : c_int = 26;
pub const SQLITE_NOTICE : c_int = 27;
pub const SQLITE_WARNING : c_int = 28;
pub const SQLITE_ROW : c_int = 100;
pub const SQLITE_DONE : c_int = 101;
const SQLITE_OK : c_int = 0;
const SQLITE_ERROR : c_int = 1;
const SQLITE_INTERNAL : c_int = 2;
const SQLITE_PERM : c_int = 3;
const SQLITE_ABORT : c_int = 4;
const SQLITE_BUSY : c_int = 5;
const SQLITE_LOCKED : c_int = 6;
const SQLITE_NOMEM : c_int = 7;
const SQLITE_READONLY : c_int = 8;
const SQLITE_INTERRUPT : c_int = 9;
const SQLITE_IOERR : c_int = 10;
const SQLITE_CORRUPT : c_int = 11;
const SQLITE_NOTFOUND : c_int = 12;
const SQLITE_FULL : c_int = 13;
const SQLITE_CANTOPEN : c_int = 14;
const SQLITE_PROTOCOL : c_int = 15;
const SQLITE_EMPTY : c_int = 16;
const SQLITE_SCHEMA : c_int = 17;
const SQLITE_TOOBIG : c_int = 18;
const SQLITE_CONSTRAINT: c_int = 19;
const SQLITE_MISMATCH : c_int = 20;
const SQLITE_MISUSE : c_int = 21;
const SQLITE_NOLFS : c_int = 22;
const SQLITE_AUTH : c_int = 23;
const SQLITE_FORMAT : c_int = 24;
const SQLITE_RANGE : c_int = 25;
const SQLITE_NOTADB : c_int = 26;
const SQLITE_NOTICE : c_int = 27;
const SQLITE_WARNING : c_int = 28;
const SQLITE_ROW : c_int = 100;
const SQLITE_DONE : c_int = 101;
// Extended result codes.
pub const SQLITE_IOERR_READ : c_int = (SQLITE_IOERR | (1<<8));
pub const SQLITE_IOERR_SHORT_READ : c_int = (SQLITE_IOERR | (2<<8));
pub const SQLITE_IOERR_WRITE : c_int = (SQLITE_IOERR | (3<<8));
pub const SQLITE_IOERR_FSYNC : c_int = (SQLITE_IOERR | (4<<8));
pub const SQLITE_IOERR_DIR_FSYNC : c_int = (SQLITE_IOERR | (5<<8));
pub const SQLITE_IOERR_TRUNCATE : c_int = (SQLITE_IOERR | (6<<8));
pub const SQLITE_IOERR_FSTAT : c_int = (SQLITE_IOERR | (7<<8));
pub const SQLITE_IOERR_UNLOCK : c_int = (SQLITE_IOERR | (8<<8));
pub const SQLITE_IOERR_RDLOCK : c_int = (SQLITE_IOERR | (9<<8));
pub const SQLITE_IOERR_DELETE : c_int = (SQLITE_IOERR | (10<<8));
pub const SQLITE_IOERR_BLOCKED : c_int = (SQLITE_IOERR | (11<<8));
pub const SQLITE_IOERR_NOMEM : c_int = (SQLITE_IOERR | (12<<8));
pub const SQLITE_IOERR_ACCESS : c_int = (SQLITE_IOERR | (13<<8));
pub const SQLITE_IOERR_CHECKRESERVEDLOCK : c_int = (SQLITE_IOERR | (14<<8));
pub const SQLITE_IOERR_LOCK : c_int = (SQLITE_IOERR | (15<<8));
pub const SQLITE_IOERR_CLOSE : c_int = (SQLITE_IOERR | (16<<8));
pub const SQLITE_IOERR_DIR_CLOSE : c_int = (SQLITE_IOERR | (17<<8));
pub const SQLITE_IOERR_SHMOPEN : c_int = (SQLITE_IOERR | (18<<8));
pub const SQLITE_IOERR_SHMSIZE : c_int = (SQLITE_IOERR | (19<<8));
pub const SQLITE_IOERR_SHMLOCK : c_int = (SQLITE_IOERR | (20<<8));
pub const SQLITE_IOERR_SHMMAP : c_int = (SQLITE_IOERR | (21<<8));
pub const SQLITE_IOERR_SEEK : c_int = (SQLITE_IOERR | (22<<8));
pub const SQLITE_IOERR_DELETE_NOENT : c_int = (SQLITE_IOERR | (23<<8));
pub const SQLITE_IOERR_MMAP : c_int = (SQLITE_IOERR | (24<<8));
pub const SQLITE_IOERR_GETTEMPPATH : c_int = (SQLITE_IOERR | (25<<8));
pub const SQLITE_IOERR_CONVPATH : c_int = (SQLITE_IOERR | (26<<8));
pub const SQLITE_IOERR_VNODE : c_int = (SQLITE_IOERR | (27<<8));
pub const SQLITE_LOCKED_SHAREDCACHE : c_int = (SQLITE_LOCKED | (1<<8));
pub const SQLITE_BUSY_RECOVERY : c_int = (SQLITE_BUSY | (1<<8));
pub const SQLITE_BUSY_SNAPSHOT : c_int = (SQLITE_BUSY | (2<<8));
pub const SQLITE_CANTOPEN_NOTEMPDIR : c_int = (SQLITE_CANTOPEN | (1<<8));
pub const SQLITE_CANTOPEN_ISDIR : c_int = (SQLITE_CANTOPEN | (2<<8));
pub const SQLITE_CANTOPEN_FULLPATH : c_int = (SQLITE_CANTOPEN | (3<<8));
pub const SQLITE_CANTOPEN_CONVPATH : c_int = (SQLITE_CANTOPEN | (4<<8));
pub const SQLITE_CORRUPT_VTAB : c_int = (SQLITE_CORRUPT | (1<<8));
pub const SQLITE_READONLY_RECOVERY : c_int = (SQLITE_READONLY | (1<<8));
pub const SQLITE_READONLY_CANTLOCK : c_int = (SQLITE_READONLY | (2<<8));
pub const SQLITE_READONLY_ROLLBACK : c_int = (SQLITE_READONLY | (3<<8));
pub const SQLITE_READONLY_DBMOVED : c_int = (SQLITE_READONLY | (4<<8));
pub const SQLITE_ABORT_ROLLBACK : c_int = (SQLITE_ABORT | (2<<8));
pub const SQLITE_CONSTRAINT_CHECK : c_int = (SQLITE_CONSTRAINT | (1<<8));
pub const SQLITE_CONSTRAINT_COMMITHOOK : c_int = (SQLITE_CONSTRAINT | (2<<8));
pub const SQLITE_CONSTRAINT_FOREIGNKEY : c_int = (SQLITE_CONSTRAINT | (3<<8));
pub const SQLITE_CONSTRAINT_FUNCTION : c_int = (SQLITE_CONSTRAINT | (4<<8));
pub const SQLITE_CONSTRAINT_NOTNULL : c_int = (SQLITE_CONSTRAINT | (5<<8));
pub const SQLITE_CONSTRAINT_PRIMARYKEY : c_int = (SQLITE_CONSTRAINT | (6<<8));
pub const SQLITE_CONSTRAINT_TRIGGER : c_int = (SQLITE_CONSTRAINT | (7<<8));
pub const SQLITE_CONSTRAINT_UNIQUE : c_int = (SQLITE_CONSTRAINT | (8<<8));
pub const SQLITE_CONSTRAINT_VTAB : c_int = (SQLITE_CONSTRAINT | (9<<8));
pub const SQLITE_CONSTRAINT_ROWID : c_int = (SQLITE_CONSTRAINT |(10<<8));
pub const SQLITE_NOTICE_RECOVER_WAL : c_int = (SQLITE_NOTICE | (1<<8));
pub const SQLITE_NOTICE_RECOVER_ROLLBACK : c_int = (SQLITE_NOTICE | (2<<8));
pub const SQLITE_WARNING_AUTOINDEX : c_int = (SQLITE_WARNING | (1<<8));
pub const SQLITE_AUTH_USER : c_int = (SQLITE_AUTH | (1<<8));
const SQLITE_IOERR_READ : c_int = (SQLITE_IOERR | (1<<8));
const SQLITE_IOERR_SHORT_READ : c_int = (SQLITE_IOERR | (2<<8));
const SQLITE_IOERR_WRITE : c_int = (SQLITE_IOERR | (3<<8));
const SQLITE_IOERR_FSYNC : c_int = (SQLITE_IOERR | (4<<8));
const SQLITE_IOERR_DIR_FSYNC : c_int = (SQLITE_IOERR | (5<<8));
const SQLITE_IOERR_TRUNCATE : c_int = (SQLITE_IOERR | (6<<8));
const SQLITE_IOERR_FSTAT : c_int = (SQLITE_IOERR | (7<<8));
const SQLITE_IOERR_UNLOCK : c_int = (SQLITE_IOERR | (8<<8));
const SQLITE_IOERR_RDLOCK : c_int = (SQLITE_IOERR | (9<<8));
const SQLITE_IOERR_DELETE : c_int = (SQLITE_IOERR | (10<<8));
const SQLITE_IOERR_BLOCKED : c_int = (SQLITE_IOERR | (11<<8));
const SQLITE_IOERR_NOMEM : c_int = (SQLITE_IOERR | (12<<8));
const SQLITE_IOERR_ACCESS : c_int = (SQLITE_IOERR | (13<<8));
const SQLITE_IOERR_CHECKRESERVEDLOCK : c_int = (SQLITE_IOERR | (14<<8));
const SQLITE_IOERR_LOCK : c_int = (SQLITE_IOERR | (15<<8));
const SQLITE_IOERR_CLOSE : c_int = (SQLITE_IOERR | (16<<8));
const SQLITE_IOERR_DIR_CLOSE : c_int = (SQLITE_IOERR | (17<<8));
const SQLITE_IOERR_SHMOPEN : c_int = (SQLITE_IOERR | (18<<8));
const SQLITE_IOERR_SHMSIZE : c_int = (SQLITE_IOERR | (19<<8));
const SQLITE_IOERR_SHMLOCK : c_int = (SQLITE_IOERR | (20<<8));
const SQLITE_IOERR_SHMMAP : c_int = (SQLITE_IOERR | (21<<8));
const SQLITE_IOERR_SEEK : c_int = (SQLITE_IOERR | (22<<8));
const SQLITE_IOERR_DELETE_NOENT : c_int = (SQLITE_IOERR | (23<<8));
const SQLITE_IOERR_MMAP : c_int = (SQLITE_IOERR | (24<<8));
const SQLITE_IOERR_GETTEMPPATH : c_int = (SQLITE_IOERR | (25<<8));
const SQLITE_IOERR_CONVPATH : c_int = (SQLITE_IOERR | (26<<8));
const SQLITE_IOERR_VNODE : c_int = (SQLITE_IOERR | (27<<8));
const SQLITE_LOCKED_SHAREDCACHE : c_int = (SQLITE_LOCKED | (1<<8));
const SQLITE_BUSY_RECOVERY : c_int = (SQLITE_BUSY | (1<<8));
const SQLITE_BUSY_SNAPSHOT : c_int = (SQLITE_BUSY | (2<<8));
const SQLITE_CANTOPEN_NOTEMPDIR : c_int = (SQLITE_CANTOPEN | (1<<8));
const SQLITE_CANTOPEN_ISDIR : c_int = (SQLITE_CANTOPEN | (2<<8));
const SQLITE_CANTOPEN_FULLPATH : c_int = (SQLITE_CANTOPEN | (3<<8));
const SQLITE_CANTOPEN_CONVPATH : c_int = (SQLITE_CANTOPEN | (4<<8));
const SQLITE_CORRUPT_VTAB : c_int = (SQLITE_CORRUPT | (1<<8));
const SQLITE_READONLY_RECOVERY : c_int = (SQLITE_READONLY | (1<<8));
const SQLITE_READONLY_CANTLOCK : c_int = (SQLITE_READONLY | (2<<8));
const SQLITE_READONLY_ROLLBACK : c_int = (SQLITE_READONLY | (3<<8));
const SQLITE_READONLY_DBMOVED : c_int = (SQLITE_READONLY | (4<<8));
const SQLITE_ABORT_ROLLBACK : c_int = (SQLITE_ABORT | (2<<8));
const SQLITE_CONSTRAINT_CHECK : c_int = (SQLITE_CONSTRAINT | (1<<8));
const SQLITE_CONSTRAINT_COMMITHOOK : c_int = (SQLITE_CONSTRAINT | (2<<8));
const SQLITE_CONSTRAINT_FOREIGNKEY : c_int = (SQLITE_CONSTRAINT | (3<<8));
const SQLITE_CONSTRAINT_FUNCTION : c_int = (SQLITE_CONSTRAINT | (4<<8));
const SQLITE_CONSTRAINT_NOTNULL : c_int = (SQLITE_CONSTRAINT | (5<<8));
const SQLITE_CONSTRAINT_PRIMARYKEY : c_int = (SQLITE_CONSTRAINT | (6<<8));
const SQLITE_CONSTRAINT_TRIGGER : c_int = (SQLITE_CONSTRAINT | (7<<8));
const SQLITE_CONSTRAINT_UNIQUE : c_int = (SQLITE_CONSTRAINT | (8<<8));
const SQLITE_CONSTRAINT_VTAB : c_int = (SQLITE_CONSTRAINT | (9<<8));
const SQLITE_CONSTRAINT_ROWID : c_int = (SQLITE_CONSTRAINT |(10<<8));
const SQLITE_NOTICE_RECOVER_WAL : c_int = (SQLITE_NOTICE | (1<<8));
const SQLITE_NOTICE_RECOVER_ROLLBACK : c_int = (SQLITE_NOTICE | (2<<8));
const SQLITE_WARNING_AUTOINDEX : c_int = (SQLITE_WARNING | (1<<8));
const SQLITE_AUTH_USER : c_int = (SQLITE_AUTH | (1<<8));
pub fn code_to_str(code: c_int) -> &'static str {
match code {

View File

@ -114,6 +114,15 @@ fn set_result<'a>(ctx: *mut sqlite3_context, result: &ToSqlOutput<'a>) {
}
unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) {
// Extended constraint error codes were added in SQLite 3.7.16. We don't have an explicit
// feature check for that, and this doesn't really warrant one. We'll use the extended code
// if we're on the bundled version (since it's at least 3.17.0) and the normal constraint
// error code if not.
#[cfg(feature = "bundled")]
fn constraint_error_code() -> i32 { ffi::SQLITE_CONSTRAINT_FUNCTION }
#[cfg(not(feature = "bundled"))]
fn constraint_error_code() -> i32 { ffi::SQLITE_CONSTRAINT }
match *err {
Error::SqliteFailure(ref err, ref s) => {
ffi::sqlite3_result_error_code(ctx, err.extended_code);
@ -122,7 +131,7 @@ unsafe fn report_error(ctx: *mut sqlite3_context, err: &Error) {
}
}
_ => {
ffi::sqlite3_result_error_code(ctx, ffi::SQLITE_CONSTRAINT_FUNCTION);
ffi::sqlite3_result_error_code(ctx, constraint_error_code());
if let Ok(cstr) = str_to_cstring(err.description()) {
ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1);
}

View File

@ -1169,6 +1169,15 @@ mod test {
#[test]
fn test_notnull_constraint_error() {
// extended error codes for constraints were added in SQLite 3.7.16; if we're
// running on our bundled version, we know the extended error code exists.
#[cfg(feature = "bundled")]
fn check_extended_code(extended_code: c_int) {
assert_eq!(extended_code, ffi::SQLITE_CONSTRAINT_NOTNULL);
}
#[cfg(not(feature = "bundled"))]
fn check_extended_code(_extended_code: c_int) {}
let db = checked_memory_handle();
db.execute_batch("CREATE TABLE foo(x NOT NULL)").unwrap();
@ -1178,12 +1187,7 @@ mod test {
match result.unwrap_err() {
Error::SqliteFailure(err, _) => {
assert_eq!(err.code, ErrorCode::ConstraintViolation);
// extended error codes for constraints were added in SQLite 3.7.16; if we're
// running on a version at least that new, check for the extended code
if version_number() >= 3007016 {
assert_eq!(err.extended_code, ffi::SQLITE_CONSTRAINT_NOTNULL)
}
check_extended_code(err.extended_code);
}
err => panic!("Unexpected error {}", err),
}