@@ -2156,3 +2156,73 @@ fn parse_print() {
21562156 let _ = ms ( ) . verified_stmt ( "PRINT N'Hello, ⛄️!'" ) ;
21572157 let _ = ms ( ) . verified_stmt ( "PRINT @my_variable" ) ;
21582158}
2159+
2160+ #[ test]
2161+ fn parse_mssql_go_keyword ( ) {
2162+ let single_go_keyword = "USE some_database;\n GO" ;
2163+ let stmts = ms ( ) . parse_sql_statements ( single_go_keyword) . unwrap ( ) ;
2164+ assert_eq ! ( stmts. len( ) , 2 ) ;
2165+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) , ) ;
2166+
2167+ let go_with_count = "SELECT 1;\n GO 5" ;
2168+ let stmts = ms ( ) . parse_sql_statements ( go_with_count) . unwrap ( ) ;
2169+ assert_eq ! ( stmts. len( ) , 2 ) ;
2170+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2171+
2172+ let bare_go = "GO" ;
2173+ let stmts = ms ( ) . parse_sql_statements ( bare_go) . unwrap ( ) ;
2174+ assert_eq ! ( stmts. len( ) , 1 ) ;
2175+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2176+
2177+ let go_then_statements = "/* whitespace */ GO\n RAISERROR('This is a test', 16, 1);" ;
2178+ let stmts = ms ( ) . parse_sql_statements ( go_then_statements) . unwrap ( ) ;
2179+ assert_eq ! ( stmts. len( ) , 2 ) ;
2180+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2181+ assert_eq ! (
2182+ stmts[ 1 ] ,
2183+ Statement :: RaisError {
2184+ message: Box :: new( Expr :: Value (
2185+ ( Value :: SingleQuotedString ( "This is a test" . to_string( ) ) ) . with_empty_span( )
2186+ ) ) ,
2187+ severity: Box :: new( Expr :: Value ( number( "16" ) . with_empty_span( ) ) ) ,
2188+ state: Box :: new( Expr :: Value ( number( "1" ) . with_empty_span( ) ) ) ,
2189+ arguments: vec![ ] ,
2190+ options: vec![ ] ,
2191+ }
2192+ ) ;
2193+
2194+ let multiple_gos = "SELECT 1;\n GO 5\n SELECT 2;\n GO" ;
2195+ let stmts = ms ( ) . parse_sql_statements ( multiple_gos) . unwrap ( ) ;
2196+ assert_eq ! ( stmts. len( ) , 4 ) ;
2197+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2198+ assert_eq ! ( stmts[ 3 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2199+
2200+ let comment_following_go = "USE some_database;\n GO -- okay" ;
2201+ let stmts = ms ( ) . parse_sql_statements ( comment_following_go) . unwrap ( ) ;
2202+ assert_eq ! ( stmts. len( ) , 2 ) ;
2203+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2204+
2205+ let actually_column_alias = "SELECT NULL AS GO" ;
2206+ let stmt = ms ( ) . verified_only_select ( actually_column_alias) ;
2207+ assert_eq ! (
2208+ only( stmt. projection) ,
2209+ SelectItem :: ExprWithAlias {
2210+ expr: Expr :: Value ( Value :: Null . with_empty_span( ) ) ,
2211+ alias: Ident :: new( "GO" ) ,
2212+ }
2213+ ) ;
2214+
2215+ let invalid_go_position = "SELECT 1; GO" ;
2216+ let err = ms ( ) . parse_sql_statements ( invalid_go_position) ;
2217+ assert_eq ! (
2218+ err. unwrap_err( ) . to_string( ) ,
2219+ "sql parser error: Expected: newline before GO, found: ;"
2220+ ) ;
2221+
2222+ let invalid_go_count = "SELECT 1\n GO x" ;
2223+ let err = ms ( ) . parse_sql_statements ( invalid_go_count) ;
2224+ assert_eq ! (
2225+ err. unwrap_err( ) . to_string( ) ,
2226+ "sql parser error: Expected: end of statement, found: x"
2227+ ) ;
2228+ }
0 commit comments