@@ -2,7 +2,8 @@ use super::AuroraConnection;
2
2
use crate :: aurora:: error:: AuroraDatabaseError ;
3
3
use crate :: aurora:: statement:: AuroraStatementMetadata ;
4
4
use crate :: aurora:: {
5
- Aurora , AuroraArguments , AuroraColumn , AuroraDone , AuroraRow , AuroraStatement , AuroraTypeInfo ,
5
+ Aurora , AuroraArguments , AuroraColumn , AuroraDbType , AuroraDone , AuroraRow , AuroraStatement ,
6
+ AuroraTypeInfo ,
6
7
} ;
7
8
use crate :: describe:: Describe ;
8
9
use crate :: error:: Error ;
@@ -16,6 +17,8 @@ use futures_core::stream::BoxStream;
16
17
use futures_core:: Stream ;
17
18
use futures_util:: stream;
18
19
use futures_util:: { pin_mut, TryStreamExt } ;
20
+ use once_cell:: sync:: Lazy ;
21
+ use regex:: Regex ;
19
22
use rusoto_rds_data:: { ExecuteStatementRequest , ExecuteStatementResponse , RdsData } ;
20
23
use std:: borrow:: Cow ;
21
24
use std:: sync:: Arc ;
@@ -24,15 +27,41 @@ impl AuroraConnection {
24
27
async fn run < ' e , ' c : ' e , ' q : ' e > (
25
28
& ' c mut self ,
26
29
query : & ' q str ,
27
- arguments : Option < AuroraArguments > ,
30
+ mut arguments : Option < AuroraArguments > ,
28
31
) -> Result < impl Stream < Item = Result < Either < AuroraDone , AuroraRow > , Error > > + ' e , Error > {
29
32
let mut logger = QueryLogger :: new ( query, self . log_settings . clone ( ) ) ;
30
33
34
+ static MYSQL_PARAMS_RE : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"\?" ) . unwrap ( ) ) ;
35
+ static POSTGRES_PARAMS_RE : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"\$\d+" ) . unwrap ( ) ) ;
36
+
37
+ let regex = match self . db_type {
38
+ AuroraDbType :: MySQL => & MYSQL_PARAMS_RE ,
39
+ AuroraDbType :: Postgres => & POSTGRES_PARAMS_RE ,
40
+ } ;
41
+
42
+ let mut owned_query = query. to_owned ( ) ;
43
+
44
+ if let Some ( arguments) = arguments. as_mut ( ) {
45
+ regex
46
+ . find_iter ( query)
47
+ . zip ( arguments. parameters . iter_mut ( ) )
48
+ . enumerate ( )
49
+ . for_each ( |( idx, ( mat, param) ) | {
50
+ let name = format ! ( "param_{}" , idx + 1 ) ;
51
+
52
+ owned_query. replace_range ( mat. start ( ) ..mat. end ( ) , & format ! ( ":{}" , name) ) ;
53
+
54
+ param. name = Some ( name) ;
55
+ } ) ;
56
+ }
57
+
58
+ dbg ! ( & owned_query) ;
59
+
31
60
// TODO: is this correct?
32
61
let transaction_id = self . transaction_ids . last ( ) . cloned ( ) ;
33
62
34
63
let request = ExecuteStatementRequest {
35
- sql : query . to_owned ( ) ,
64
+ sql : owned_query ,
36
65
parameters : arguments. map ( |m| m. parameters ) ,
37
66
resource_arn : self . resource_arn . clone ( ) ,
38
67
secret_arn : self . secret_arn . clone ( ) ,
0 commit comments