11use crate :: database:: Database ;
22use crate :: describe:: Describe ;
33use crate :: error:: { BoxDynError , Error } ;
4+ use crate :: sql_str:: { SqlSafeStr , SqlStr } ;
45
56use either:: Either ;
67use futures_core:: future:: BoxFuture ;
@@ -146,9 +147,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
146147 /// This explicit API is provided to allow access to the statement metadata available after
147148 /// it prepared but before the first row is returned.
148149 #[ inline]
149- fn prepare < ' e , ' q : ' e > (
150+ fn prepare < ' e > (
150151 self ,
151- query : & ' q str ,
152+ query : impl SqlSafeStr ,
152153 ) -> BoxFuture < ' e , Result < <Self :: Database as Database >:: Statement , Error > >
153154 where
154155 ' c : ' e ,
@@ -161,9 +162,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
161162 ///
162163 /// Only some database drivers (PostgreSQL, MSSQL) can take advantage of
163164 /// this extra information to influence parameter type inference.
164- fn prepare_with < ' e , ' q : ' e > (
165+ fn prepare_with < ' e > (
165166 self ,
166- sql : & ' q str ,
167+ sql : impl SqlSafeStr ,
167168 parameters : & ' e [ <Self :: Database as Database >:: TypeInfo ] ,
168169 ) -> BoxFuture < ' e , Result < <Self :: Database as Database >:: Statement , Error > >
169170 where
@@ -175,9 +176,9 @@ pub trait Executor<'c>: Send + Debug + Sized {
175176 /// This is used by compile-time verification in the query macros to
176177 /// power their type inference.
177178 #[ doc( hidden) ]
178- fn describe < ' e , ' q : ' e > (
179+ fn describe < ' e > (
179180 self ,
180- sql : & ' q str ,
181+ sql : impl SqlSafeStr ,
181182 ) -> BoxFuture < ' e , Result < Describe < Self :: Database > , Error > >
182183 where
183184 ' c : ' e ;
@@ -192,7 +193,7 @@ pub trait Executor<'c>: Send + Debug + Sized {
192193///
193194pub trait Execute < ' q , DB : Database > : Send + Sized {
194195 /// Gets the SQL that will be executed.
195- fn sql ( & self ) -> & ' q str ;
196+ fn sql ( self ) -> SqlStr ;
196197
197198 /// Gets the previously cached statement, if available.
198199 fn statement ( & self ) -> Option < & DB :: Statement > ;
@@ -210,12 +211,13 @@ pub trait Execute<'q, DB: Database>: Send + Sized {
210211 fn persistent ( & self ) -> bool ;
211212}
212213
213- // NOTE: `Execute` is explicitly not implemented for String and &String to make it slightly more
214- // involved to write `conn.execute(format!("SELECT {val}"))`
215- impl < ' q , DB : Database > Execute < ' q , DB > for & ' q str {
214+ impl < ' q , DB : Database , T > Execute < ' q , DB > for ( T , Option < <DB as Database >:: Arguments < ' q > > )
215+ where
216+ T : SqlSafeStr + Send ,
217+ {
216218 #[ inline]
217- fn sql ( & self ) -> & ' q str {
218- self
219+ fn sql ( self ) -> SqlStr {
220+ self . 0 . into_sql_str ( )
219221 }
220222
221223 #[ inline]
@@ -225,7 +227,7 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str {
225227
226228 #[ inline]
227229 fn take_arguments ( & mut self ) -> Result < Option < <DB as Database >:: Arguments < ' q > > , BoxDynError > {
228- Ok ( None )
230+ Ok ( self . 1 . take ( ) )
229231 }
230232
231233 #[ inline]
@@ -234,10 +236,13 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str {
234236 }
235237}
236238
237- impl < ' q , DB : Database > Execute < ' q , DB > for ( & ' q str , Option < <DB as Database >:: Arguments < ' q > > ) {
239+ impl < ' q , DB : Database , T > Execute < ' q , DB > for T
240+ where
241+ T : SqlSafeStr + Send ,
242+ {
238243 #[ inline]
239- fn sql ( & self ) -> & ' q str {
240- self . 0
244+ fn sql ( self ) -> SqlStr {
245+ self . into_sql_str ( )
241246 }
242247
243248 #[ inline]
@@ -247,7 +252,7 @@ impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<<DB as Database>::Ar
247252
248253 #[ inline]
249254 fn take_arguments ( & mut self ) -> Result < Option < <DB as Database >:: Arguments < ' q > > , BoxDynError > {
250- Ok ( self . 1 . take ( ) )
255+ Ok ( None )
251256 }
252257
253258 #[ inline]
0 commit comments