@@ -37,7 +37,7 @@ use serde::{Deserialize, Serialize};
37
37
#[ cfg( feature = "visitor" ) ]
38
38
use sqlparser_derive:: { Visit , VisitMut } ;
39
39
40
- use crate :: tokenizer:: Span ;
40
+ use crate :: { keywords :: Keyword , tokenizer:: Span } ;
41
41
42
42
pub use self :: data_type:: {
43
43
ArrayElemTypeDef , BinaryLength , CharLengthUnits , CharacterLength , DataType , EnumMember ,
@@ -2942,7 +2942,7 @@ pub enum Statement {
2942
2942
/// least MySQL and PostgreSQL. Not all MySQL-specific syntactic forms are
2943
2943
/// supported yet.
2944
2944
SetVariable {
2945
- local : bool ,
2945
+ scope : ContextModifier ,
2946
2946
hivevar : bool ,
2947
2947
variables : OneOrManyWithParens < ObjectName > ,
2948
2948
value : Vec < Expr > ,
@@ -4649,22 +4649,19 @@ impl fmt::Display for Statement {
4649
4649
role_name,
4650
4650
} => {
4651
4651
let role_name = role_name. clone ( ) . unwrap_or_else ( || Ident :: new ( "NONE" ) ) ;
4652
- write ! ( f, "SET{context_modifier} ROLE {role_name}" )
4652
+ write ! ( f, "SET {context_modifier}ROLE {role_name}" , )
4653
4653
}
4654
4654
Statement :: SetVariable {
4655
- local ,
4655
+ scope ,
4656
4656
variables,
4657
4657
hivevar,
4658
4658
value,
4659
4659
} => {
4660
4660
f. write_str ( "SET " ) ?;
4661
- if * local {
4662
- f. write_str ( "LOCAL " ) ?;
4663
- }
4664
4661
let parenthesized = matches ! ( variables, OneOrManyWithParens :: Many ( _) ) ;
4665
4662
write ! (
4666
4663
f,
4667
- "{hivevar}{name} = {l_paren}{value}{r_paren}" ,
4664
+ "{scope}{ hivevar}{name} = {l_paren}{value}{r_paren}" ,
4668
4665
hivevar = if * hivevar { "HIVEVAR:" } else { "" } ,
4669
4666
name = variables,
4670
4667
l_paren = parenthesized. then_some( "(" ) . unwrap_or_default( ) ,
@@ -7624,6 +7621,8 @@ pub enum ContextModifier {
7624
7621
Local ,
7625
7622
/// `SESSION` identifier
7626
7623
Session ,
7624
+ /// `GLOBAL` identifier
7625
+ Global ,
7627
7626
}
7628
7627
7629
7628
impl fmt:: Display for ContextModifier {
@@ -7633,15 +7632,32 @@ impl fmt::Display for ContextModifier {
7633
7632
write ! ( f, "" )
7634
7633
}
7635
7634
Self :: Local => {
7636
- write ! ( f, " LOCAL" )
7635
+ write ! ( f, "LOCAL " )
7637
7636
}
7638
7637
Self :: Session => {
7639
- write ! ( f, " SESSION" )
7638
+ write ! ( f, "SESSION " )
7639
+ }
7640
+ Self :: Global => {
7641
+ write ! ( f, "GLOBAL " )
7640
7642
}
7641
7643
}
7642
7644
}
7643
7645
}
7644
7646
7647
+ impl From < Option < Keyword > > for ContextModifier {
7648
+ fn from ( kw : Option < Keyword > ) -> Self {
7649
+ match kw {
7650
+ Some ( kw) => match kw {
7651
+ Keyword :: LOCAL => Self :: Local ,
7652
+ Keyword :: SESSION => Self :: Session ,
7653
+ Keyword :: GLOBAL => Self :: Global ,
7654
+ _ => Self :: None ,
7655
+ } ,
7656
+ None => Self :: None ,
7657
+ }
7658
+ }
7659
+ }
7660
+
7645
7661
/// Function describe in DROP FUNCTION.
7646
7662
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7647
7663
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments