@@ -24,6 +24,7 @@ mod generic;
2424mod hive;
2525mod mssql;
2626mod mysql;
27+ mod oracle;
2728mod postgresql;
2829mod redshift;
2930mod snowflake;
@@ -45,6 +46,7 @@ pub use self::generic::GenericDialect;
4546pub use self :: hive:: HiveDialect ;
4647pub use self :: mssql:: MsSqlDialect ;
4748pub use self :: mysql:: MySqlDialect ;
49+ pub use self :: oracle:: OracleDialect ;
4850pub use self :: postgresql:: PostgreSqlDialect ;
4951pub use self :: redshift:: RedshiftSqlDialect ;
5052pub use self :: snowflake:: SnowflakeDialect ;
@@ -84,6 +86,26 @@ macro_rules! dialect_is {
8486 }
8587}
8688
89+ const DEFAULT_PREC_VALUE_PERIOD : u8 = 100 ;
90+ const DEFAULT_PREC_VALUE_DOUBLE_COLON : u8 = 50 ;
91+ const DEFAULT_PREC_VALUE_AT_TZ : u8 = 41 ;
92+ const DEFAULT_PREC_VALUE_MUL_DIV_MOD_OP : u8 = 40 ;
93+ const DEFAULT_PREC_VALUE_PLUS_MINUS : u8 = 30 ;
94+ const DEFAULT_PREC_VALUE_XOR : u8 = 24 ;
95+ const DEFAULT_PREC_VALUE_AMPERSAND : u8 = 23 ;
96+ const DEFAULT_PREC_VALUE_CARET : u8 = 22 ;
97+ const DEFAULT_PREC_VALUE_PIPE : u8 = 21 ;
98+ const DEFAULT_PREC_VALUE_BETWEEN : u8 = 20 ;
99+ const DEFAULT_PREC_VALUE_EQ : u8 = 20 ;
100+ const DEFAULT_PREC_VALUE_LIKE : u8 = 19 ;
101+ const DEFAULT_PREC_VALUE_IS : u8 = 17 ;
102+ const DEFAULT_PREC_VALUE_PG_OTHER : u8 = 16 ;
103+ const DEFAULT_PREC_VALUE_UNARY_NOT : u8 = 15 ;
104+ const DEFAULT_PREC_VALUE_AND : u8 = 10 ;
105+ const DEFAULT_PREC_VALUE_OR : u8 = 5 ;
106+
107+ const DEFAULT_PREC_VALUE_UNKNOWN : u8 = 0 ;
108+
87109/// Encapsulates the differences between SQL implementations.
88110///
89111/// # SQL Dialects
@@ -773,6 +795,36 @@ pub trait Dialect: Debug + Any {
773795 }
774796 }
775797
798+ /// Decide the lexical Precedence of operators.
799+ ///
800+ /// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
801+ fn prec_value ( & self , prec : Precedence ) -> u8 {
802+ match prec {
803+ Precedence :: Period => DEFAULT_PREC_VALUE_PERIOD ,
804+ Precedence :: DoubleColon => DEFAULT_PREC_VALUE_DOUBLE_COLON ,
805+ Precedence :: AtTz => DEFAULT_PREC_VALUE_AT_TZ ,
806+ Precedence :: MulDivModOp => DEFAULT_PREC_VALUE_MUL_DIV_MOD_OP ,
807+ Precedence :: PlusMinus => DEFAULT_PREC_VALUE_PLUS_MINUS ,
808+ Precedence :: Xor => DEFAULT_PREC_VALUE_XOR ,
809+ Precedence :: Ampersand => DEFAULT_PREC_VALUE_AMPERSAND ,
810+ Precedence :: Caret => DEFAULT_PREC_VALUE_CARET ,
811+ Precedence :: Pipe => DEFAULT_PREC_VALUE_PIPE ,
812+ Precedence :: Between => DEFAULT_PREC_VALUE_BETWEEN ,
813+ Precedence :: Eq => DEFAULT_PREC_VALUE_EQ ,
814+ Precedence :: Like => DEFAULT_PREC_VALUE_LIKE ,
815+ Precedence :: Is => DEFAULT_PREC_VALUE_IS ,
816+ Precedence :: PgOther => DEFAULT_PREC_VALUE_PG_OTHER ,
817+ Precedence :: UnaryNot => DEFAULT_PREC_VALUE_UNARY_NOT ,
818+ Precedence :: And => DEFAULT_PREC_VALUE_AND ,
819+ Precedence :: Or => DEFAULT_PREC_VALUE_OR ,
820+ }
821+ }
822+
823+ /// Returns the precedence when the precedence is otherwise unknown
824+ fn prec_unknown ( & self ) -> u8 {
825+ DEFAULT_PREC_VALUE_UNKNOWN
826+ }
827+
776828 /// Dialect-specific statement parser override
777829 ///
778830 /// This method is called to parse the next statement.
@@ -796,36 +848,6 @@ pub trait Dialect: Debug + Any {
796848 Ok ( None )
797849 }
798850
799- /// Decide the lexical Precedence of operators.
800- ///
801- /// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
802- fn prec_value ( & self , prec : Precedence ) -> u8 {
803- match prec {
804- Precedence :: Period => 100 ,
805- Precedence :: DoubleColon => 50 ,
806- Precedence :: AtTz => 41 ,
807- Precedence :: MulDivModOp => 40 ,
808- Precedence :: PlusMinus => 30 ,
809- Precedence :: Xor => 24 ,
810- Precedence :: Ampersand => 23 ,
811- Precedence :: Caret => 22 ,
812- Precedence :: Pipe => 21 ,
813- Precedence :: Between => 20 ,
814- Precedence :: Eq => 20 ,
815- Precedence :: Like => 19 ,
816- Precedence :: Is => 17 ,
817- Precedence :: PgOther => 16 ,
818- Precedence :: UnaryNot => 15 ,
819- Precedence :: And => 10 ,
820- Precedence :: Or => 5 ,
821- }
822- }
823-
824- /// Returns the precedence when the precedence is otherwise unknown
825- fn prec_unknown ( & self ) -> u8 {
826- 0
827- }
828-
829851 /// Returns true if this dialect requires the `TABLE` keyword after `DESCRIBE`
830852 ///
831853 /// Defaults to false.
@@ -1260,6 +1282,7 @@ pub fn dialect_from_str(dialect_name: impl AsRef<str>) -> Option<Box<dyn Dialect
12601282 "ansi" => Some ( Box :: new ( AnsiDialect { } ) ) ,
12611283 "duckdb" => Some ( Box :: new ( DuckDbDialect { } ) ) ,
12621284 "databricks" => Some ( Box :: new ( DatabricksDialect { } ) ) ,
1285+ "oracle" => Some ( Box :: new ( OracleDialect { } ) ) ,
12631286 _ => None ,
12641287 }
12651288}
0 commit comments