sqlparser/dialect/
sqlite.rs1#[cfg(not(feature = "std"))]
19use alloc::boxed::Box;
20
21use crate::ast::BinaryOperator;
22use crate::ast::{Expr, Statement};
23use crate::dialect::Dialect;
24use crate::keywords::Keyword;
25use crate::parser::{Parser, ParserError};
26
27#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
34#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35pub struct SQLiteDialect {}
36
37impl Dialect for SQLiteDialect {
38 fn is_delimited_identifier_start(&self, ch: char) -> bool {
42 ch == '`' || ch == '"' || ch == '['
43 }
44
45 fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
46 Some('`')
47 }
48
49 fn is_identifier_start(&self, ch: char) -> bool {
50 ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' || ch >= '\u{0080}'
52 }
53
54 fn supports_filter_during_aggregation(&self) -> bool {
55 true
56 }
57
58 fn supports_start_transaction_modifier(&self) -> bool {
59 true
60 }
61
62 fn is_identifier_part(&self, ch: char) -> bool {
63 self.is_identifier_start(ch) || ch.is_ascii_digit()
64 }
65
66 fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
67 if parser.parse_keyword(Keyword::REPLACE) {
68 parser.prev_token();
69 Some(parser.parse_insert(parser.get_current_token().clone()))
70 } else {
71 None
72 }
73 }
74
75 fn parse_infix(
76 &self,
77 parser: &mut crate::parser::Parser,
78 expr: &crate::ast::Expr,
79 precedence: u8,
80 ) -> Option<Result<crate::ast::Expr, ParserError>> {
81 for (keyword, op) in [
84 (Keyword::REGEXP, BinaryOperator::Regexp),
85 (Keyword::MATCH, BinaryOperator::Match),
86 (Keyword::GLOB, BinaryOperator::Glob),
87 ] {
88 if parser.parse_keyword(keyword) {
89 let left = Box::new(expr.clone());
90 let right = Box::new(match parser.parse_subexpr(precedence) {
91 Ok(expr) => expr,
92 Err(e) => return Some(Err(e)),
93 });
94 return Some(Ok(Expr::BinaryOp { left, op, right }));
95 }
96 }
97 None
98 }
99
100 fn supports_in_empty_list(&self) -> bool {
101 true
102 }
103
104 fn supports_limit_comma(&self) -> bool {
105 true
106 }
107
108 fn supports_asc_desc_in_column_definition(&self) -> bool {
109 true
110 }
111
112 fn supports_dollar_placeholder(&self) -> bool {
113 true
114 }
115
116 fn supports_notnull_operator(&self) -> bool {
119 true
120 }
121
122 fn supports_comma_separated_trim(&self) -> bool {
123 true
124 }
125
126 fn supports_numeric_literal_underscores(&self) -> bool {
127 true
128 }
129
130 fn supports_double_eq_assignment(&self) -> bool {
131 true
132 }
133
134 fn supports_string_literal_column_names(&self) -> bool {
135 true
136 }
137
138 fn supports_cast_empty_data_type_to_unspecified(&self) -> bool {
139 true
140 }
141
142 fn supports_national_string_literal(&self) -> bool {
143 false
144 }
145}