@@ -2818,6 +2818,41 @@ impl fmt::Display for RaiseStatementValue {
28182818 }
28192819}
28202820
2821+ /// A MSSQL `THROW` statement.
2822+ ///
2823+ /// ```sql
2824+ /// THROW [ error_number, message, state ]
2825+ /// ```
2826+ ///
2827+ /// [MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql)
2828+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2829+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2830+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2831+ pub struct ThrowStatement {
2832+ /// Error number expression.
2833+ pub error_number : Option < Box < Expr > > ,
2834+ /// Error message expression.
2835+ pub message : Option < Box < Expr > > ,
2836+ /// State expression.
2837+ pub state : Option < Box < Expr > > ,
2838+ }
2839+
2840+ impl fmt:: Display for ThrowStatement {
2841+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2842+ let ThrowStatement {
2843+ error_number,
2844+ message,
2845+ state,
2846+ } = self ;
2847+
2848+ write ! ( f, "THROW" ) ?;
2849+ if let ( Some ( error_number) , Some ( message) , Some ( state) ) = ( error_number, message, state) {
2850+ write ! ( f, " {error_number}, {message}, {state}" ) ?;
2851+ }
2852+ Ok ( ( ) )
2853+ }
2854+ }
2855+
28212856/// Represents an expression assignment within a variable `DECLARE` statement.
28222857///
28232858/// Examples:
@@ -4700,6 +4735,8 @@ pub enum Statement {
47004735 /// Additional `WITH` options for RAISERROR.
47014736 options : Vec < RaisErrorOption > ,
47024737 } ,
4738+ /// A MSSQL `THROW` statement.
4739+ Throw ( ThrowStatement ) ,
47034740 /// ```sql
47044741 /// PRINT msg_str | @local_variable | string_expr
47054742 /// ```
@@ -6157,6 +6194,7 @@ impl fmt::Display for Statement {
61576194 }
61586195 Ok ( ( ) )
61596196 }
6197+ Statement :: Throw ( s) => write ! ( f, "{s}" ) ,
61606198 Statement :: Print ( s) => write ! ( f, "{s}" ) ,
61616199 Statement :: Return ( r) => write ! ( f, "{r}" ) ,
61626200 Statement :: List ( command) => write ! ( f, "LIST {command}" ) ,
@@ -11687,6 +11725,12 @@ impl From<RaiseStatement> for Statement {
1168711725 }
1168811726}
1168911727
11728+ impl From < ThrowStatement > for Statement {
11729+ fn from ( t : ThrowStatement ) -> Self {
11730+ Self :: Throw ( t)
11731+ }
11732+ }
11733+
1169011734impl From < Function > for Statement {
1169111735 fn from ( f : Function ) -> Self {
1169211736 Self :: Call ( f)
0 commit comments