@@ -37,7 +37,7 @@ use serde::{Deserialize, Serialize};
3737#[ cfg( feature = "visitor" ) ]
3838use sqlparser_derive:: { Visit , VisitMut } ;
3939
40- use crate :: tokenizer:: Span ;
40+ use crate :: { keywords :: Keyword , tokenizer:: Span } ;
4141
4242pub use self :: data_type:: {
4343 ArrayElemTypeDef , BinaryLength , CharLengthUnits , CharacterLength , DataType , EnumMember ,
@@ -2942,7 +2942,7 @@ pub enum Statement {
29422942 /// least MySQL and PostgreSQL. Not all MySQL-specific syntactic forms are
29432943 /// supported yet.
29442944 SetVariable {
2945- local : bool ,
2945+ scope : ContextModifier ,
29462946 hivevar : bool ,
29472947 variables : OneOrManyWithParens < ObjectName > ,
29482948 value : Vec < Expr > ,
@@ -4649,22 +4649,19 @@ impl fmt::Display for Statement {
46494649 role_name,
46504650 } => {
46514651 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}" , )
46534653 }
46544654 Statement :: SetVariable {
4655- local ,
4655+ scope ,
46564656 variables,
46574657 hivevar,
46584658 value,
46594659 } => {
46604660 f. write_str ( "SET " ) ?;
4661- if * local {
4662- f. write_str ( "LOCAL " ) ?;
4663- }
46644661 let parenthesized = matches ! ( variables, OneOrManyWithParens :: Many ( _) ) ;
46654662 write ! (
46664663 f,
4667- "{hivevar}{name} = {l_paren}{value}{r_paren}" ,
4664+ "{scope}{ hivevar}{name} = {l_paren}{value}{r_paren}" ,
46684665 hivevar = if * hivevar { "HIVEVAR:" } else { "" } ,
46694666 name = variables,
46704667 l_paren = parenthesized. then_some( "(" ) . unwrap_or_default( ) ,
@@ -7624,6 +7621,8 @@ pub enum ContextModifier {
76247621 Local ,
76257622 /// `SESSION` identifier
76267623 Session ,
7624+ /// `GLOBAL` identifier
7625+ Global ,
76277626}
76287627
76297628impl fmt:: Display for ContextModifier {
@@ -7633,15 +7632,32 @@ impl fmt::Display for ContextModifier {
76337632 write ! ( f, "" )
76347633 }
76357634 Self :: Local => {
7636- write ! ( f, " LOCAL" )
7635+ write ! ( f, "LOCAL " )
76377636 }
76387637 Self :: Session => {
7639- write ! ( f, " SESSION" )
7638+ write ! ( f, "SESSION " )
7639+ }
7640+ Self :: Global => {
7641+ write ! ( f, "GLOBAL " )
76407642 }
76417643 }
76427644 }
76437645}
76447646
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+
76457661/// Function describe in DROP FUNCTION.
76467662#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
76477663#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments