@@ -2070,3 +2070,73 @@ fn parse_print() {
20702070 let _ = ms ( ) . verified_stmt ( "PRINT N'Hello, ⛄️!'" ) ;
20712071 let _ = ms ( ) . verified_stmt ( "PRINT @my_variable" ) ;
20722072}
2073+
2074+ #[ test]
2075+ fn parse_mssql_go_keyword ( ) {
2076+ let single_go_keyword = "USE some_database;\n GO" ;
2077+ let stmts = ms ( ) . parse_sql_statements ( single_go_keyword) . unwrap ( ) ;
2078+ assert_eq ! ( stmts. len( ) , 2 ) ;
2079+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) , ) ;
2080+
2081+ let go_with_count = "SELECT 1;\n GO 5" ;
2082+ let stmts = ms ( ) . parse_sql_statements ( go_with_count) . unwrap ( ) ;
2083+ assert_eq ! ( stmts. len( ) , 2 ) ;
2084+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2085+
2086+ let bare_go = "GO" ;
2087+ let stmts = ms ( ) . parse_sql_statements ( bare_go) . unwrap ( ) ;
2088+ assert_eq ! ( stmts. len( ) , 1 ) ;
2089+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2090+
2091+ let go_then_statements = "/* whitespace */ GO\n RAISERROR('This is a test', 16, 1);" ;
2092+ let stmts = ms ( ) . parse_sql_statements ( go_then_statements) . unwrap ( ) ;
2093+ assert_eq ! ( stmts. len( ) , 2 ) ;
2094+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2095+ assert_eq ! (
2096+ stmts[ 1 ] ,
2097+ Statement :: RaisError {
2098+ message: Box :: new( Expr :: Value (
2099+ ( Value :: SingleQuotedString ( "This is a test" . to_string( ) ) ) . with_empty_span( )
2100+ ) ) ,
2101+ severity: Box :: new( Expr :: Value ( number( "16" ) . with_empty_span( ) ) ) ,
2102+ state: Box :: new( Expr :: Value ( number( "1" ) . with_empty_span( ) ) ) ,
2103+ arguments: vec![ ] ,
2104+ options: vec![ ] ,
2105+ }
2106+ ) ;
2107+
2108+ let multiple_gos = "SELECT 1;\n GO 5\n SELECT 2;\n GO" ;
2109+ let stmts = ms ( ) . parse_sql_statements ( multiple_gos) . unwrap ( ) ;
2110+ assert_eq ! ( stmts. len( ) , 4 ) ;
2111+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2112+ assert_eq ! ( stmts[ 3 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2113+
2114+ let comment_following_go = "USE some_database;\n GO -- okay" ;
2115+ let stmts = ms ( ) . parse_sql_statements ( comment_following_go) . unwrap ( ) ;
2116+ assert_eq ! ( stmts. len( ) , 2 ) ;
2117+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2118+
2119+ let actually_column_alias = "SELECT NULL AS GO" ;
2120+ let stmt = ms ( ) . verified_only_select ( actually_column_alias) ;
2121+ assert_eq ! (
2122+ only( stmt. projection) ,
2123+ SelectItem :: ExprWithAlias {
2124+ expr: Expr :: Value ( Value :: Null . with_empty_span( ) ) ,
2125+ alias: Ident :: new( "GO" ) ,
2126+ }
2127+ ) ;
2128+
2129+ let invalid_go_position = "SELECT 1; GO" ;
2130+ let err = ms ( ) . parse_sql_statements ( invalid_go_position) ;
2131+ assert_eq ! (
2132+ err. unwrap_err( ) . to_string( ) ,
2133+ "sql parser error: Expected: newline before GO, found: ;"
2134+ ) ;
2135+
2136+ let invalid_go_count = "SELECT 1\n GO x" ;
2137+ let err = ms ( ) . parse_sql_statements ( invalid_go_count) ;
2138+ assert_eq ! (
2139+ err. unwrap_err( ) . to_string( ) ,
2140+ "sql parser error: Expected: end of statement, found: x"
2141+ ) ;
2142+ }
0 commit comments