@@ -236,6 +236,22 @@ pub unsafe extern "C" fn sqlite3_bind_int64(
236236 SQLITE_OK
237237}
238238
239+ #[ no_mangle]
240+ pub extern "C" fn sqlite3_bind_null ( stmt_ptr : * mut SQLite3PreparedStmt , index : c_int ) -> c_int {
241+ if stmt_ptr. is_null ( ) {
242+ return SQLITE_MISUSE ;
243+ }
244+
245+ let stmt = unsafe { & mut * stmt_ptr } ;
246+
247+ if index <= 0 || index > stmt. param_count {
248+ return SQLITE_RANGE ;
249+ }
250+
251+ stmt. params . insert ( index, Value :: Null ) ;
252+ SQLITE_OK
253+ }
254+
239255#[ no_mangle]
240256pub unsafe extern "C" fn sqlite3_step ( stmt_ptr : * mut SQLite3PreparedStmt ) -> c_int {
241257 if stmt_ptr. is_null ( ) {
@@ -246,7 +262,7 @@ pub unsafe extern "C" fn sqlite3_step(stmt_ptr: *mut SQLite3PreparedStmt) -> c_i
246262
247263 let mut exec_state = match stmt. execution_state . lock ( ) {
248264 Ok ( guard) => guard,
249- Err ( _) => return SQLITE_ERROR , // Lock poisoned
265+ Err ( _) => return SQLITE_ERROR ,
250266 } ;
251267
252268 match * exec_state {
@@ -261,17 +277,15 @@ pub unsafe extern "C" fn sqlite3_step(stmt_ptr: *mut SQLite3PreparedStmt) -> c_i
261277 drop ( exec_state) ;
262278
263279 let sql = stmt. sql . to_uppercase ( ) ;
264- if sql. starts_with ( "INSERT" ) {
265- return execute_async_task ( stmt. db , sqlite:: handle_insert ( stmt) ) ;
266- } else if sql. starts_with ( "SELECT" ) {
280+ if sql. starts_with ( "SELECT" ) {
267281 return execute_async_task ( stmt. db , sqlite:: handle_select ( stmt) ) ;
268282 } else if sql_is_begin_transaction ( & sql) {
269283 return execute_async_task ( stmt. db , sqlite:: begin_tnx_on_db ( stmt. db ) ) ;
270284 } else if sql_is_commit ( & sql) {
271285 return execute_async_task ( stmt. db , sqlite:: commit_tnx_on_db ( stmt. db ) ) ;
272286 }
273287
274- SQLITE_ERROR
288+ execute_async_task ( stmt . db , sqlite :: execute_statement ( stmt ) )
275289}
276290
277291#[ no_mangle]
@@ -363,18 +377,18 @@ pub extern "C" fn sqlite3_extended_errcode(db: *mut SQLite3) -> c_int {
363377#[ no_mangle]
364378pub extern "C" fn sqlite3_errmsg ( db : * mut SQLite3 ) -> * const c_char {
365379 if db. is_null ( ) {
366- return std :: ptr :: null ( ) ;
380+ return b"Invalid DB pointer \0 " . as_ptr ( ) as * const c_char ;
367381 }
368382
369383 let db = unsafe { & mut * db } ;
370384
371385 if let Some ( error_entry) = sqlite:: get_latest_error ( db) {
372386 match CString :: new ( error_entry. 0 ) {
373- Ok ( c_string) => c_string. into_raw ( ) ,
387+ Ok ( c_string) => c_string. as_ptr ( ) ,
374388 Err ( _) => std:: ptr:: null ( ) ,
375389 }
376390 } else {
377- std :: ptr :: null ( )
391+ b"No error \0 " . as_ptr ( ) as * const c_char
378392 }
379393}
380394
@@ -594,14 +608,14 @@ pub unsafe extern "C" fn sqlite3_exec(
594608 if sql_is_pragma ( & sql) {
595609 return SQLITE_OK ;
596610 } else if sql_is_begin_transaction ( & sql) {
597- execute_async_task ( db, sqlite:: begin_tnx_on_db ( db) )
611+ return execute_async_task ( db, sqlite:: begin_tnx_on_db ( db) ) ;
598612 } else if sql_is_rollback ( & sql) {
599- reset_txn_on_db ( db)
613+ return reset_txn_on_db ( db) ;
600614 } else if sql_is_commit ( & sql) {
601- execute_async_task ( db, sqlite:: commit_tnx_on_db ( db) )
602- } else {
603- execute_async_task ( db, sqlite:: handle_execute ( db, & sql) )
615+ return execute_async_task ( db, sqlite:: commit_tnx_on_db ( db) ) ;
604616 }
617+
618+ execute_async_task ( db, sqlite:: handle_execute ( db, & sql) )
605619}
606620
607621#[ no_mangle]
0 commit comments