mirror of
https://github.com/isar/rusqlite.git
synced 2025-10-21 15:58:54 +08:00
Draft for carray module in Rust
Incomplete support for sqlite3_bind_pointer. Make Context::set_result return a Result. Add Values::get_array.
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
//! assert!(is_match);
|
||||
//! }
|
||||
//! ```
|
||||
use std::error::Error as StdError;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::os::raw::{c_int, c_void};
|
||||
@@ -57,11 +58,41 @@ use ffi;
|
||||
use ffi::sqlite3_context;
|
||||
use ffi::sqlite3_value;
|
||||
|
||||
use context::{report_error, set_result};
|
||||
use context::{set_result};
|
||||
use types::{ToSql, FromSql, FromSqlError, ValueRef};
|
||||
|
||||
use {Result, Error, Connection, str_to_cstring, InnerConnection};
|
||||
|
||||
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);
|
||||
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_code(ctx, constraint_error_code());
|
||||
if let Ok(cstr) = str_to_cstring(err.description()) {
|
||||
ffi::sqlite3_result_error(ctx, cstr.as_ptr(), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn free_boxed_value<T>(p: *mut c_void) {
|
||||
let _: Box<T> = Box::from_raw(p as *mut T);
|
||||
}
|
||||
|
Reference in New Issue
Block a user