Unable to use SQLite3 in Rust via FFI due to a misused prepared statement -


i porting code rust reads database path stdin, opens database , loops queries. have done similar in c pretty sure problem non-understanding of rust ffi.

i using sqlite3 binding provided libsqlite3-sys, 1 rusqlite. the whole code here.

open_connection initializes pointer , passes sqlite3_open_v2 , checks if went well.

// line 54 of complete code  fn open_connection(s: string) -> result<rawconnection, sqlite3error> {     unsafe {         let mut db: *mut sqlite3::sqlite3 = mem::uninitialized();         let r = sqlite3::sqlite3_open_v2(cstring::new(s).unwrap().as_ptr(),                                          &mut db,                                          sqlite3::sqlite_open_create |                                          sqlite3::sqlite_open_readwrite,                                          ptr::null());         match r {             sqlite3::sqlite_ok => ok(rawconnection { db: db }),             _ => return err(sqlite3error::openerror),         }     } } 

i create sql statement converting query rust string c string, creating pointer location of statement , go on creating statement , checking output:

// line 35 of complete code fn create_statement(conn: &rawconnection, query: string) -> result<statement, sqlite3error> {     let len = query.len();     let raw_query = cstring::new(query).unwrap().as_ptr();     unsafe {         let mut stmt: *mut sqlite3::sqlite3_stmt = mem::uninitialized();         if stmt.is_null() {             println!("now null!");         }         match sqlite3::sqlite3_prepare_v2(conn.db,                                           raw_query,                                           len i32,                                           &mut stmt,                                           ptr::null_mut()) {             sqlite3::sqlite_ok => ok(statement { stmt: stmt }),             _ => err(sqlite3error::statementerror),         }     } } 

i try execute statement

// line 81 of complete code fn execute_statement(conn: &rawconnection, stmt: statement) -> result<cursor, sqlite3error> {      match unsafe { sqlite3::sqlite3_step(stmt.stmt) } {         sqlite3::sqlite_ok => ok(cursor::okcursor),         sqlite3::sqlite_done => ok(cursor::donecursor),         sqlite3::sqlite_row => {             let n_columns = unsafe { sqlite3::sqlite3_column_count(stmt.stmt) } i32;             let mut types: vec<entitytype> = vec::new();             in 0..n_columns {                 types.push(match unsafe { sqlite3::sqlite3_column_type(stmt.stmt, i) } {                     sqlite3::sqlite_integer => entitytype::integer,                     sqlite3::sqlite_float => entitytype::float,                     sqlite3::sqlite_text => entitytype::text,                     sqlite3::sqlite_blob => entitytype::blob,                     sqlite3::sqlite_null => entitytype::null,                     _ => entitytype::null,                 })             }             ok(cursor::rowscursor {                 stmt: stmt,                 num_columns: n_columns,                 types: types,                 previous_status: sqlite3::sqlite_row,             })         }         x => {             println!("{}", x);             return err(sqlite3error::executeerror);         }     } } 

this fails error code 21 misuse. usually, error happens when try execute null statement have no idea how figure out.

do see other problem may cause code 21 misuse?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -