@@ -5,7 +5,7 @@ use std::thread;
5
5
6
6
use futures_channel:: oneshot;
7
7
use futures_intrusive:: sync:: { Mutex , MutexGuard } ;
8
- use sqlx_core:: sql_str:: { AssertSqlSafe , SqlSafeStr } ;
8
+ use sqlx_core:: sql_str:: SqlStr ;
9
9
use tracing:: span:: Span ;
10
10
11
11
use sqlx_core:: describe:: Describe ;
@@ -42,15 +42,15 @@ pub(crate) struct WorkerSharedState {
42
42
43
43
enum Command {
44
44
Prepare {
45
- query : Box < str > ,
45
+ query : SqlStr ,
46
46
tx : oneshot:: Sender < Result < SqliteStatement , Error > > ,
47
47
} ,
48
48
Describe {
49
- query : Box < str > ,
49
+ query : SqlStr ,
50
50
tx : oneshot:: Sender < Result < Describe < Sqlite > , Error > > ,
51
51
} ,
52
52
Execute {
53
- query : Box < str > ,
53
+ query : SqlStr ,
54
54
arguments : Option < SqliteArguments < ' static > > ,
55
55
persistent : bool ,
56
56
tx : flume:: Sender < Result < Either < SqliteQueryResult , SqliteRow > , Error > > ,
@@ -132,7 +132,7 @@ impl ConnectionWorker {
132
132
let _guard = span. enter ( ) ;
133
133
match cmd {
134
134
Command :: Prepare { query, tx } => {
135
- tx. send ( prepare ( & mut conn, & query) . map ( |prepared| {
135
+ tx. send ( prepare ( & mut conn, query) . map ( |prepared| {
136
136
update_cached_statements_size (
137
137
& conn,
138
138
& shared. cached_statements_size ,
@@ -142,7 +142,7 @@ impl ConnectionWorker {
142
142
. ok ( ) ;
143
143
}
144
144
Command :: Describe { query, tx } => {
145
- tx. send ( describe ( & mut conn, & query) ) . ok ( ) ;
145
+ tx. send ( describe ( & mut conn, query) ) . ok ( ) ;
146
146
}
147
147
Command :: Execute {
148
148
query,
@@ -151,7 +151,7 @@ impl ConnectionWorker {
151
151
tx,
152
152
limit
153
153
} => {
154
- let iter = match execute:: iter ( & mut conn, & query, arguments, persistent)
154
+ let iter = match execute:: iter ( & mut conn, query, arguments, persistent)
155
155
{
156
156
Ok ( iter) => iter,
157
157
Err ( e) => {
@@ -198,7 +198,7 @@ impl ConnectionWorker {
198
198
let depth = conn. transaction_depth ;
199
199
let res =
200
200
conn. handle
201
- . exec ( begin_ansi_transaction_sql ( depth) )
201
+ . exec ( begin_ansi_transaction_sql ( depth) . as_str ( ) )
202
202
. map ( |_| {
203
203
conn. transaction_depth += 1 ;
204
204
} ) ;
@@ -211,7 +211,7 @@ impl ConnectionWorker {
211
211
// immediately otherwise it would remain started forever.
212
212
if let Err ( error) = conn
213
213
. handle
214
- . exec ( rollback_ansi_transaction_sql ( depth + 1 ) )
214
+ . exec ( rollback_ansi_transaction_sql ( depth + 1 ) . as_str ( ) )
215
215
. map ( |_| {
216
216
conn. transaction_depth -= 1 ;
217
217
} )
@@ -229,7 +229,7 @@ impl ConnectionWorker {
229
229
230
230
let res = if depth > 0 {
231
231
conn. handle
232
- . exec ( commit_ansi_transaction_sql ( depth) )
232
+ . exec ( commit_ansi_transaction_sql ( depth) . as_str ( ) )
233
233
. map ( |_| {
234
234
conn. transaction_depth -= 1 ;
235
235
} )
@@ -255,7 +255,7 @@ impl ConnectionWorker {
255
255
256
256
let res = if depth > 0 {
257
257
conn. handle
258
- . exec ( rollback_ansi_transaction_sql ( depth) )
258
+ . exec ( rollback_ansi_transaction_sql ( depth) . as_str ( ) )
259
259
. map ( |_| {
260
260
conn. transaction_depth -= 1 ;
261
261
} )
@@ -308,25 +308,19 @@ impl ConnectionWorker {
308
308
establish_rx. await . map_err ( |_| Error :: WorkerCrashed ) ?
309
309
}
310
310
311
- pub ( crate ) async fn prepare ( & mut self , query : & str ) -> Result < SqliteStatement , Error > {
312
- self . oneshot_cmd ( |tx| Command :: Prepare {
313
- query : query. into ( ) ,
314
- tx,
315
- } )
316
- . await ?
311
+ pub ( crate ) async fn prepare ( & mut self , query : SqlStr ) -> Result < SqliteStatement , Error > {
312
+ self . oneshot_cmd ( |tx| Command :: Prepare { query, tx } )
313
+ . await ?
317
314
}
318
315
319
- pub ( crate ) async fn describe ( & mut self , query : & str ) -> Result < Describe < Sqlite > , Error > {
320
- self . oneshot_cmd ( |tx| Command :: Describe {
321
- query : query. into ( ) ,
322
- tx,
323
- } )
324
- . await ?
316
+ pub ( crate ) async fn describe ( & mut self , query : SqlStr ) -> Result < Describe < Sqlite > , Error > {
317
+ self . oneshot_cmd ( |tx| Command :: Describe { query, tx } )
318
+ . await ?
325
319
}
326
320
327
321
pub ( crate ) async fn execute (
328
322
& mut self ,
329
- query : & str ,
323
+ query : SqlStr ,
330
324
args : Option < SqliteArguments < ' _ > > ,
331
325
chan_size : usize ,
332
326
persistent : bool ,
@@ -337,7 +331,7 @@ impl ConnectionWorker {
337
331
self . command_tx
338
332
. send_async ( (
339
333
Command :: Execute {
340
- query : query . into ( ) ,
334
+ query,
341
335
arguments : args. map ( SqliteArguments :: into_static) ,
342
336
persistent,
343
337
tx,
@@ -465,9 +459,9 @@ impl ConnectionWorker {
465
459
}
466
460
}
467
461
468
- fn prepare ( conn : & mut ConnectionState , query : & str ) -> Result < SqliteStatement , Error > {
462
+ fn prepare ( conn : & mut ConnectionState , query : SqlStr ) -> Result < SqliteStatement , Error > {
469
463
// prepare statement object (or checkout from cache)
470
- let statement = conn. statements . get ( query, true ) ?;
464
+ let statement = conn. statements . get ( query. as_str ( ) , true ) ?;
471
465
472
466
let mut parameters = 0 ;
473
467
let mut columns = None ;
@@ -484,7 +478,7 @@ fn prepare(conn: &mut ConnectionState, query: &str) -> Result<SqliteStatement, E
484
478
}
485
479
486
480
Ok ( SqliteStatement {
487
- sql : AssertSqlSafe ( query) . into_sql_str ( ) ,
481
+ sql : query,
488
482
columns : columns. unwrap_or_default ( ) ,
489
483
column_names : column_names. unwrap_or_default ( ) ,
490
484
parameters,
0 commit comments