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:
gwenn
2018-06-10 12:16:54 +02:00
parent b89b574f81
commit fa64a4d0bf
10 changed files with 290 additions and 60 deletions

View File

@@ -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);
}