@@ -10,13 +10,27 @@ use std::sync::Arc;
1010pub struct AnyArguments {
1111 #[ doc( hidden) ]
1212 pub values : AnyArgumentBuffer ,
13+
14+ /// Byte offsets, into the query string being built by
15+ /// [`QueryBuilder`][crate::query_builder::QueryBuilder], of each `?` placeholder written by
16+ /// [`push_bind()`][crate::query_builder::QueryBuilder::push_bind], in the order they were
17+ /// added.
18+ ///
19+ /// This is empty unless the query was built with `QueryBuilder<Any>`; e.g. a plain
20+ /// `sqlx::query()` call with a hand-written `?` in the SQL string has no way to report
21+ /// where that `?` is, since the string is opaque to us. Backends that can't use `?`
22+ /// natively (namely Postgres) use this, when available, to rewrite placeholders precisely
23+ /// instead of re-parsing the query string.
24+ #[ doc( hidden) ]
25+ pub placeholder_offsets : Vec < usize > ,
1326}
1427
1528impl Arguments for AnyArguments {
1629 type Database = Any ;
1730
1831 fn reserve ( & mut self , additional : usize , _size : usize ) {
1932 self . values . 0 . reserve ( additional) ;
33+ self . placeholder_offsets . reserve ( additional) ;
2034 }
2135
2236 fn add < ' t , T > ( & mut self , value : T ) -> Result < ( ) , BoxDynError >
@@ -30,6 +44,10 @@ impl Arguments for AnyArguments {
3044 fn len ( & self ) -> usize {
3145 self . values . 0 . len ( )
3246 }
47+
48+ fn note_placeholder_offset ( & mut self , offset : usize ) {
49+ self . placeholder_offsets . push ( offset) ;
50+ }
3351}
3452
3553#[ derive( Default ) ]
0 commit comments