@@ -3032,6 +3032,14 @@ pub enum Statement {
30323032 partition : Option < Box < Expr > > ,
30333033 } ,
30343034 /// ```sql
3035+ /// OPEN cursor_name
3036+ /// ```
3037+ /// Opens a cursor.
3038+ Open {
3039+ /// Cursor name
3040+ cursor_name : Ident ,
3041+ } ,
3042+ /// ```sql
30353043 /// CLOSE
30363044 /// ```
30373045 /// Closes the portal underlying an open cursor.
@@ -3403,6 +3411,10 @@ pub enum Statement {
34033411 /// Cursor name
34043412 name : Ident ,
34053413 direction : FetchDirection ,
3414+ /// Differentiate between dialects that fetch `FROM` vs fetch `IN`
3415+ ///
3416+ /// [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/fetch-transact-sql)
3417+ from_or_in : AttachedToken ,
34063418 /// Optional, It's possible to fetch rows form cursor to the table
34073419 into : Option < ObjectName > ,
34083420 } ,
@@ -4225,11 +4237,25 @@ impl fmt::Display for Statement {
42254237 Statement :: Fetch {
42264238 name,
42274239 direction,
4240+ from_or_in,
42284241 into,
42294242 } => {
42304243 write ! ( f, "FETCH {direction} " ) ?;
42314244
4232- write ! ( f, "IN {name}" ) ?;
4245+ match & from_or_in. 0 . token {
4246+ Token :: Word ( w) => match w. keyword {
4247+ Keyword :: FROM => {
4248+ write ! ( f, "FROM {name}" ) ?;
4249+ }
4250+ Keyword :: IN => {
4251+ write ! ( f, "IN {name}" ) ?;
4252+ }
4253+ _ => unreachable ! ( ) ,
4254+ } ,
4255+ _ => {
4256+ unreachable ! ( )
4257+ }
4258+ }
42334259
42344260 if let Some ( into) = into {
42354261 write ! ( f, " INTO {into}" ) ?;
@@ -4488,6 +4514,11 @@ impl fmt::Display for Statement {
44884514 Ok ( ( ) )
44894515 }
44904516 Statement :: Delete ( delete) => write ! ( f, "{delete}" ) ,
4517+ Statement :: Open { cursor_name } => {
4518+ write ! ( f, "OPEN {cursor_name}" ) ?;
4519+
4520+ Ok ( ( ) )
4521+ }
44914522 Statement :: Close { cursor } => {
44924523 write ! ( f, "CLOSE {cursor}" ) ?;
44934524
0 commit comments