@@ -2776,33 +2776,23 @@ pub enum Statement {
2776
2776
ShowColumns {
2777
2777
extended : bool ,
2778
2778
full : bool ,
2779
- show_in : Option < ShowStatementIn > ,
2780
- filter : Option < ShowStatementFilter > ,
2781
- filter_position : ShowStatementFilterPosition ,
2779
+ show_options : ShowStatementOptions ,
2782
2780
} ,
2783
2781
/// ```sql
2784
2782
/// SHOW DATABASES
2785
2783
/// ```
2786
2784
ShowDatabases {
2787
2785
terse : bool ,
2788
2786
history : bool ,
2789
- filter : Option < ShowStatementFilter > ,
2790
- show_in : Option < ShowStatementIn > ,
2791
- starts_with : Option < Value > ,
2792
- limit : Option < Expr > ,
2793
- from : Option < Value > ,
2787
+ show_options : ShowStatementOptions ,
2794
2788
} ,
2795
2789
/// ```sql
2796
2790
/// SHOW SCHEMAS
2797
2791
/// ```
2798
2792
ShowSchemas {
2799
2793
terse : bool ,
2800
2794
history : bool ,
2801
- filter : Option < ShowStatementFilter > ,
2802
- show_in : Option < ShowStatementIn > ,
2803
- starts_with : Option < Value > ,
2804
- limit : Option < Expr > ,
2805
- from : Option < Value > ,
2795
+ show_options : ShowStatementOptions ,
2806
2796
} ,
2807
2797
/// ```sql
2808
2798
/// SHOW TABLES
@@ -2813,25 +2803,15 @@ pub enum Statement {
2813
2803
extended : bool ,
2814
2804
full : bool ,
2815
2805
external : bool ,
2816
- filter : Option < ShowStatementFilter > ,
2817
- show_in : Option < ShowStatementIn > ,
2818
- starts_with : Option < Value > ,
2819
- limit : Option < Expr > ,
2820
- from : Option < Value > ,
2821
- filter_position : ShowStatementFilterPosition ,
2806
+ show_options : ShowStatementOptions ,
2822
2807
} ,
2823
2808
/// ```sql
2824
2809
/// SHOW VIEWS
2825
2810
/// ```
2826
2811
ShowViews {
2827
2812
terse : bool ,
2828
2813
materialized : bool ,
2829
- filter : Option < ShowStatementFilter > ,
2830
- show_in : Option < ShowStatementIn > ,
2831
- starts_with : Option < Value > ,
2832
- limit : Option < Expr > ,
2833
- from : Option < Value > ,
2834
- filter_position : ShowStatementFilterPosition ,
2814
+ show_options : ShowStatementOptions ,
2835
2815
} ,
2836
2816
/// ```sql
2837
2817
/// SHOW COLLATION
@@ -4411,113 +4391,39 @@ impl fmt::Display for Statement {
4411
4391
Statement :: ShowColumns {
4412
4392
extended,
4413
4393
full,
4414
- show_in,
4415
- filter,
4416
- filter_position,
4394
+ show_options,
4417
4395
} => {
4418
4396
write ! (
4419
4397
f,
4420
- "SHOW {extended}{full}COLUMNS" ,
4398
+ "SHOW {extended}{full}COLUMNS{show_options} " ,
4421
4399
extended = if * extended { "EXTENDED " } else { "" } ,
4422
4400
full = if * full { "FULL " } else { "" } ,
4423
4401
) ?;
4424
- if filter_position == & ShowStatementFilterPosition :: InTheMiddle {
4425
- if let Some ( filter) = filter {
4426
- write ! ( f, " {filter}" ) ?;
4427
- }
4428
- if let Some ( show_in) = show_in {
4429
- write ! ( f, " {show_in}" ) ?;
4430
- }
4431
- }
4432
- if filter_position == & ShowStatementFilterPosition :: AtTheEnd {
4433
- if let Some ( show_in) = show_in {
4434
- write ! ( f, " {show_in}" ) ?;
4435
- }
4436
- if let Some ( filter) = filter {
4437
- write ! ( f, " {filter}" ) ?;
4438
- }
4439
- }
4440
4402
Ok ( ( ) )
4441
4403
}
4442
4404
Statement :: ShowDatabases {
4443
4405
terse,
4444
4406
history,
4445
- filter,
4446
- show_in,
4447
- starts_with,
4448
- limit,
4449
- from,
4407
+ show_options,
4450
4408
} => {
4451
4409
write ! (
4452
4410
f,
4453
- "SHOW {terse}DATABASES" ,
4454
- terse = if * terse { "TERSE " } else { "" }
4455
- ) ?;
4456
- write ! (
4457
- f,
4458
- "{history}{filter}{show_in}{starts_with}{limit}{from}" ,
4411
+ "SHOW {terse}DATABASES{history}{show_options}" ,
4412
+ terse = if * terse { "TERSE " } else { "" } ,
4459
4413
history = if * history { " HISTORY" } else { "" } ,
4460
- filter = match filter. as_ref( ) {
4461
- Some ( l) => format!( " {l}" ) ,
4462
- None => String :: new( ) ,
4463
- } ,
4464
- show_in = match show_in {
4465
- Some ( i) => format!( " {i}" ) ,
4466
- None => String :: new( ) ,
4467
- } ,
4468
- starts_with = match starts_with. as_ref( ) {
4469
- Some ( s) => format!( " STARTS WITH {s}" ) ,
4470
- None => String :: new( ) ,
4471
- } ,
4472
- limit = match limit. as_ref( ) {
4473
- Some ( l) => format!( " LIMIT {l}" ) ,
4474
- None => String :: new( ) ,
4475
- } ,
4476
- from = match from. as_ref( ) {
4477
- Some ( f) => format!( " FROM {f}" ) ,
4478
- None => String :: new( ) ,
4479
- }
4480
4414
) ?;
4481
4415
Ok ( ( ) )
4482
4416
}
4483
4417
Statement :: ShowSchemas {
4484
4418
terse,
4485
4419
history,
4486
- filter,
4487
- show_in,
4488
- starts_with,
4489
- limit,
4490
- from,
4420
+ show_options,
4491
4421
} => {
4492
4422
write ! (
4493
4423
f,
4494
- "SHOW {terse}SCHEMAS" ,
4495
- terse = if * terse { "TERSE " } else { "" }
4496
- ) ?;
4497
- write ! (
4498
- f,
4499
- "{history}{filter}{show_in}{starts_with}{limit}{from}" ,
4424
+ "SHOW {terse}SCHEMAS{history}{show_options}" ,
4425
+ terse = if * terse { "TERSE " } else { "" } ,
4500
4426
history = if * history { " HISTORY" } else { "" } ,
4501
- filter = match filter. as_ref( ) {
4502
- Some ( l) => format!( " {l}" ) ,
4503
- None => String :: new( ) ,
4504
- } ,
4505
- show_in = match show_in {
4506
- Some ( i) => format!( " {i}" ) ,
4507
- None => String :: new( ) ,
4508
- } ,
4509
- starts_with = match starts_with. as_ref( ) {
4510
- Some ( s) => format!( " STARTS WITH {s}" ) ,
4511
- None => String :: new( ) ,
4512
- } ,
4513
- limit = match limit. as_ref( ) {
4514
- Some ( l) => format!( " LIMIT {l}" ) ,
4515
- None => String :: new( ) ,
4516
- } ,
4517
- from = match from. as_ref( ) {
4518
- Some ( f) => format!( " FROM {f}" ) ,
4519
- None => String :: new( ) ,
4520
- }
4521
4427
) ?;
4522
4428
Ok ( ( ) )
4523
4429
}
@@ -4527,110 +4433,30 @@ impl fmt::Display for Statement {
4527
4433
extended,
4528
4434
full,
4529
4435
external,
4530
- filter,
4531
- show_in,
4532
- starts_with,
4533
- limit,
4534
- from,
4535
- filter_position,
4436
+ show_options,
4536
4437
} => {
4537
4438
write ! (
4538
4439
f,
4539
- "SHOW {terse}{extended}{full}{external}TABLES" ,
4440
+ "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options} " ,
4540
4441
terse = if * terse { "TERSE " } else { "" } ,
4541
4442
extended = if * extended { "EXTENDED " } else { "" } ,
4542
4443
full = if * full { "FULL " } else { "" } ,
4543
4444
external = if * external { "EXTERNAL " } else { "" } ,
4544
- ) ?;
4545
- write ! (
4546
- f,
4547
- "{history}{like_in_the_middle}{show_in}{starts_with}{limit}{from}{like_at_the_end}" ,
4548
4445
history = if * history { " HISTORY" } else { "" } ,
4549
- like_in_the_middle = if * filter_position
4550
- == ShowStatementFilterPosition :: InTheMiddle
4551
- && filter. is_some( )
4552
- {
4553
- format!( " {}" , filter. as_ref( ) . unwrap( ) )
4554
- } else {
4555
- String :: new( )
4556
- } ,
4557
- show_in = match show_in {
4558
- Some ( i) => format!( " {i}" ) ,
4559
- None => String :: new( ) ,
4560
- } ,
4561
- starts_with = match starts_with. as_ref( ) {
4562
- Some ( s) => format!( " STARTS WITH {s}" ) ,
4563
- None => String :: new( ) ,
4564
- } ,
4565
- limit = match limit. as_ref( ) {
4566
- Some ( l) => format!( " LIMIT {l}" ) ,
4567
- None => String :: new( ) ,
4568
- } ,
4569
- from = match from. as_ref( ) {
4570
- Some ( f) => format!( " FROM {f}" ) ,
4571
- None => String :: new( ) ,
4572
- } ,
4573
- like_at_the_end = if * filter_position
4574
- == ShowStatementFilterPosition :: AtTheEnd
4575
- && filter. is_some( )
4576
- {
4577
- format!( " {}" , filter. as_ref( ) . unwrap( ) )
4578
- } else {
4579
- String :: new( )
4580
- } ,
4581
- )
4446
+ ) ?;
4447
+ Ok ( ( ) )
4582
4448
}
4583
4449
Statement :: ShowViews {
4584
4450
terse,
4585
4451
materialized,
4586
- filter,
4587
- show_in,
4588
- starts_with,
4589
- limit,
4590
- from,
4591
- filter_position,
4452
+ show_options,
4592
4453
} => {
4593
4454
write ! (
4594
4455
f,
4595
- "SHOW {terse}{materialized}VIEWS" ,
4456
+ "SHOW {terse}{materialized}VIEWS{show_options} " ,
4596
4457
terse = if * terse { "TERSE " } else { "" } ,
4597
4458
materialized = if * materialized { "MATERIALIZED " } else { "" }
4598
4459
) ?;
4599
- write ! (
4600
- f,
4601
- "{like_in_the_middle}{show_in}{starts_with}{limit}{from}{like_at_the_end}" ,
4602
- like_in_the_middle = if * filter_position
4603
- == ShowStatementFilterPosition :: InTheMiddle
4604
- && filter. is_some( )
4605
- {
4606
- format!( " {}" , filter. as_ref( ) . unwrap( ) )
4607
- } else {
4608
- String :: new( )
4609
- } ,
4610
- show_in = match show_in {
4611
- Some ( i) => format!( " {i}" ) ,
4612
- None => String :: new( ) ,
4613
- } ,
4614
- starts_with = match starts_with. as_ref( ) {
4615
- Some ( s) => format!( " STARTS WITH {s}" ) ,
4616
- None => String :: new( ) ,
4617
- } ,
4618
- limit = match limit. as_ref( ) {
4619
- Some ( l) => format!( " LIMIT {l}" ) ,
4620
- None => String :: new( ) ,
4621
- } ,
4622
- from = match from. as_ref( ) {
4623
- Some ( f) => format!( " FROM {f}" ) ,
4624
- None => String :: new( ) ,
4625
- } ,
4626
- like_at_the_end = if * filter_position == ShowStatementFilterPosition :: AtTheEnd
4627
- && filter. is_some( )
4628
- {
4629
- format!( " {}" , filter. as_ref( ) . unwrap( ) )
4630
- } else {
4631
- String :: new( )
4632
- }
4633
- ) ?;
4634
4460
Ok ( ( ) )
4635
4461
}
4636
4462
Statement :: ShowFunctions { filter } => {
@@ -7528,10 +7354,54 @@ impl Display for UtilityOption {
7528
7354
}
7529
7355
}
7530
7356
7357
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7358
+ pub struct ShowStatementOptions {
7359
+ pub show_in : Option < ShowStatementIn > ,
7360
+ pub starts_with : Option < Value > ,
7361
+ pub limit : Option < Expr > ,
7362
+ pub limit_from : Option < Value > ,
7363
+ pub filter_position : Option < ShowStatementFilterPosition > ,
7364
+ }
7365
+
7366
+ impl Display for ShowStatementOptions {
7367
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7368
+ let ( life_in_infix, like_in_suffix) = match & self . filter_position {
7369
+ Some ( ShowStatementFilterPosition :: Infix ( filter) ) => {
7370
+ ( format ! ( " {filter}" ) , "" . to_string ( ) )
7371
+ }
7372
+ Some ( ShowStatementFilterPosition :: Suffix ( filter) ) => {
7373
+ ( "" . to_string ( ) , format ! ( " {filter}" ) )
7374
+ }
7375
+ None => ( "" . to_string ( ) , "" . to_string ( ) ) ,
7376
+ } ;
7377
+ write ! (
7378
+ f,
7379
+ "{life_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}" ,
7380
+ show_in = match & self . show_in {
7381
+ Some ( i) => format!( " {i}" ) ,
7382
+ None => String :: new( ) ,
7383
+ } ,
7384
+ starts_with = match & self . starts_with {
7385
+ Some ( s) => format!( " STARTS WITH {s}" ) ,
7386
+ None => String :: new( ) ,
7387
+ } ,
7388
+ limit = match & self . limit {
7389
+ Some ( l) => format!( " LIMIT {l}" ) ,
7390
+ None => String :: new( ) ,
7391
+ } ,
7392
+ from = match & self . limit_from {
7393
+ Some ( f) => format!( " FROM {f}" ) ,
7394
+ None => String :: new( ) ,
7395
+ }
7396
+ ) ?;
7397
+ Ok ( ( ) )
7398
+ }
7399
+ }
7400
+
7531
7401
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7532
7402
pub enum ShowStatementFilterPosition {
7533
- InTheMiddle , // Snowflake like
7534
- AtTheEnd , // MySQL like
7403
+ Infix ( ShowStatementFilter ) , // For example: SHOW COLUMNS LIKE '%name%' IN TABLE tbl
7404
+ Suffix ( ShowStatementFilter ) , // For example: SHOW COLUMNS IN tbl LIKE '%name%'
7535
7405
}
7536
7406
7537
7407
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
0 commit comments