@@ -72,7 +72,7 @@ pub fn stream_query_results_with_conn<'a>(
7272 }
7373 } ,
7474 ParsedStatement :: SetVariable { variable, value} => {
75- execute_set_variable_query( db_connection, request, variable, value) . await
75+ execute_set_variable_query( db_connection, request, variable, value, source_file ) . await
7676 . with_context( ||
7777 format!( "Failed to set the {variable} variable to {value:?}" )
7878 ) ?;
@@ -153,19 +153,27 @@ async fn execute_set_variable_query<'a>(
153153 request : & ' a mut RequestInfo ,
154154 variable : & StmtParam ,
155155 statement : & StmtWithParams ,
156+ source_file : & Path ,
156157) -> anyhow:: Result < ( ) > {
157158 let query = bind_parameters ( statement, request, db_connection) . await ?;
158159 let connection = take_connection ( & request. app_state . db , db_connection) . await ?;
159160 log:: debug!(
160161 "Executing query to set the {variable:?} variable: {:?}" ,
161162 query. sql
162163 ) ;
163- let value: Option < String > = connection
164- . fetch_optional ( query)
165- . await ?
166- . as_ref ( )
167- . and_then ( row_to_string) ;
164+
165+ let value = match connection. fetch_optional ( query) . await {
166+ Ok ( Some ( row) ) => row_to_string ( & row) ,
167+ Ok ( None ) => None ,
168+ Err ( e) => {
169+ let err = display_db_error ( source_file, & statement. query , e) ;
170+ log:: error!( "{err}" ) ;
171+ return Err ( err) ;
172+ }
173+ } ;
174+
168175 let ( vars, name) = vars_and_name ( request, variable) ?;
176+
169177 if let Some ( value) = value {
170178 log:: debug!( "Setting variable {name} to {value:?}" ) ;
171179 vars. insert ( name. to_owned ( ) , SingleOrVec :: Single ( value) ) ;
0 commit comments