@@ -11532,3 +11532,91 @@ fn test_select_top() {
11532
11532
dialects. verified_stmt ( "SELECT TOP 3 DISTINCT * FROM tbl" ) ;
11533
11533
dialects. verified_stmt ( "SELECT TOP 3 DISTINCT a, b, c FROM tbl" ) ;
11534
11534
}
11535
+
11536
+ #[ test]
11537
+ fn parse_comments ( ) {
11538
+ match all_dialects_where ( |d| d. supports_comment_on ( ) )
11539
+ . verified_stmt ( "COMMENT ON COLUMN tab.name IS 'comment'" )
11540
+ {
11541
+ Statement :: Comment {
11542
+ object_type,
11543
+ object_name,
11544
+ comment : Some ( comment) ,
11545
+ if_exists,
11546
+ } => {
11547
+ assert_eq ! ( "comment" , comment) ;
11548
+ assert_eq ! ( "tab.name" , object_name. to_string( ) ) ;
11549
+ assert_eq ! ( CommentObject :: Column , object_type) ;
11550
+ assert ! ( !if_exists) ;
11551
+ }
11552
+ _ => unreachable ! ( ) ,
11553
+ }
11554
+
11555
+ let object_types = [
11556
+ ( "COLUMN" , CommentObject :: Column ) ,
11557
+ ( "EXTENSION" , CommentObject :: Extension ) ,
11558
+ ( "TABLE" , CommentObject :: Table ) ,
11559
+ ( "SCHEMA" , CommentObject :: Schema ) ,
11560
+ ( "DATABASE" , CommentObject :: Database ) ,
11561
+ ( "USER" , CommentObject :: User ) ,
11562
+ ( "ROLE" , CommentObject :: Role ) ,
11563
+ ] ;
11564
+ for ( keyword, expected_object_type) in object_types. iter ( ) {
11565
+ match all_dialects_where ( |d| d. supports_comment_on ( ) )
11566
+ . verified_stmt ( format ! ( "COMMENT IF EXISTS ON {keyword} db.t0 IS 'comment'" ) . as_str ( ) )
11567
+ {
11568
+ Statement :: Comment {
11569
+ object_type,
11570
+ object_name,
11571
+ comment : Some ( comment) ,
11572
+ if_exists,
11573
+ } => {
11574
+ assert_eq ! ( "comment" , comment) ;
11575
+ assert_eq ! ( "db.t0" , object_name. to_string( ) ) ;
11576
+ assert_eq ! ( * expected_object_type, object_type) ;
11577
+ assert ! ( if_exists) ;
11578
+ }
11579
+ _ => unreachable ! ( ) ,
11580
+ }
11581
+ }
11582
+
11583
+ match all_dialects_where ( |d| d. supports_comment_on ( ) )
11584
+ . verified_stmt ( "COMMENT IF EXISTS ON TABLE public.tab IS NULL" )
11585
+ {
11586
+ Statement :: Comment {
11587
+ object_type,
11588
+ object_name,
11589
+ comment : None ,
11590
+ if_exists,
11591
+ } => {
11592
+ assert_eq ! ( "public.tab" , object_name. to_string( ) ) ;
11593
+ assert_eq ! ( CommentObject :: Table , object_type) ;
11594
+ assert ! ( if_exists) ;
11595
+ }
11596
+ _ => unreachable ! ( ) ,
11597
+ }
11598
+
11599
+ // missing IS statement
11600
+ assert_eq ! (
11601
+ all_dialects_where( |d| d. supports_comment_on( ) )
11602
+ . parse_sql_statements( "COMMENT ON TABLE t0" )
11603
+ . unwrap_err( ) ,
11604
+ ParserError :: ParserError ( "Expected: IS, found: EOF" . to_string( ) )
11605
+ ) ;
11606
+
11607
+ // missing comment literal
11608
+ assert_eq ! (
11609
+ all_dialects_where( |d| d. supports_comment_on( ) )
11610
+ . parse_sql_statements( "COMMENT ON TABLE t0 IS" )
11611
+ . unwrap_err( ) ,
11612
+ ParserError :: ParserError ( "Expected: literal string, found: EOF" . to_string( ) )
11613
+ ) ;
11614
+
11615
+ // unknown object type
11616
+ assert_eq ! (
11617
+ all_dialects_where( |d| d. supports_comment_on( ) )
11618
+ . parse_sql_statements( "COMMENT ON UNKNOWN t0 IS 'comment'" )
11619
+ . unwrap_err( ) ,
11620
+ ParserError :: ParserError ( "Expected: comment object_type, found: UNKNOWN" . to_string( ) )
11621
+ ) ;
11622
+ }
0 commit comments