From 394327642e7557b430ce698a812ed9fc274b47b2 Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 17 Sep 2020 21:19:03 +0300 Subject: [PATCH] make compatible with FCE --- Cargo.toml | 21 +- sqlite3.wit | 464 ++++++++++++++++++++++ src/connection.rs | 146 ++----- src/cursor.rs | 14 +- src/lib.rs | 76 ++-- src/sqlite3_connector/consts.rs | 380 ++++++++++++++++++ src/sqlite3_connector/import_functions.rs | 138 +++++++ src/sqlite3_connector/mod.rs | 5 + src/statement.rs | 119 ++---- src/test.rs | 86 ++++ src/wit_generator.rs | 211 ++++++++++ 11 files changed, 1407 insertions(+), 253 deletions(-) create mode 100644 sqlite3.wit create mode 100644 src/sqlite3_connector/consts.rs create mode 100644 src/sqlite3_connector/import_functions.rs create mode 100644 src/sqlite3_connector/mod.rs create mode 100644 src/test.rs create mode 100644 src/wit_generator.rs diff --git a/Cargo.toml b/Cargo.toml index 8749486..ff3f55e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,16 +22,21 @@ readme = "README.md" categories = ["api-bindings", "database"] keywords = ["database"] -[features] -default = ["linkage"] -linkage = ["sqlite3-sys/linkage"] +[lib] +name = "sqlite" +path = "src/lib.rs" + +[[bin]] +name = "wit_generator" +path = "src/wit_generator.rs" + +[[bin]] +name = "test" +path = "src/test.rs" [dependencies] -libc = "0.2" - -[dependencies.sqlite3-sys] -version = "0.12" -default-features = false +fluence = "0.2.3" [dev-dependencies] temporary = "0.6" +fluence = "0.2.3" diff --git a/sqlite3.wit b/sqlite3.wit new file mode 100644 index 0000000..3642b44 --- /dev/null +++ b/sqlite3.wit @@ -0,0 +1,464 @@ +;; Types +(@interface type (func + (param $size: i32) + (result i32))) ;; 0 +(@interface type (func + (param $pointer: i32 $size: i32) )) ;; 1 +(@interface type (func + (result i32))) ;; 2 +(@interface type (func + (result i32))) ;; 3 +(@interface type (func + (param $result_size: i32) )) ;; 4 +(@interface type (func + (param $result_ptr: i32) )) ;; 5 +(@interface type (record DBExecDescriptor { + ret_code: s32 + err_msg: string +})) ;; 6 +(@interface type (record DBPrepareDescriptor { + ret_code: s32 + stmt_handle: u32 + tail: u32 +})) ;; 7 +(@interface type (record DBOpenDescriptor { + ret_code: s32 + db_handle: u32 +})) ;; 8 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result string))) ;; 9 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result string))) ;; 10 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s32))) ;; 11 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s32))) ;; 12 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 13 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 14 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $value: f64) + (result s32))) ;; 15 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $value: f64) + (result s32))) ;; 16 +(@interface type (func + (param $filename: string $flags: s32 $vfs: string) + (result 8))) ;; 17 +(@interface type (func + (param $filename: string $flags: s32 $vfs: string) + (result 8))) ;; 18 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 19 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 20 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 21 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 22 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s64))) ;; 23 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s64))) ;; 24 +(@interface type (func + (param $db: u32) + (result s32))) ;; 25 +(@interface type (func + (param $db: u32) + (result s32))) ;; 26 +(@interface type (func + (param $stmt_handle: u32 $icol: s32) + (result f64))) ;; 27 +(@interface type (func + (param $stmt_handle: u32 $icol: s32) + (result f64))) ;; 28 +(@interface type (func + (param $db_handle: u32 $ms: u32) + (result s32))) ;; 29 +(@interface type (func + (param $db_handle: u32 $ms: u32) + (result s32))) ;; 30 +(@interface type (func + (param $db_handle: u32) + (result string))) ;; 31 +(@interface type (func + (param $db_handle: u32) + (result string))) ;; 32 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $value: s64) + (result s32))) ;; 33 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $value: s64) + (result s32))) ;; 34 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 35 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 36 +(@interface type (func + (param $db_handle: u32 $sql: string) + (result 7))) ;; 37 +(@interface type (func + (param $db_handle: u32 $sql: string) + (result 7))) ;; 38 +(@interface type (func + (param $stmt_handle: u32 $pos: s32) + (result s32))) ;; 39 +(@interface type (func + (param $stmt_handle: u32 $pos: s32) + (result s32))) ;; 40 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 41 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 42 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $blob: byte_array $xDel: s32) + (result s32))) ;; 43 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $blob: byte_array $xDel: s32) + (result s32))) ;; 44 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 45 +(@interface type (func + (param $db_handle: u32) + (result s32))) ;; 46 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32) + (result s32))) ;; 47 +(@interface type (func + (param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32) + (result s32))) ;; 48 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 49 +(@interface type (func + (param $stmt_handle: u32) + (result s32))) ;; 50 +(@interface type (func + (param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32) + (result 6))) ;; 51 +(@interface type (func + (param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32) + (result 6))) ;; 52 +(@interface type (func + (result s32))) ;; 53 +(@interface type (func + (result s32))) ;; 54 +(@interface type (func + (param $stmt_handle: u32 $icol: s32) + (result byte_array))) ;; 55 +(@interface type (func + (param $stmt_handle: u32 $icol: s32) + (result byte_array))) ;; 56 +(@interface type (func + (param $stmt_handle: u32 $N: u32) + (result string))) ;; 57 +(@interface type (func + (param $stmt_handle: u32 $N: u32) + (result string))) ;; 58 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s32))) ;; 59 +(@interface type (func + (param $stmt_handle: u32 $icol: u32) + (result s32))) ;; 60 + + + +;; Adapters +(@interface func (type 9) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 6 + call-core 3 + call-core 2 + string.lift_memory + call-core 3 + call-core 2 + call-core 1) +(@interface func (type 11) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 7 + s32.from_i32) +(@interface func (type 13) + arg.get 0 + i32.from_u32 + call-core 8 + s32.from_i32) +(@interface func (type 15) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + arg.get 2 + call-core 9 + s32.from_i32) +(@interface func (type 17) + arg.get 0 + string.size + call-core 0 + arg.get 0 + string.lower_memory + arg.get 1 + i32.from_s32 + arg.get 2 + string.size + call-core 0 + arg.get 2 + string.lower_memory + call-core 10 + call-core 3 + record.lift_memory 8) +(@interface func (type 19) + arg.get 0 + i32.from_u32 + call-core 11 + s32.from_i32) +(@interface func (type 21) + arg.get 0 + i32.from_u32 + call-core 12 + s32.from_i32) +(@interface func (type 23) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 13 + s64.from_i64) +(@interface func (type 25) + arg.get 0 + i32.from_u32 + call-core 14 + s32.from_i32) +(@interface func (type 27) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + call-core 15) +(@interface func (type 29) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 16 + s32.from_i32) +(@interface func (type 31) + arg.get 0 + i32.from_u32 + call-core 17 + call-core 3 + call-core 2 + string.lift_memory + call-core 3 + call-core 2 + call-core 1) +(@interface func (type 33) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + arg.get 2 + i64.from_s64 + call-core 18 + s32.from_i32) +(@interface func (type 35) + arg.get 0 + i32.from_u32 + call-core 19 + s32.from_i32) +(@interface func (type 37) + arg.get 0 + i32.from_u32 + arg.get 1 + string.size + call-core 0 + arg.get 1 + string.lower_memory + call-core 20 + call-core 3 + record.lift_memory 7) +(@interface func (type 39) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + call-core 21 + s32.from_i32) +(@interface func (type 41) + arg.get 0 + i32.from_u32 + call-core 22 + s32.from_i32) +(@interface func (type 43) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + arg.get 2 + byte_array.size + call-core 0 + arg.get 2 + byte_array.lower_memory + arg.get 3 + i32.from_s32 + call-core 23 + s32.from_i32) +(@interface func (type 45) + arg.get 0 + i32.from_u32 + call-core 24 + s32.from_i32) +(@interface func (type 47) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + arg.get 2 + string.size + call-core 0 + arg.get 2 + string.lower_memory + arg.get 3 + i32.from_s32 + call-core 25 + s32.from_i32) +(@interface func (type 49) + arg.get 0 + i32.from_u32 + call-core 26 + s32.from_i32) +(@interface func (type 51) + arg.get 0 + i32.from_u32 + arg.get 1 + string.size + call-core 0 + arg.get 1 + string.lower_memory + arg.get 2 + i32.from_s32 + arg.get 3 + i32.from_s32 + call-core 27 + call-core 3 + record.lift_memory 6) +(@interface func (type 53) + call-core 28 + s32.from_i32) +(@interface func (type 55) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_s32 + call-core 29 + call-core 3 + call-core 2 + byte_array.lift_memory + call-core 3 + call-core 2 + call-core 1) +(@interface func (type 57) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 30 + call-core 3 + call-core 2 + string.lift_memory + call-core 3 + call-core 2 + call-core 1) +(@interface func (type 59) + arg.get 0 + i32.from_u32 + arg.get 1 + i32.from_u32 + call-core 31 + s32.from_i32) + +;; Exports +(@interface export "allocate" (func 0)) +(@interface export "deallocate" (func 1)) +(@interface export "get_result_size" (func 2)) +(@interface export "get_result_ptr" (func 3)) +(@interface export "set_result_size" (func 4)) +(@interface export "set_result_ptr" (func 5)) +(@interface export "sqlite3_column_text" (func 10)) +(@interface export "sqlite3_column_bytes" (func 12)) +(@interface export "sqlite3_close" (func 14)) +(@interface export "sqlite3_bind_double" (func 16)) +(@interface export "sqlite3_open_v2" (func 18)) +(@interface export "sqlite3_changes" (func 20)) +(@interface export "sqlite3_step" (func 22)) +(@interface export "sqlite3_column_int64" (func 24)) +(@interface export "sqlite3_errcode" (func 26)) +(@interface export "sqlite3_column_double" (func 28)) +(@interface export "sqlite3_busy_timeout" (func 30)) +(@interface export "sqlite3_errmsg" (func 32)) +(@interface export "sqlite3_bind_int64" (func 34)) +(@interface export "sqlite3_finalize" (func 36)) +(@interface export "sqlite3_prepare_v2" (func 38)) +(@interface export "sqlite3_bind_null" (func 40)) +(@interface export "sqlite3_column_count" (func 42)) +(@interface export "sqlite3_bind_blob" (func 44)) +(@interface export "sqlite3_total_changes" (func 46)) +(@interface export "sqlite3_bind_text" (func 48)) +(@interface export "sqlite3_reset" (func 50)) +(@interface export "sqlite3_exec" (func 52)) +(@interface export "sqlite3_libversion_number" (func 54)) +(@interface export "sqlite3_column_blob" (func 56)) +(@interface export "sqlite3_column_name" (func 58)) +(@interface export "sqlite3_column_type" (func 60)) + +;; Implementations +(@interface implement (func 10) (func 9)) +(@interface implement (func 12) (func 11)) +(@interface implement (func 14) (func 13)) +(@interface implement (func 16) (func 15)) +(@interface implement (func 18) (func 17)) +(@interface implement (func 20) (func 19)) +(@interface implement (func 22) (func 21)) +(@interface implement (func 24) (func 23)) +(@interface implement (func 26) (func 25)) +(@interface implement (func 28) (func 27)) +(@interface implement (func 30) (func 29)) +(@interface implement (func 32) (func 31)) +(@interface implement (func 34) (func 33)) +(@interface implement (func 36) (func 35)) +(@interface implement (func 38) (func 37)) +(@interface implement (func 40) (func 39)) +(@interface implement (func 42) (func 41)) +(@interface implement (func 44) (func 43)) +(@interface implement (func 46) (func 45)) +(@interface implement (func 48) (func 47)) +(@interface implement (func 50) (func 49)) +(@interface implement (func 52) (func 51)) +(@interface implement (func 54) (func 53)) +(@interface implement (func 56) (func 55)) +(@interface implement (func 58) (func 57)) +(@interface implement (func 60) (func 59)) diff --git a/src/connection.rs b/src/connection.rs index e8cae26..8f7c30c 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -1,5 +1,5 @@ -use ffi; -use libc::{c_char, c_int, c_void}; +use sqlite3_connector as ffi; + use std::marker::PhantomData; use std::path::Path; @@ -7,14 +7,13 @@ use {Result, Statement}; /// A database connection. pub struct Connection { - raw: *mut ffi::sqlite3, - busy_callback: Option bool>>, - phantom: PhantomData, + raw: ffi::Sqlite3DbHandle, + phantom: PhantomData, } /// Flags for opening a database connection. #[derive(Clone, Copy, Debug)] -pub struct OpenFlags(c_int); +pub struct OpenFlags(i32); unsafe impl Send for Connection {} @@ -26,51 +25,44 @@ impl Connection { /// Open a database connection with specific flags. pub fn open_with_flags>(path: T, flags: OpenFlags) -> Result { - let mut raw = 0 as *mut _; unsafe { - let code = ffi::sqlite3_open_v2( - path_to_cstr!(path.as_ref()).as_ptr(), - &mut raw, - flags.0, - 0 as *const _, - ); - match code { + let path = path.as_ref(); + let path = path.to_string_lossy().into_owned(); + let result = ffi::sqlite3_open_v2(path, flags.0, String::new()); + + match result.ret_code { ffi::SQLITE_OK => {} - code => match ::last_error(raw) { - Some(error) => { - ffi::sqlite3_close(raw); - return Err(error); + code => { + return match ::last_error(result.db_handle) { + Some(error) => { + ffi::sqlite3_close(result.db_handle); + Err(error) + } + _ => { + ffi::sqlite3_close(result.db_handle); + Err(::Error { + code: Some(code as isize), + message: None, + }) + } } - _ => { - ffi::sqlite3_close(raw); - return Err(::Error { - code: Some(code as isize), - message: None, - }); - } - }, + } } + + Ok(Connection { + raw: result.db_handle, + phantom: PhantomData, + }) } - Ok(Connection { - raw: raw, - busy_callback: None, - phantom: PhantomData, - }) } /// Execute a statement without processing the resulting rows if any. #[inline] pub fn execute>(&self, statement: T) -> Result<()> { unsafe { - ok!( + ok_descr!( self.raw, - ffi::sqlite3_exec( - self.raw, - str_to_cstr!(statement.as_ref()).as_ptr(), - None, - 0 as *mut _, - 0 as *mut _, - ) + ffi::sqlite3_exec(self.raw, statement.as_ref().into(), 0, 0,) ); } Ok(()) @@ -87,16 +79,10 @@ impl Connection { F: FnMut(&[(&str, Option<&str>)]) -> bool, { unsafe { - let callback = Box::new(callback); - ok!( + let _callback = Box::new(callback); + ok_descr!( self.raw, - ffi::sqlite3_exec( - self.raw, - str_to_cstr!(statement.as_ref()).as_ptr(), - Some(process_callback::), - &*callback as *const F as *mut F as *mut _, - 0 as *mut _, - ) + ffi::sqlite3_exec(self.raw, statement.as_ref().into(), 0, 0,) ); } Ok(()) @@ -104,7 +90,7 @@ impl Connection { /// Create a prepared statement. #[inline] - pub fn prepare<'l, T: AsRef>(&'l self, statement: T) -> Result> { + pub fn prepare>(&self, statement: T) -> Result { ::statement::new(self.raw, statement) } @@ -122,50 +108,14 @@ impl Connection { unsafe { ffi::sqlite3_total_changes(self.raw) as usize } } - /// Set a callback for handling busy events. - /// - /// The callback is triggered when the database cannot perform an operation - /// due to processing of some other request. If the callback returns `true`, - /// the operation will be repeated. - pub fn set_busy_handler(&mut self, callback: F) -> Result<()> - where - F: FnMut(usize) -> bool + Send + 'static, - { - self.remove_busy_handler()?; - unsafe { - let callback = Box::new(callback); - let result = ffi::sqlite3_busy_handler( - self.raw, - Some(busy_callback::), - &*callback as *const F as *mut F as *mut _, - ); - self.busy_callback = Some(callback); - ok!(self.raw, result); - } - Ok(()) - } - /// Set an implicit callback for handling busy events that tries to repeat /// rejected operations until a timeout expires. #[inline] pub fn set_busy_timeout(&mut self, milliseconds: usize) -> Result<()> { unsafe { - ok!( + ok_raw!( self.raw, - ffi::sqlite3_busy_timeout(self.raw, milliseconds as c_int) - ); - } - Ok(()) - } - - /// Remove the callback handling busy events. - #[inline] - pub fn remove_busy_handler(&mut self) -> Result<()> { - self.busy_callback = None; - unsafe { - ok!( - self.raw, - ffi::sqlite3_busy_handler(self.raw, None, 0 as *mut _) + ffi::sqlite3_busy_timeout(self.raw, milliseconds as _) ); } Ok(()) @@ -173,7 +123,7 @@ impl Connection { /// Return the raw pointer. #[inline] - pub fn as_raw(&self) -> *mut ffi::sqlite3 { + pub fn as_raw(&self) -> ffi::Sqlite3DbHandle { self.raw } } @@ -182,7 +132,6 @@ impl Drop for Connection { #[inline] #[allow(unused_must_use)] fn drop(&mut self) { - self.remove_busy_handler(); unsafe { ffi::sqlite3_close(self.raw) }; } } @@ -229,25 +178,13 @@ impl OpenFlags { } } -extern "C" fn busy_callback(callback: *mut c_void, attempts: c_int) -> c_int -where - F: FnMut(usize) -> bool, -{ - unsafe { - if (*(callback as *mut F))(attempts as usize) { - 1 - } else { - 0 - } - } -} - +/* extern "C" fn process_callback( callback: *mut c_void, - count: c_int, + count: i32, values: *mut *mut c_char, columns: *mut *mut c_char, -) -> c_int +) -> i32 where F: FnMut(&[(&str, Option<&str>)]) -> bool, { @@ -276,3 +213,4 @@ where } } } +*/ diff --git a/src/cursor.rs b/src/cursor.rs index b417bd5..2a749d4 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -1,15 +1,15 @@ -use ffi; +use sqlite3_connector as ffi; use statement::{State, Statement}; use {Result, Value}; /// An iterator over rows. -pub struct Cursor<'l> { +pub struct Cursor { state: Option, values: Option>, - statement: Statement<'l>, + statement: Statement, } -impl<'l> Cursor<'l> { +impl Cursor { /// Bind values to all parameters. pub fn bind(&mut self, values: &[Value]) -> Result<()> { self.state = None; @@ -58,16 +58,16 @@ impl<'l> Cursor<'l> { /// Return the raw pointer. #[inline] - pub fn as_raw(&self) -> *mut ffi::sqlite3_stmt { + pub fn as_raw(&self) -> ffi::Sqlite3StmtHandle { self.statement.as_raw() } } #[inline] -pub fn new<'l>(statement: Statement<'l>) -> Cursor<'l> { +pub fn new(statement: Statement) -> Cursor { Cursor { state: None, values: None, - statement: statement, + statement, } } diff --git a/src/lib.rs b/src/lib.rs index 662cc08..ac716ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,20 +100,12 @@ //! //! [1]: https://www.sqlite.org -extern crate libc; -extern crate sqlite3_sys as ffi; +#![allow(dead_code)] + +use sqlite3_connector as ffi; use std::{error, fmt}; -macro_rules! raise( - ($message:expr) => ( - return Err(::Error { - code: None, - message: Some($message.to_string()), - }) - ); -); - macro_rules! error( ($connection:expr, $code:expr) => ( match ::last_error($connection) { @@ -126,7 +118,25 @@ macro_rules! error( ); ); -macro_rules! ok( +macro_rules! ok_descr( + ($connection:expr, $result:expr) => ( + match $result.ret_code { + ::ffi::SQLITE_OK => {} + code => error!($connection, code), + } + ); + ($result:expr) => ( + match $result.ret_code { + ::ffi::SQLITE_OK => {} + code => return Err(::Error { + code: Some(code as isize), + message: None, + }), + } + ); +); + +macro_rules! ok_raw( ($connection:expr, $result:expr) => ( match $result { ::ffi::SQLITE_OK => {} @@ -144,40 +154,6 @@ macro_rules! ok( ); ); -macro_rules! c_str_to_str( - ($string:expr) => (::std::str::from_utf8(::std::ffi::CStr::from_ptr($string).to_bytes())); -); - -macro_rules! c_str_to_string( - ($string:expr) => ( - String::from_utf8_lossy(::std::ffi::CStr::from_ptr($string as *const _).to_bytes()) - .into_owned() - ); -); - -macro_rules! path_to_cstr( - ($path:expr) => ( - match $path.to_str() { - Some(path) => { - match ::std::ffi::CString::new(path) { - Ok(string) => string, - _ => raise!("failed to process a path"), - } - } - _ => raise!("failed to process a path"), - } - ); -); - -macro_rules! str_to_cstr( - ($string:expr) => ( - match ::std::ffi::CString::new($string) { - Ok(string) => string, - _ => raise!("failed to process a string"), - } - ); -); - /// An error. #[derive(Debug)] pub struct Error { @@ -291,6 +267,7 @@ impl Value { mod connection; mod cursor; +mod sqlite3_connector; mod statement; pub use connection::Connection; @@ -312,19 +289,16 @@ pub fn version() -> usize { unsafe { ffi::sqlite3_libversion_number() as usize } } -fn last_error(raw: *mut ffi::sqlite3) -> Option { +fn last_error(raw: ffi::Sqlite3DbHandle) -> Option { unsafe { let code = ffi::sqlite3_errcode(raw); if code == ffi::SQLITE_OK { return None; } let message = ffi::sqlite3_errmsg(raw); - if message.is_null() { - return None; - } Some(Error { code: Some(code as isize), - message: Some(c_str_to_string!(message)), + message: Some(message), }) } } diff --git a/src/sqlite3_connector/consts.rs b/src/sqlite3_connector/consts.rs new file mode 100644 index 0000000..5edc5af --- /dev/null +++ b/src/sqlite3_connector/consts.rs @@ -0,0 +1,380 @@ +pub const SQLITE_OK: i32 = 0; +pub const SQLITE_ERROR: i32 = 1; +pub const SQLITE_INTERNAL: i32 = 2; +pub const SQLITE_PERM: i32 = 3; +pub const SQLITE_ABORT: i32 = 4; +pub const SQLITE_BUSY: i32 = 5; +pub const SQLITE_LOCKED: i32 = 6; +pub const SQLITE_NOMEM: i32 = 7; +pub const SQLITE_READONLY: i32 = 8; +pub const SQLITE_INTERRUPT: i32 = 9; +pub const SQLITE_IOERR: i32 = 10; +pub const SQLITE_CORRUPT: i32 = 11; +pub const SQLITE_NOTFOUND: i32 = 12; +pub const SQLITE_FULL: i32 = 13; +pub const SQLITE_CANTOPEN: i32 = 14; +pub const SQLITE_PROTOCOL: i32 = 15; +pub const SQLITE_EMPTY: i32 = 16; +pub const SQLITE_SCHEMA: i32 = 17; +pub const SQLITE_TOOBIG: i32 = 18; +pub const SQLITE_CONSTRAINT: i32 = 19; +pub const SQLITE_MISMATCH: i32 = 20; +pub const SQLITE_MISUSE: i32 = 21; +pub const SQLITE_NOLFS: i32 = 22; +pub const SQLITE_AUTH: i32 = 23; +pub const SQLITE_FORMAT: i32 = 24; +pub const SQLITE_RANGE: i32 = 25; +pub const SQLITE_NOTADB: i32 = 26; +pub const SQLITE_NOTICE: i32 = 27; +pub const SQLITE_WARNING: i32 = 28; +pub const SQLITE_ROW: i32 = 100; +pub const SQLITE_DONE: i32 = 101; + +pub const SQLITE_IOERR_READ: i32 = SQLITE_IOERR | (1 << 8); +pub const SQLITE_IOERR_SHORT_READ: i32 = SQLITE_IOERR | (2 << 8); +pub const SQLITE_IOERR_WRITE: i32 = SQLITE_IOERR | (3 << 8); +pub const SQLITE_IOERR_FSYNC: i32 = SQLITE_IOERR | (4 << 8); +pub const SQLITE_IOERR_DIR_FSYNC: i32 = SQLITE_IOERR | (5 << 8); +pub const SQLITE_IOERR_TRUNCATE: i32 = SQLITE_IOERR | (6 << 8); +pub const SQLITE_IOERR_FSTAT: i32 = SQLITE_IOERR | (7 << 8); +pub const SQLITE_IOERR_UNLOCK: i32 = SQLITE_IOERR | (8 << 8); +pub const SQLITE_IOERR_RDLOCK: i32 = SQLITE_IOERR | (9 << 8); +pub const SQLITE_IOERR_DELETE: i32 = SQLITE_IOERR | (10 << 8); +pub const SQLITE_IOERR_BLOCKED: i32 = SQLITE_IOERR | (11 << 8); +pub const SQLITE_IOERR_NOMEM: i32 = SQLITE_IOERR | (12 << 8); +pub const SQLITE_IOERR_ACCESS: i32 = SQLITE_IOERR | (13 << 8); +pub const SQLITE_IOERR_CHECKRESERVEDLOCK: i32 = SQLITE_IOERR | (14 << 8); +pub const SQLITE_IOERR_LOCK: i32 = SQLITE_IOERR | (15 << 8); +pub const SQLITE_IOERR_CLOSE: i32 = SQLITE_IOERR | (16 << 8); +pub const SQLITE_IOERR_DIR_CLOSE: i32 = SQLITE_IOERR | (17 << 8); +pub const SQLITE_IOERR_SHMOPEN: i32 = SQLITE_IOERR | (18 << 8); +pub const SQLITE_IOERR_SHMSIZE: i32 = SQLITE_IOERR | (19 << 8); +pub const SQLITE_IOERR_SHMLOCK: i32 = SQLITE_IOERR | (20 << 8); +pub const SQLITE_IOERR_SHMMAP: i32 = SQLITE_IOERR | (21 << 8); +pub const SQLITE_IOERR_SEEK: i32 = SQLITE_IOERR | (22 << 8); +pub const SQLITE_IOERR_DELETE_NOENT: i32 = SQLITE_IOERR | (23 << 8); +pub const SQLITE_IOERR_MMAP: i32 = SQLITE_IOERR | (24 << 8); +pub const SQLITE_IOERR_GETTEMPPATH: i32 = SQLITE_IOERR | (25 << 8); +pub const SQLITE_IOERR_CONVPATH: i32 = SQLITE_IOERR | (26 << 8); +pub const SQLITE_LOCKED_SHAREDCACHE: i32 = SQLITE_LOCKED | (1 << 8); +pub const SQLITE_BUSY_RECOVERY: i32 = SQLITE_BUSY | (1 << 8); +pub const SQLITE_BUSY_SNAPSHOT: i32 = SQLITE_BUSY | (2 << 8); +pub const SQLITE_CANTOPEN_NOTEMPDIR: i32 = SQLITE_CANTOPEN | (1 << 8); +pub const SQLITE_CANTOPEN_ISDIR: i32 = SQLITE_CANTOPEN | (2 << 8); +pub const SQLITE_CANTOPEN_FULLPATH: i32 = SQLITE_CANTOPEN | (3 << 8); +pub const SQLITE_CANTOPEN_CONVPATH: i32 = SQLITE_CANTOPEN | (4 << 8); +pub const SQLITE_CORRUPT_VTAB: i32 = SQLITE_CORRUPT | (1 << 8); +pub const SQLITE_READONLY_RECOVERY: i32 = SQLITE_READONLY | (1 << 8); +pub const SQLITE_READONLY_CANTLOCK: i32 = SQLITE_READONLY | (2 << 8); +pub const SQLITE_READONLY_ROLLBACK: i32 = SQLITE_READONLY | (3 << 8); +pub const SQLITE_READONLY_DBMOVED: i32 = SQLITE_READONLY | (4 << 8); +pub const SQLITE_ABORT_ROLLBACK: i32 = SQLITE_ABORT | (2 << 8); +pub const SQLITE_CONSTRAINT_CHECK: i32 = SQLITE_CONSTRAINT | (1 << 8); +pub const SQLITE_CONSTRAINT_COMMITHOOK: i32 = SQLITE_CONSTRAINT | (2 << 8); +pub const SQLITE_CONSTRAINT_FOREIGNKEY: i32 = SQLITE_CONSTRAINT | (3 << 8); +pub const SQLITE_CONSTRAINT_FUNCTION: i32 = SQLITE_CONSTRAINT | (4 << 8); +pub const SQLITE_CONSTRAINT_NOTNULL: i32 = SQLITE_CONSTRAINT | (5 << 8); +pub const SQLITE_CONSTRAINT_PRIMARYKEY: i32 = SQLITE_CONSTRAINT | (6 << 8); +pub const SQLITE_CONSTRAINT_TRIGGER: i32 = SQLITE_CONSTRAINT | (7 << 8); +pub const SQLITE_CONSTRAINT_UNIQUE: i32 = SQLITE_CONSTRAINT | (8 << 8); +pub const SQLITE_CONSTRAINT_VTAB: i32 = SQLITE_CONSTRAINT | (9 << 8); +pub const SQLITE_CONSTRAINT_ROWID: i32 = SQLITE_CONSTRAINT | (10 << 8); +pub const SQLITE_NOTICE_RECOVER_WAL: i32 = SQLITE_NOTICE | (1 << 8); +pub const SQLITE_NOTICE_RECOVER_ROLLBACK: i32 = SQLITE_NOTICE | (2 << 8); +pub const SQLITE_WARNING_AUTOINDEX: i32 = SQLITE_WARNING | (1 << 8); +pub const SQLITE_AUTH_USER: i32 = SQLITE_AUTH | (1 << 8); +pub const SQLITE_OK_LOAD_PERMANENTLY: i32 = SQLITE_OK | (1 << 8); + +pub const SQLITE_OPEN_READONLY: i32 = 0x00000001; +pub const SQLITE_OPEN_READWRITE: i32 = 0x00000002; +pub const SQLITE_OPEN_CREATE: i32 = 0x00000004; +pub const SQLITE_OPEN_DELETEONCLOSE: i32 = 0x00000008; +pub const SQLITE_OPEN_EXCLUSIVE: i32 = 0x00000010; +pub const SQLITE_OPEN_AUTOPROXY: i32 = 0x00000020; +pub const SQLITE_OPEN_URI: i32 = 0x00000040; +pub const SQLITE_OPEN_MEMORY: i32 = 0x00000080; +pub const SQLITE_OPEN_MAIN_DB: i32 = 0x00000100; +pub const SQLITE_OPEN_TEMP_DB: i32 = 0x00000200; +pub const SQLITE_OPEN_TRANSIENT_DB: i32 = 0x00000400; +pub const SQLITE_OPEN_MAIN_JOURNAL: i32 = 0x00000800; +pub const SQLITE_OPEN_TEMP_JOURNAL: i32 = 0x00001000; +pub const SQLITE_OPEN_SUBJOURNAL: i32 = 0x00002000; +pub const SQLITE_OPEN_MASTER_JOURNAL: i32 = 0x00004000; +pub const SQLITE_OPEN_NOMUTEX: i32 = 0x00008000; +pub const SQLITE_OPEN_FULLMUTEX: i32 = 0x00010000; +pub const SQLITE_OPEN_SHAREDCACHE: i32 = 0x00020000; +pub const SQLITE_OPEN_PRIVATECACHE: i32 = 0x00040000; +pub const SQLITE_OPEN_WAL: i32 = 0x00080000; + +pub const SQLITE_IOCAP_ATOMIC: i32 = 0x00000001; +pub const SQLITE_IOCAP_ATOMIC512: i32 = 0x00000002; +pub const SQLITE_IOCAP_ATOMIC1K: i32 = 0x00000004; +pub const SQLITE_IOCAP_ATOMIC2K: i32 = 0x00000008; +pub const SQLITE_IOCAP_ATOMIC4K: i32 = 0x00000010; +pub const SQLITE_IOCAP_ATOMIC8K: i32 = 0x00000020; +pub const SQLITE_IOCAP_ATOMIC16K: i32 = 0x00000040; +pub const SQLITE_IOCAP_ATOMIC32K: i32 = 0x00000080; +pub const SQLITE_IOCAP_ATOMIC64K: i32 = 0x00000100; +pub const SQLITE_IOCAP_SAFE_APPEND: i32 = 0x00000200; +pub const SQLITE_IOCAP_SEQUENTIAL: i32 = 0x00000400; +pub const SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: i32 = 0x00000800; +pub const SQLITE_IOCAP_POWERSAFE_OVERWRITE: i32 = 0x00001000; +pub const SQLITE_IOCAP_IMMUTABLE: i32 = 0x00002000; + +pub const SQLITE_LOCK_NONE: i32 = 0; +pub const SQLITE_LOCK_SHARED: i32 = 1; +pub const SQLITE_LOCK_RESERVED: i32 = 2; +pub const SQLITE_LOCK_PENDING: i32 = 3; +pub const SQLITE_LOCK_EXCLUSIVE: i32 = 4; + +pub const SQLITE_SYNC_NORMAL: i32 = 0x00002; +pub const SQLITE_SYNC_FULL: i32 = 0x00003; +pub const SQLITE_SYNC_DATAONLY: i32 = 0x00010; + +pub const SQLITE_FCNTL_LOCKSTATE: i32 = 1; +pub const SQLITE_FCNTL_GET_LOCKPROXYFILE: i32 = 2; +pub const SQLITE_FCNTL_SET_LOCKPROXYFILE: i32 = 3; +pub const SQLITE_FCNTL_LAST_ERRNO: i32 = 4; +pub const SQLITE_FCNTL_SIZE_HINT: i32 = 5; +pub const SQLITE_FCNTL_CHUNK_SIZE: i32 = 6; +pub const SQLITE_FCNTL_FILE_POINTER: i32 = 7; +pub const SQLITE_FCNTL_SYNC_OMITTED: i32 = 8; +pub const SQLITE_FCNTL_WIN32_AV_RETRY: i32 = 9; +pub const SQLITE_FCNTL_PERSIST_WAL: i32 = 10; +pub const SQLITE_FCNTL_OVERWRITE: i32 = 11; +pub const SQLITE_FCNTL_VFSNAME: i32 = 12; +pub const SQLITE_FCNTL_POWERSAFE_OVERWRITE: i32 = 13; +pub const SQLITE_FCNTL_PRAGMA: i32 = 14; +pub const SQLITE_FCNTL_BUSYHANDLER: i32 = 15; +pub const SQLITE_FCNTL_TEMPFILENAME: i32 = 16; +pub const SQLITE_FCNTL_MMAP_SIZE: i32 = 18; +pub const SQLITE_FCNTL_TRACE: i32 = 19; +pub const SQLITE_FCNTL_HAS_MOVED: i32 = 20; +pub const SQLITE_FCNTL_SYNC: i32 = 21; +pub const SQLITE_FCNTL_COMMIT_PHASETWO: i32 = 22; +pub const SQLITE_FCNTL_WIN32_SET_HANDLE: i32 = 23; +pub const SQLITE_FCNTL_WAL_BLOCK: i32 = 24; +pub const SQLITE_FCNTL_ZIPVFS: i32 = 25; +pub const SQLITE_FCNTL_RBU: i32 = 26; +pub const SQLITE_FCNTL_VFS_POINTER: i32 = 27; +pub const SQLITE_FCNTL_JOURNAL_POINTER: i32 = 28; +pub const SQLITE_FCNTL_WIN32_GET_HANDLE: i32 = 29; +pub const SQLITE_FCNTL_PDB: i32 = 30; + +pub const SQLITE_ACCESS_EXISTS: i32 = 0; +pub const SQLITE_ACCESS_READWRITE: i32 = 1; +pub const SQLITE_ACCESS_READ: i32 = 2; + +pub const SQLITE_SHM_UNLOCK: i32 = 1; +pub const SQLITE_SHM_LOCK: i32 = 2; +pub const SQLITE_SHM_SHARED: i32 = 4; +pub const SQLITE_SHM_EXCLUSIVE: i32 = 8; +pub const SQLITE_SHM_NLOCK: i32 = 8; + +pub const SQLITE_CONFIG_SINGLETHREAD: i32 = 1; +pub const SQLITE_CONFIG_MULTITHREAD: i32 = 2; +pub const SQLITE_CONFIG_SERIALIZED: i32 = 3; +pub const SQLITE_CONFIG_MALLOC: i32 = 4; +pub const SQLITE_CONFIG_GETMALLOC: i32 = 5; +pub const SQLITE_CONFIG_SCRATCH: i32 = 6; +pub const SQLITE_CONFIG_PAGECACHE: i32 = 7; +pub const SQLITE_CONFIG_HEAP: i32 = 8; +pub const SQLITE_CONFIG_MEMSTATUS: i32 = 9; +pub const SQLITE_CONFIG_MUTEX: i32 = 10; +pub const SQLITE_CONFIG_GETMUTEX: i32 = 11; +pub const SQLITE_CONFIG_LOOKASIDE: i32 = 13; +pub const SQLITE_CONFIG_PCACHE: i32 = 14; +pub const SQLITE_CONFIG_GETPCACHE: i32 = 15; +pub const SQLITE_CONFIG_LOG: i32 = 16; +pub const SQLITE_CONFIG_URI: i32 = 17; +pub const SQLITE_CONFIG_PCACHE2: i32 = 18; +pub const SQLITE_CONFIG_GETPCACHE2: i32 = 19; +pub const SQLITE_CONFIG_COVERING_INDEX_SCAN: i32 = 20; +pub const SQLITE_CONFIG_SQLLOG: i32 = 21; +pub const SQLITE_CONFIG_MMAP_SIZE: i32 = 22; +pub const SQLITE_CONFIG_WIN32_HEAPSIZE: i32 = 23; +pub const SQLITE_CONFIG_PCACHE_HDRSZ: i32 = 24; +pub const SQLITE_CONFIG_PMASZ: i32 = 25; + +pub const SQLITE_DBCONFIG_MAINDBNAME: i32 = 1000; +pub const SQLITE_DBCONFIG_LOOKASIDE: i32 = 1001; +pub const SQLITE_DBCONFIG_ENABLE_FKEY: i32 = 1002; +pub const SQLITE_DBCONFIG_ENABLE_TRIGGER: i32 = 1003; +pub const SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: i32 = 1004; +pub const SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: i32 = 1005; +pub const SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: i32 = 1006; + +pub const SQLITE_DENY: i32 = 1; +pub const SQLITE_IGNORE: i32 = 2; + +pub const SQLITE_CREATE_INDEX: i32 = 1; +pub const SQLITE_CREATE_TABLE: i32 = 2; +pub const SQLITE_CREATE_TEMP_INDEX: i32 = 3; +pub const SQLITE_CREATE_TEMP_TABLE: i32 = 4; +pub const SQLITE_CREATE_TEMP_TRIGGER: i32 = 5; +pub const SQLITE_CREATE_TEMP_VIEW: i32 = 6; +pub const SQLITE_CREATE_TRIGGER: i32 = 7; +pub const SQLITE_CREATE_VIEW: i32 = 8; +pub const SQLITE_DELETE: i32 = 9; +pub const SQLITE_DROP_INDEX: i32 = 10; +pub const SQLITE_DROP_TABLE: i32 = 11; +pub const SQLITE_DROP_TEMP_INDEX: i32 = 12; +pub const SQLITE_DROP_TEMP_TABLE: i32 = 13; +pub const SQLITE_DROP_TEMP_TRIGGER: i32 = 14; +pub const SQLITE_DROP_TEMP_VIEW: i32 = 15; +pub const SQLITE_DROP_TRIGGER: i32 = 16; +pub const SQLITE_DROP_VIEW: i32 = 17; +pub const SQLITE_INSERT: i32 = 18; +pub const SQLITE_PRAGMA: i32 = 19; +pub const SQLITE_READ: i32 = 20; +pub const SQLITE_SELECT: i32 = 21; +pub const SQLITE_TRANSACTION: i32 = 22; +pub const SQLITE_UPDATE: i32 = 23; +pub const SQLITE_ATTACH: i32 = 24; +pub const SQLITE_DETACH: i32 = 25; +pub const SQLITE_ALTER_TABLE: i32 = 26; +pub const SQLITE_REINDEX: i32 = 27; +pub const SQLITE_ANALYZE: i32 = 28; +pub const SQLITE_CREATE_VTABLE: i32 = 29; +pub const SQLITE_DROP_VTABLE: i32 = 30; +pub const SQLITE_FUNCTION: i32 = 31; +pub const SQLITE_SAVEPOINT: i32 = 32; +pub const SQLITE_COPY: i32 = 0; +pub const SQLITE_RECURSIVE: i32 = 33; + +pub const SQLITE_TRACE_STMT: i32 = 0x01; +pub const SQLITE_TRACE_PROFILE: i32 = 0x02; +pub const SQLITE_TRACE_ROW: i32 = 0x04; +pub const SQLITE_TRACE_CLOSE: i32 = 0x08; + +pub const SQLITE_LIMIT_LENGTH: i32 = 0; +pub const SQLITE_LIMIT_SQL_LENGTH: i32 = 1; +pub const SQLITE_LIMIT_COLUMN: i32 = 2; +pub const SQLITE_LIMIT_EXPR_DEPTH: i32 = 3; +pub const SQLITE_LIMIT_COMPOUND_SELECT: i32 = 4; +pub const SQLITE_LIMIT_VDBE_OP: i32 = 5; +pub const SQLITE_LIMIT_FUNCTION_ARG: i32 = 6; +pub const SQLITE_LIMIT_ATTACHED: i32 = 7; +pub const SQLITE_LIMIT_LIKE_PATTERN_LENGTH: i32 = 8; +pub const SQLITE_LIMIT_VARIABLE_NUMBER: i32 = 9; +pub const SQLITE_LIMIT_TRIGGER_DEPTH: i32 = 10; +pub const SQLITE_LIMIT_WORKER_THREADS: i32 = 11; + +pub const SQLITE_INTEGER: i32 = 1; +pub const SQLITE_FLOAT: i32 = 2; +pub const SQLITE_TEXT: i32 = 3; +pub const SQLITE_BLOB: i32 = 4; +pub const SQLITE_NULL: i32 = 5; + +pub const SQLITE_UTF8: i32 = 1; +pub const SQLITE_UTF16LE: i32 = 2; +pub const SQLITE_UTF16BE: i32 = 3; +pub const SQLITE_UTF16: i32 = 4; +pub const SQLITE_ANY: i32 = 5; +pub const SQLITE_UTF16_ALIGNED: i32 = 8; + +pub const SQLITE_DETERMINISTIC: i32 = 0x800; + +pub const SQLITE_STATIC: i32 = 0; +pub const SQLITE_TRANSIENT: i32 = -1; + +pub const SQLITE_INDEX_SCAN_UNIQUE: i32 = 1; +pub const SQLITE_INDEX_CONSTRAINT_EQ: i32 = 2; +pub const SQLITE_INDEX_CONSTRAINT_GT: i32 = 4; +pub const SQLITE_INDEX_CONSTRAINT_LE: i32 = 8; +pub const SQLITE_INDEX_CONSTRAINT_LT: i32 = 16; +pub const SQLITE_INDEX_CONSTRAINT_GE: i32 = 32; +pub const SQLITE_INDEX_CONSTRAINT_MATCH: i32 = 64; +pub const SQLITE_INDEX_CONSTRAINT_LIKE: i32 = 65; +pub const SQLITE_INDEX_CONSTRAINT_GLOB: i32 = 66; +pub const SQLITE_INDEX_CONSTRAINT_REGEXP: i32 = 67; + +pub const SQLITE_MUTEX_FAST: i32 = 0; +pub const SQLITE_MUTEX_RECURSIVE: i32 = 1; +pub const SQLITE_MUTEX_STATIC_MASTER: i32 = 2; +pub const SQLITE_MUTEX_STATIC_MEM: i32 = 3; +pub const SQLITE_MUTEX_STATIC_MEM2: i32 = 4; +pub const SQLITE_MUTEX_STATIC_OPEN: i32 = 4; +pub const SQLITE_MUTEX_STATIC_PRNG: i32 = 5; +pub const SQLITE_MUTEX_STATIC_LRU: i32 = 6; +pub const SQLITE_MUTEX_STATIC_LRU2: i32 = 7; +pub const SQLITE_MUTEX_STATIC_PMEM: i32 = 7; +pub const SQLITE_MUTEX_STATIC_APP1: i32 = 8; +pub const SQLITE_MUTEX_STATIC_APP2: i32 = 9; +pub const SQLITE_MUTEX_STATIC_APP3: i32 = 10; +pub const SQLITE_MUTEX_STATIC_VFS1: i32 = 11; +pub const SQLITE_MUTEX_STATIC_VFS2: i32 = 12; +pub const SQLITE_MUTEX_STATIC_VFS3: i32 = 13; + +pub const SQLITE_TESTCTRL_FIRST: i32 = 5; +pub const SQLITE_TESTCTRL_PRNG_SAVE: i32 = 5; +pub const SQLITE_TESTCTRL_PRNG_RESTORE: i32 = 6; +pub const SQLITE_TESTCTRL_PRNG_RESET: i32 = 7; +pub const SQLITE_TESTCTRL_BITVEC_TEST: i32 = 8; +pub const SQLITE_TESTCTRL_FAULT_INSTALL: i32 = 9; +pub const SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: i32 = 10; +pub const SQLITE_TESTCTRL_PENDING_BYTE: i32 = 11; +pub const SQLITE_TESTCTRL_ASSERT: i32 = 12; +pub const SQLITE_TESTCTRL_ALWAYS: i32 = 13; +pub const SQLITE_TESTCTRL_RESERVE: i32 = 14; +pub const SQLITE_TESTCTRL_OPTIMIZATIONS: i32 = 15; +pub const SQLITE_TESTCTRL_ISKEYWORD: i32 = 16; +pub const SQLITE_TESTCTRL_SCRATCHMALLOC: i32 = 17; +pub const SQLITE_TESTCTRL_LOCALTIME_FAULT: i32 = 18; +pub const SQLITE_TESTCTRL_EXPLAIN_STMT: i32 = 19; +pub const SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD: i32 = 19; +pub const SQLITE_TESTCTRL_NEVER_CORRUPT: i32 = 20; +pub const SQLITE_TESTCTRL_VDBE_COVERAGE: i32 = 21; +pub const SQLITE_TESTCTRL_BYTEORDER: i32 = 22; +pub const SQLITE_TESTCTRL_ISINIT: i32 = 23; +pub const SQLITE_TESTCTRL_SORTER_MMAP: i32 = 24; +pub const SQLITE_TESTCTRL_IMPOSTER: i32 = 25; +pub const SQLITE_TESTCTRL_LAST: i32 = 25; + +pub const SQLITE_STATUS_MEMORY_USED: i32 = 0; +pub const SQLITE_STATUS_PAGECACHE_USED: i32 = 1; +pub const SQLITE_STATUS_PAGECACHE_OVERFLOW: i32 = 2; +pub const SQLITE_STATUS_SCRATCH_USED: i32 = 3; +pub const SQLITE_STATUS_SCRATCH_OVERFLOW: i32 = 4; +pub const SQLITE_STATUS_MALLOC_SIZE: i32 = 5; +pub const SQLITE_STATUS_PARSER_STACK: i32 = 6; +pub const SQLITE_STATUS_PAGECACHE_SIZE: i32 = 7; +pub const SQLITE_STATUS_SCRATCH_SIZE: i32 = 8; +pub const SQLITE_STATUS_MALLOC_COUNT: i32 = 9; + +pub const SQLITE_DBSTATUS_LOOKASIDE_USED: i32 = 0; +pub const SQLITE_DBSTATUS_CACHE_USED: i32 = 1; +pub const SQLITE_DBSTATUS_SCHEMA_USED: i32 = 2; +pub const SQLITE_DBSTATUS_STMT_USED: i32 = 3; +pub const SQLITE_DBSTATUS_LOOKASIDE_HIT: i32 = 4; +pub const SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: i32 = 5; +pub const SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: i32 = 6; +pub const SQLITE_DBSTATUS_CACHE_HIT: i32 = 7; +pub const SQLITE_DBSTATUS_CACHE_MISS: i32 = 8; +pub const SQLITE_DBSTATUS_CACHE_WRITE: i32 = 9; +pub const SQLITE_DBSTATUS_DEFERRED_FKS: i32 = 10; +pub const SQLITE_DBSTATUS_CACHE_USED_SHARED: i32 = 11; +pub const SQLITE_DBSTATUS_MAX: i32 = 11; + +pub const SQLITE_STMTSTATUS_FULLSCAN_STEP: i32 = 1; +pub const SQLITE_STMTSTATUS_SORT: i32 = 2; +pub const SQLITE_STMTSTATUS_AUTOINDEX: i32 = 3; +pub const SQLITE_STMTSTATUS_VM_STEP: i32 = 4; + +pub const SQLITE_CHECKPOINT_PASSIVE: i32 = 0; +pub const SQLITE_CHECKPOINT_FULL: i32 = 1; +pub const SQLITE_CHECKPOINT_RESTART: i32 = 2; +pub const SQLITE_CHECKPOINT_TRUNCATE: i32 = 3; + +pub const SQLITE_VTAB_CONSTRAINT_SUPPORT: i32 = 1; + +pub const SQLITE_ROLLBACK: i32 = 1; +pub const SQLITE_FAIL: i32 = 3; +pub const SQLITE_REPLACE: i32 = 5; + +pub const SQLITE_SCANSTAT_NLOOP: i32 = 0; +pub const SQLITE_SCANSTAT_NVISIT: i32 = 1; +pub const SQLITE_SCANSTAT_EST: i32 = 2; +pub const SQLITE_SCANSTAT_NAME: i32 = 3; +pub const SQLITE_SCANSTAT_EXPLAIN: i32 = 4; +pub const SQLITE_SCANSTAT_SELECTID: i32 = 5; diff --git a/src/sqlite3_connector/import_functions.rs b/src/sqlite3_connector/import_functions.rs new file mode 100644 index 0000000..21c9861 --- /dev/null +++ b/src/sqlite3_connector/import_functions.rs @@ -0,0 +1,138 @@ +extern crate fluence; + +use self::fluence::fce; + +pub(crate) type Sqlite3DbHandle = u32; +pub(crate) type Sqlite3StmtHandle = u32; + +#[fce] +#[derive(Clone, Debug)] +pub struct DBOpenDescriptor { + pub ret_code: i32, + pub db_handle: u32, +} + +#[fce] +#[derive(Clone, Debug)] +pub struct DBPrepareDescriptor { + pub ret_code: i32, + pub stmt_handle: u32, + pub tail: u32, +} + +#[fce] +#[derive(Clone, Debug)] +pub struct DBExecDescriptor { + pub ret_code: i32, + pub err_msg: String, +} + +#[fce] +#[link(wasm_import_module = "sqlite3")] +extern "C" { + /* + SQLITE_API int sqlite3_open_v2( + const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + int flags, /* Flags */ + const char *zVfs /* Name of VFS module to use */ + ); + */ + pub fn sqlite3_open_v2(filename: String, flags: i32, vfs: String) -> DBOpenDescriptor; + + // SQLITE_API int sqlite3_close(sqlite3*); + pub fn sqlite3_close(db_handle: u32) -> i32; + + /* + SQLITE_API int sqlite3_prepare_v2( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ + ); + */ + pub fn sqlite3_prepare_v2(db_handle: u32, sql: String) -> DBPrepareDescriptor; + + /* + SQLITE_API int sqlite3_exec( + sqlite3*, /* An open database */ + const char *sql, /* SQL to be evaluated */ + int (*callback)(void*,int,char**,char**), /* Callback function */ + void *, /* 1st argument to callback */ + char **errmsg /* Error msg written here */ + ); + */ + pub fn sqlite3_exec( + db_handle: u32, + sql: String, + callback_id: i32, + callback_arg: i32, + ) -> DBExecDescriptor; + + // SQLITE_API int sqlite3_libversion_number(void); + pub fn sqlite3_libversion_number() -> i32; + + // SQLITE_API int sqlite3_changes(sqlite3*); + pub fn sqlite3_changes(db_handle: u32) -> i32; + + // SQLITE_API int sqlite3_total_changes(sqlite3*); + pub fn sqlite3_total_changes(db_handle: u32) -> i32; + + // SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); + pub fn sqlite3_busy_timeout(db_handle: u32, ms: u32) -> i32; + + // SQLITE_API const char *sqlite3_errmsg(sqlite3*); + pub fn sqlite3_errmsg(db_handle: u32) -> String; + + // SQLITE_API int sqlite3_errcode(sqlite3 *db); + pub fn sqlite3_errcode(db: u32) -> i32; + + // SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_type(stmt_handle: u32, icol: u32) -> i32; + + // SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); + pub fn sqlite3_column_name(stmt_handle: u32, N: u32) -> String; + + // SQLITE_API int sqlite3_step(sqlite3_stmt*); + pub fn sqlite3_step(stmt_handle: u32) -> i32; + + // SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); + pub fn sqlite3_reset(stmt_handle: u32) -> i32; + + // SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); + pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: Vec, xDel: i32) -> i32; + + // SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); + pub fn sqlite3_bind_double(stmt_handle: u32, pos: i32, value: f64) -> i32; + + // SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); + pub fn sqlite3_bind_int64(stmt_handle: u32, pos: i32, value: i64) -> i32; + + // SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); + pub fn sqlite3_bind_null(stmt_handle: u32, pos: i32) -> i32; + + // SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); + pub fn sqlite3_bind_text(stmt_handle: u32, pos: i32, text: String, xDel: i32) -> i32; + + // SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt) + pub fn sqlite3_column_count(stmt_handle: u32) -> i32; + + // SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_blob(stmt_handle: u32, icol: i32) -> Vec; + + // SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_double(stmt_handle: u32, icol: i32) -> f64; + + // SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_int64(stmt_handle: u32, icol: u32) -> i64; + + // SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_text(stmt_handle: u32, icol: u32) -> String; + + // SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); + pub fn sqlite3_column_bytes(stmt_handle: u32, icol: u32) -> i32; + + // SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); + pub fn sqlite3_finalize(stmt_handle: u32) -> i32; +} diff --git a/src/sqlite3_connector/mod.rs b/src/sqlite3_connector/mod.rs new file mode 100644 index 0000000..fefe3bd --- /dev/null +++ b/src/sqlite3_connector/mod.rs @@ -0,0 +1,5 @@ +mod consts; +mod import_functions; + +pub(crate) use self::consts::*; +pub(crate) use self::import_functions::*; diff --git a/src/statement.rs b/src/statement.rs index abff1d1..1920c9e 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -1,18 +1,12 @@ -use ffi; -use libc::{c_double, c_int}; +use sqlite3_connector as ffi; use std::marker::PhantomData; use {Cursor, Result, Type, Value}; -// https://sqlite.org/c3ref/c_static.html -macro_rules! transient( - () => (::std::mem::transmute(!0 as *const ::libc::c_void)); -); - /// A prepared statement. -pub struct Statement<'l> { - raw: (*mut ffi::sqlite3_stmt, *mut ffi::sqlite3), - phantom: PhantomData<(ffi::sqlite3_stmt, &'l ffi::sqlite3)>, +pub struct Statement { + raw: (ffi::Sqlite3StmtHandle, ffi::Sqlite3DbHandle), + phantom: PhantomData<(ffi::Sqlite3StmtHandle, ffi::Sqlite3DbHandle)>, } /// A state of a prepared statement. @@ -29,7 +23,7 @@ pub trait Bindable { /// Bind to a parameter. /// /// The leftmost parameter has the index 1. - fn bind(self, &mut Statement, usize) -> Result<()>; + fn bind(self, _: &mut Statement, _: usize) -> Result<()>; } /// A type suitable for reading from a prepared statement. @@ -40,7 +34,7 @@ pub trait Readable: Sized { fn read(&Statement, usize) -> Result; } -impl<'l> Statement<'l> { +impl Statement { /// Bind a value to a parameter. /// /// The leftmost parameter has the index 1. @@ -60,7 +54,7 @@ impl<'l> Statement<'l> { /// The type becomes available after taking a step. pub fn kind(&self, i: usize) -> Type { debug_assert!(i < self.count(), "the index is out of range"); - match unsafe { ffi::sqlite3_column_type(self.raw.0, i as c_int) } { + match unsafe { ffi::sqlite3_column_type(self.raw.0, i as _) } { ffi::SQLITE_BLOB => Type::Binary, ffi::SQLITE_FLOAT => Type::Float, ffi::SQLITE_INTEGER => Type::Integer, @@ -72,18 +66,14 @@ impl<'l> Statement<'l> { /// Return the name of a column. #[inline] - pub fn name(&self, i: usize) -> &str { + pub fn name(&self, i: usize) -> String { debug_assert!(i < self.count(), "the index is out of range"); - unsafe { - let pointer = ffi::sqlite3_column_name(self.raw.0, i as c_int); - debug_assert!(!pointer.is_null()); - c_str_to_str!(pointer).unwrap() - } + unsafe { ffi::sqlite3_column_name(self.raw.0, i as _) } } /// Return column names. #[inline] - pub fn names(&self) -> Vec<&str> { + pub fn names(&self) -> Vec { (0..self.count()).map(|i| self.name(i)).collect() } @@ -111,31 +101,31 @@ impl<'l> Statement<'l> { /// Reset the statement. #[inline] pub fn reset(&mut self) -> Result<()> { - unsafe { ok!(self.raw.1, ffi::sqlite3_reset(self.raw.0)) }; + unsafe { ok_raw!(self.raw.1, ffi::sqlite3_reset(self.raw.0)) }; Ok(()) } /// Upgrade to a cursor. #[inline] - pub fn cursor(self) -> Cursor<'l> { + pub fn cursor(self) -> Cursor { ::cursor::new(self) } /// Return the raw pointer. #[inline] - pub fn as_raw(&self) -> *mut ffi::sqlite3_stmt { + pub fn as_raw(&self) -> ffi::Sqlite3StmtHandle { self.raw.0 } } -impl<'l> Drop for Statement<'l> { +impl<'l> Drop for Statement { #[inline] fn drop(&mut self) { unsafe { ffi::sqlite3_finalize(self.raw.0) }; } } -impl<'l> Bindable for &'l Value { +impl Bindable for &Value { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { match self { &Value::Binary(ref value) => (value as &[u8]).bind(statement, i), @@ -147,20 +137,14 @@ impl<'l> Bindable for &'l Value { } } -impl<'l> Bindable for &'l [u8] { +impl Bindable for &[u8] { #[inline] fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { - ok!( + ok_raw!( statement.raw.1, - ffi::sqlite3_bind_blob( - statement.raw.0, - i as c_int, - self.as_ptr() as *const _, - self.len() as c_int, - transient!(), - ) + ffi::sqlite3_bind_blob(statement.raw.0, i as _, self.into(), 0) ); } Ok(()) @@ -172,9 +156,9 @@ impl Bindable for f64 { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { - ok!( + ok_raw!( statement.raw.1, - ffi::sqlite3_bind_double(statement.raw.0, i as c_int, self as c_double) + ffi::sqlite3_bind_double(statement.raw.0, i as i32, self) ); } Ok(()) @@ -186,9 +170,9 @@ impl Bindable for i64 { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { - ok!( + ok_raw!( statement.raw.1, - ffi::sqlite3_bind_int64(statement.raw.0, i as c_int, self as ffi::sqlite3_int64) + ffi::sqlite3_bind_int64(statement.raw.0, i as i32, self as _) ); } Ok(()) @@ -200,15 +184,9 @@ impl<'l> Bindable for &'l str { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { - ok!( + ok_raw!( statement.raw.1, - ffi::sqlite3_bind_text( - statement.raw.0, - i as c_int, - self.as_ptr() as *const _, - self.len() as c_int, - transient!(), - ) + ffi::sqlite3_bind_text(statement.raw.0, i as i32, self.into(), 0) ); } Ok(()) @@ -220,9 +198,9 @@ impl Bindable for () { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); unsafe { - ok!( + ok_raw!( statement.raw.1, - ffi::sqlite3_bind_null(statement.raw.0, i as c_int) + ffi::sqlite3_bind_null(statement.raw.0, i as i32) ); } Ok(()) @@ -255,45 +233,28 @@ impl Readable for Value { impl Readable for f64 { #[inline] fn read(statement: &Statement, i: usize) -> Result { - Ok(unsafe { ffi::sqlite3_column_double(statement.raw.0, i as c_int) as f64 }) + Ok(unsafe { ffi::sqlite3_column_double(statement.raw.0, i as _) }) } } impl Readable for i64 { #[inline] fn read(statement: &Statement, i: usize) -> Result { - Ok(unsafe { ffi::sqlite3_column_int64(statement.raw.0, i as c_int) as i64 }) + Ok(unsafe { ffi::sqlite3_column_int64(statement.raw.0, i as _) }) } } impl Readable for String { #[inline] fn read(statement: &Statement, i: usize) -> Result { - unsafe { - let pointer = ffi::sqlite3_column_text(statement.raw.0, i as c_int); - if pointer.is_null() { - raise!("cannot read a text column"); - } - Ok(c_str_to_string!(pointer)) - } + unsafe { Ok(ffi::sqlite3_column_text(statement.raw.0, i as _)) } } } impl Readable for Vec { #[inline] fn read(statement: &Statement, i: usize) -> Result { - use std::ptr::copy_nonoverlapping as copy; - unsafe { - let pointer = ffi::sqlite3_column_blob(statement.raw.0, i as c_int); - if pointer.is_null() { - return Ok(vec![]); - } - let count = ffi::sqlite3_column_bytes(statement.raw.0, i as c_int) as usize; - let mut buffer = Vec::with_capacity(count); - buffer.set_len(count); - copy(pointer as *const u8, buffer.as_mut_ptr(), count); - Ok(buffer) - } + unsafe { Ok(ffi::sqlite3_column_blob(statement.raw.0, i as i32)) } } } @@ -309,22 +270,14 @@ impl Readable for Option { } #[inline] -pub fn new<'l, T: AsRef>(raw1: *mut ffi::sqlite3, statement: T) -> Result> { - let mut raw0 = 0 as *mut _; - unsafe { - ok!( - raw1, - ffi::sqlite3_prepare_v2( - raw1, - str_to_cstr!(statement.as_ref()).as_ptr(), - -1, - &mut raw0, - 0 as *mut _, - ) - ); +pub fn new>(raw1: ffi::Sqlite3DbHandle, statement: T) -> Result { + let result = unsafe { ffi::sqlite3_prepare_v2(raw1, statement.as_ref().into()) }; + if result.ret_code != ffi::SQLITE_OK { + error!(raw1, result.ret_code) } + Ok(Statement { - raw: (raw0, raw1), + raw: (result.stmt_handle, raw1), phantom: PhantomData, }) } diff --git a/src/test.rs b/src/test.rs new file mode 100644 index 0000000..76f9bef --- /dev/null +++ b/src/test.rs @@ -0,0 +1,86 @@ +extern crate fluence; +extern crate sqlite; + +use fluence::fce; +use sqlite::State; + +pub fn main() {} + +#[fce] +pub fn test1() { + let connection = sqlite::open(":memory:").unwrap(); + + connection + .execute( + " + CREATE TABLE users (name TEXT, age INTEGER); + INSERT INTO users VALUES ('Alice', 42); + INSERT INTO users VALUES ('Bob', 69); + ", + ) + .unwrap(); + + connection + .iterate("SELECT * FROM users WHERE age > 50", |pairs| { + for &(column, value) in pairs.iter() { + println!("{} = {}", column, value.unwrap()); + } + true + }) + .unwrap(); +} + +#[fce] +pub fn test2() { + let connection = sqlite::open(":memory:").unwrap(); + + println!("connection id = {}\n", connection.as_raw()); + connection + .execute( + " + CREATE TABLE users (name TEXT, age INTEGER); + INSERT INTO users VALUES ('Alice', 42); + INSERT INTO users VALUES ('Bob', 69); + ", + ) + .unwrap(); + + let mut statement = connection + .prepare("SELECT * FROM users WHERE age > ?") + .unwrap(); + + statement.bind(1, 50).unwrap(); + + while let State::Row = statement.next().unwrap() { + println!("name = {}", statement.read::(0).unwrap()); + println!("age = {}", statement.read::(1).unwrap()); + } +} +#[fce] +pub fn test3() { + use sqlite::Value; + + let connection = sqlite::open(":memory:").unwrap(); + + connection + .execute( + " + CREATE TABLE users (name TEXT, age INTEGER); + INSERT INTO users VALUES ('Alice', 42); + INSERT INTO users VALUES ('Bob', 69); + ", + ) + .unwrap(); + + let mut cursor = connection + .prepare("SELECT * FROM users WHERE age > ?") + .unwrap() + .cursor(); + + cursor.bind(&[Value::Integer(50)]).unwrap(); + + while let Some(row) = cursor.next().unwrap() { + println!("name = {}", row[0].as_string().unwrap()); + println!("age = {}", row[1].as_integer().unwrap()); + } +} diff --git a/src/wit_generator.rs b/src/wit_generator.rs new file mode 100644 index 0000000..63a690e --- /dev/null +++ b/src/wit_generator.rs @@ -0,0 +1,211 @@ +extern crate fluence; + +use fluence::fce; + +pub fn main() {} + +#[fce] +#[derive(Default)] +pub struct DBOpenDescriptor { + pub ret_code: i32, + pub db_handle: u32, +} + +#[fce] +#[derive(Default)] +pub struct DBPrepareDescriptor { + pub ret_code: i32, + pub stmt_handle: u32, + pub tail: u32, +} + +#[fce] +#[derive(Default)] +pub struct DBExecDescriptor { + pub ret_code: i32, + pub err_msg: String, +} + +/* + SQLITE_API int sqlite3_open_v2( + const char *filename, /* Database filename (UTF-8) */ + sqlite3 **ppDb, /* OUT: SQLite db handle */ + int flags, /* Flags */ + const char *zVfs /* Name of VFS module to use */ + ); +*/ +#[fce] +pub fn sqlite3_open_v2(filename: String, flags: i32, vfs: String) -> DBOpenDescriptor { + <_>::default() +} + +// SQLITE_API int sqlite3_close(sqlite3*); +#[fce] +pub fn sqlite3_close(db_handle: u32) -> i32 { + <_>::default() +} + +/* + SQLITE_API int sqlite3_prepare_v2( + sqlite3 *db, /* Database handle */ + const char *zSql, /* SQL statement, UTF-8 encoded */ + int nByte, /* Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /* OUT: Statement handle */ + const char **pzTail /* OUT: Pointer to unused portion of zSql */ + ); +*/ +#[fce] +pub fn sqlite3_prepare_v2(db_handle: u32, sql: String) -> DBPrepareDescriptor { + <_>::default() +} + +/* + SQLITE_API int sqlite3_exec( + sqlite3*, /* An open database */ + const char *sql, /* SQL to be evaluated */ + int (*callback)(void*,int,char**,char**), /* Callback function */ + void *, /* 1st argument to callback */ + char **errmsg /* Error msg written here */ + ); +*/ +#[fce] +pub fn sqlite3_exec( + db_handle: u32, + sql: String, + callback_id: i32, + callback_arg: i32, +) -> DBExecDescriptor { + <_>::default() +} + +// SQLITE_API int sqlite3_libversion_number(void); +#[fce] +pub fn sqlite3_libversion_number() -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_changes(sqlite3*); +#[fce] +pub fn sqlite3_changes(db_handle: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_total_changes(sqlite3*); +#[fce] +pub fn sqlite3_total_changes(db_handle: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); +#[fce] +pub fn sqlite3_busy_timeout(db_handle: u32, ms: u32) -> i32 { + <_>::default() +} + +// SQLITE_API const char *sqlite3_errmsg(sqlite3*); +#[fce] +pub fn sqlite3_errmsg(db_handle: u32) -> String { + <_>::default() +} + +// SQLITE_API int sqlite3_errcode(sqlite3 *db); +#[fce] +pub fn sqlite3_errcode(db: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_type(stmt_handle: u32, icol: u32) -> i32 { + <_>::default() +} + +// SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); +#[fce] +pub fn sqlite3_column_name(stmt_handle: u32, N: u32) -> String { + <_>::default() +} + +// SQLITE_API int sqlite3_step(sqlite3_stmt*); +#[fce] +pub fn sqlite3_step(stmt_handle: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); +#[fce] +pub fn sqlite3_reset(stmt_handle: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); +#[fce] +pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: Vec, xDel: i32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); +#[fce] +pub fn sqlite3_bind_double(stmt_handle: u32, pos: i32, value: f64) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); +#[fce] +pub fn sqlite3_bind_int64(stmt_handle: u32, pos: i32, value: i64) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); +#[fce] +pub fn sqlite3_bind_null(stmt_handle: u32, pos: i32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); +#[fce] +pub fn sqlite3_bind_text(stmt_handle: u32, pos: i32, text: String, xDel: i32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt) +#[fce] +pub fn sqlite3_column_count(stmt_handle: u32) -> i32 { + <_>::default() +} + +// SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_blob(stmt_handle: u32, icol: i32) -> Vec { + <_>::default() +} + +// SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_double(stmt_handle: u32, icol: i32) -> f64 { + <_>::default() +} + +// SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_int64(stmt_handle: u32, icol: u32) -> i64 { + <_>::default() +} + +// SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_text(stmt_handle: u32, icol: u32) -> String { + <_>::default() +} + +// SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); +#[fce] +pub fn sqlite3_column_bytes(stmt_handle: u32, icol: u32) -> i32 { + <_>::default() +} + +// SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); +#[fce] +pub fn sqlite3_finalize(stmt_handle: u32) -> i32 { + <_>::default() +}