@@ -2053,3 +2053,73 @@ fn parse_drop_trigger() {
20532053 }
20542054 ) ;
20552055}
2056+
2057+ #[ test]
2058+ fn parse_mssql_go_keyword ( ) {
2059+ let single_go_keyword = "USE some_database;\n GO" ;
2060+ let stmts = ms ( ) . parse_sql_statements ( single_go_keyword) . unwrap ( ) ;
2061+ assert_eq ! ( stmts. len( ) , 2 ) ;
2062+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) , ) ;
2063+
2064+ let go_with_count = "SELECT 1;\n GO 5" ;
2065+ let stmts = ms ( ) . parse_sql_statements ( go_with_count) . unwrap ( ) ;
2066+ assert_eq ! ( stmts. len( ) , 2 ) ;
2067+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2068+
2069+ let bare_go = "GO" ;
2070+ let stmts = ms ( ) . parse_sql_statements ( bare_go) . unwrap ( ) ;
2071+ assert_eq ! ( stmts. len( ) , 1 ) ;
2072+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2073+
2074+ let go_then_statements = "/* whitespace */ GO\n RAISERROR('This is a test', 16, 1);" ;
2075+ let stmts = ms ( ) . parse_sql_statements ( go_then_statements) . unwrap ( ) ;
2076+ assert_eq ! ( stmts. len( ) , 2 ) ;
2077+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2078+ assert_eq ! (
2079+ stmts[ 1 ] ,
2080+ Statement :: RaisError {
2081+ message: Box :: new( Expr :: Value (
2082+ ( Value :: SingleQuotedString ( "This is a test" . to_string( ) ) ) . with_empty_span( )
2083+ ) ) ,
2084+ severity: Box :: new( Expr :: Value ( number( "16" ) . with_empty_span( ) ) ) ,
2085+ state: Box :: new( Expr :: Value ( number( "1" ) . with_empty_span( ) ) ) ,
2086+ arguments: vec![ ] ,
2087+ options: vec![ ] ,
2088+ }
2089+ ) ;
2090+
2091+ let multiple_gos = "SELECT 1;\n GO 5\n SELECT 2;\n GO" ;
2092+ let stmts = ms ( ) . parse_sql_statements ( multiple_gos) . unwrap ( ) ;
2093+ assert_eq ! ( stmts. len( ) , 4 ) ;
2094+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2095+ assert_eq ! ( stmts[ 3 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2096+
2097+ let comment_following_go = "USE some_database;\n GO -- okay" ;
2098+ let stmts = ms ( ) . parse_sql_statements ( comment_following_go) . unwrap ( ) ;
2099+ assert_eq ! ( stmts. len( ) , 2 ) ;
2100+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2101+
2102+ let actually_column_alias = "SELECT NULL AS GO" ;
2103+ let stmt = ms ( ) . verified_only_select ( actually_column_alias) ;
2104+ assert_eq ! (
2105+ only( stmt. projection) ,
2106+ SelectItem :: ExprWithAlias {
2107+ expr: Expr :: Value ( Value :: Null . with_empty_span( ) ) ,
2108+ alias: Ident :: new( "GO" ) ,
2109+ }
2110+ ) ;
2111+
2112+ let invalid_go_position = "SELECT 1; GO" ;
2113+ let err = ms ( ) . parse_sql_statements ( invalid_go_position) ;
2114+ assert_eq ! (
2115+ err. unwrap_err( ) . to_string( ) ,
2116+ "sql parser error: Expected: newline before GO, found: ;"
2117+ ) ;
2118+
2119+ let invalid_go_count = "SELECT 1\n GO x" ;
2120+ let err = ms ( ) . parse_sql_statements ( invalid_go_count) ;
2121+ assert_eq ! (
2122+ err. unwrap_err( ) . to_string( ) ,
2123+ "sql parser error: Expected: end of statement, found: x"
2124+ ) ;
2125+ }
0 commit comments