LucaCappelletti94 commented on code in PR #2451:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2451#discussion_r4111570982


##########
src/parser/mod.rs:
##########
@@ -8159,6 +8165,21 @@ impl<'a> Parser<'a> {
         })
     }
 
+    fn parse_mssql_cursor_options(&mut self) -> Vec<MsSqlCursorOption> {
+        let mut options = vec![];
+
+        match self.parse_one_of_keywords(&[Keyword::LOCAL, Keyword::GLOBAL]) {
+            Some(Keyword::LOCAL) => options.push(MsSqlCursorOption::Local),
+            Some(Keyword::GLOBAL) => options.push(MsSqlCursorOption::Global),
+            _ => {}
+        }
+        if self.parse_keyword(Keyword::FAST_FORWARD) {
+            options.push(MsSqlCursorOption::FastForward);
+        }
+
+        options

Review Comment:
   You should accept the options in any order. SQL Server 2022 runs `DECLARE c 
CURSOR FAST_FORWARD LOCAL FOR SELECT name FROM sys.objects`, while this branch 
fails with `Expected: end of statement, found: LOCAL`. The `Vec` already keeps 
source order, so the round trip holds.
   
   ```suggestion
           let mut options = vec![];
   
           loop {
               options.push(
                   match self.parse_one_of_keywords(&[
                       Keyword::LOCAL,
                       Keyword::GLOBAL,
                       Keyword::FAST_FORWARD,
                   ]) {
                       Some(Keyword::LOCAL) => MsSqlCursorOption::Local,
                       Some(Keyword::GLOBAL) => MsSqlCursorOption::Global,
                       Some(Keyword::FAST_FORWARD) => 
MsSqlCursorOption::FastForward,
                       _ => return options,
                   },
               );
           }
   ```



##########
tests/sqlparser_mssql.rs:
##########
@@ -2941,3 +2945,33 @@ fn parse_bracket_quoted_function_argument_name() {
         }])
     );
 }
+
+#[test]
+fn parse_mssql_cursor_options() {
+    for (sql, expected_options) in [
+        (
+            "DECLARE local_cursor CURSOR LOCAL FOR SELECT name FROM 
dbo.reports",
+            vec![MsSqlCursorOption::Local],
+        ),
+        (
+            "DECLARE fast_cursor CURSOR FAST_FORWARD FOR SELECT name FROM 
dbo.reports",
+            vec![MsSqlCursorOption::FastForward],
+        ),
+        (
+            "DECLARE global_cursor CURSOR GLOBAL FAST_FORWARD FOR SELECT name 
FROM dbo.reports",
+            vec![MsSqlCursorOption::Global, MsSqlCursorOption::FastForward],
+        ),

Review Comment:
   Red test for the aforementioned case
   
   ```suggestion
           ),
           (
               "DECLARE local_cursor CURSOR FAST_FORWARD LOCAL FOR SELECT name 
FROM dbo.reports",
               vec![MsSqlCursorOption::FastForward, MsSqlCursorOption::Local],
           ),
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to