@@ -8,8 +8,8 @@ use crate::sqlite::{SqliteColumn, SqliteError, SqliteRow, SqliteValue};
8
8
use crate :: HashMap ;
9
9
use bytes:: { Buf , Bytes } ;
10
10
use 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 ,
13
13
} ;
14
14
use smallvec:: SmallVec ;
15
15
use std:: i32;
@@ -31,7 +31,7 @@ pub(crate) struct VirtualStatement {
31
31
// underlying sqlite handles for each inner statement
32
32
// a SQL query string in SQLite is broken up into N statements
33
33
// 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 ] > ,
35
35
36
36
// each set of columns
37
37
pub ( crate ) columns : SmallVec < [ Arc < Vec < SqliteColumn > > ; 1 ] > ,
@@ -126,7 +126,7 @@ impl VirtualStatement {
126
126
conn : & mut ConnectionHandle ,
127
127
) -> Result <
128
128
Option < (
129
- & StatementHandle ,
129
+ & Arc < StatementHandle > ,
130
130
& mut Arc < Vec < SqliteColumn > > ,
131
131
& Arc < HashMap < UStr , usize > > ,
132
132
& mut Option < Weak < AtomicPtr < SqliteValue > > > ,
@@ -159,7 +159,7 @@ impl VirtualStatement {
159
159
column_names. insert ( name, i) ;
160
160
}
161
161
162
- self . handles . push ( statement) ;
162
+ self . handles . push ( Arc :: new ( statement) ) ;
163
163
self . columns . push ( Arc :: new ( columns) ) ;
164
164
self . column_names . push ( Arc :: new ( column_names) ) ;
165
165
self . last_row_values . push ( None ) ;
@@ -198,20 +198,6 @@ impl Drop for VirtualStatement {
198
198
fn drop ( & mut self ) {
199
199
for ( i, handle) in self . handles . drain ( ..) . enumerate ( ) {
200
200
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
- }
215
201
}
216
202
}
217
203
}
0 commit comments