@@ -8,8 +8,8 @@ use crate::sqlite::{SqliteColumn, SqliteError, SqliteRow, SqliteValue};
88use crate :: HashMap ;
99use bytes:: { Buf , Bytes } ;
1010use libsqlite3_sys:: {
11- sqlite3, sqlite3_clear_bindings, sqlite3_finalize , sqlite3_prepare_v3, sqlite3_reset,
12- sqlite3_stmt , SQLITE_MISUSE , SQLITE_OK , SQLITE_PREPARE_PERSISTENT ,
11+ sqlite3, sqlite3_clear_bindings, sqlite3_prepare_v3, sqlite3_reset, sqlite3_stmt , SQLITE_OK ,
12+ SQLITE_PREPARE_PERSISTENT ,
1313} ;
1414use smallvec:: SmallVec ;
1515use std:: i32;
@@ -31,7 +31,7 @@ pub(crate) struct VirtualStatement {
3131 // underlying sqlite handles for each inner statement
3232 // a SQL query string in SQLite is broken up into N statements
3333 // we use a [`SmallVec`] to optimize for the most likely case of a single statement
34- pub ( crate ) handles : SmallVec < [ StatementHandle ; 1 ] > ,
34+ pub ( crate ) handles : SmallVec < [ Arc < StatementHandle > ; 1 ] > ,
3535
3636 // each set of columns
3737 pub ( crate ) columns : SmallVec < [ Arc < Vec < SqliteColumn > > ; 1 ] > ,
@@ -126,7 +126,7 @@ impl VirtualStatement {
126126 conn : & mut ConnectionHandle ,
127127 ) -> Result <
128128 Option < (
129- & StatementHandle ,
129+ & Arc < StatementHandle > ,
130130 & mut Arc < Vec < SqliteColumn > > ,
131131 & Arc < HashMap < UStr , usize > > ,
132132 & mut Option < Weak < AtomicPtr < SqliteValue > > > ,
@@ -159,7 +159,7 @@ impl VirtualStatement {
159159 column_names. insert ( name, i) ;
160160 }
161161
162- self . handles . push ( statement) ;
162+ self . handles . push ( Arc :: new ( statement) ) ;
163163 self . columns . push ( Arc :: new ( columns) ) ;
164164 self . column_names . push ( Arc :: new ( column_names) ) ;
165165 self . last_row_values . push ( None ) ;
@@ -198,20 +198,6 @@ impl Drop for VirtualStatement {
198198 fn drop ( & mut self ) {
199199 for ( i, handle) in self . handles . drain ( ..) . enumerate ( ) {
200200 SqliteRow :: inflate_if_needed ( & handle, & self . columns [ i] , self . last_row_values [ i] . take ( ) ) ;
201-
202- unsafe {
203- // https://sqlite.org/c3ref/finalize.html
204- let status = sqlite3_finalize ( handle. 0 . as_ptr ( ) ) ;
205- if status == SQLITE_MISUSE {
206- // Panic in case of detected misuse of SQLite API.
207- //
208- // sqlite3_finalize returns it at least in the
209- // case of detected double free, i.e. calling
210- // sqlite3_finalize on already finalized
211- // statement.
212- panic ! ( "Detected sqlite3_finalize misuse." ) ;
213- }
214- }
215201 }
216202 }
217203}
0 commit comments