Skip to content

Commit f4f8c07

Browse files
authored
Merge pull request #26 from antialize/updates
Updates
2 parents 75fa8d6 + 4f1b8dd commit f4f8c07

File tree

8 files changed

+48
-8
lines changed

8 files changed

+48
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sql-parse"
3-
version = "0.25.0"
3+
version = "0.26.0"
44
edition = "2021"
55
authors = ["Jakob Truelsen <[email protected]>"]
66
keywords = [ "mysql", "postgresql", "sql", "lexer", "parser" ]

src/alter.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,7 @@ fn parse_alter_table<'a>(
756756
match parser.token {
757757
Token::Ident(_, Keyword::DEFAULT) => {
758758
let drop_default_span = parser.consume().join_span(&set_span);
759-
AlterColumnAction::DropDefault {
760-
drop_default_span,
761-
}
759+
AlterColumnAction::DropDefault { drop_default_span }
762760
}
763761
Token::Ident(_, Keyword::NOT) => {
764762
let drop_not_null_span = set_span.join_span(

src/create.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,31 @@ fn parse_create_index<'a>(
10331033
gist_span.join_span(&using_span),
10341034
));
10351035
}
1036+
10361037
let l_paren_span = parser.consume_token(Token::LParen)?;
10371038
let mut column_names = Vec::new();
1038-
column_names.push(parser.consume_plain_identifier()?);
1039-
while parser.skip_token(Token::Comma).is_some() {
1039+
loop {
10401040
column_names.push(parser.consume_plain_identifier()?);
1041+
if let Token::Ident(
1042+
_,
1043+
Keyword::TEXT_PATTERN_OPS
1044+
| Keyword::VARCHAR_PATTERN_OPS
1045+
| Keyword::BPCHAR_PATTERN_OPS
1046+
| Keyword::INT8_OPS
1047+
| Keyword::INT4_OPS
1048+
| Keyword::INT2_OPS,
1049+
) = &parser.token
1050+
{
1051+
let range = parser.consume();
1052+
if !parser.options.dialect.is_postgresql() {
1053+
parser.err("Opclasses not supporetd", &range);
1054+
}
1055+
}
1056+
if parser.skip_token(Token::Comma).is_none() {
1057+
break;
1058+
}
10411059
}
1060+
10421061
let r_paren_span = parser.consume_token(Token::RParen)?;
10431062

10441063
let mut where_ = None;

src/expression.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub enum Function<'a> {
174174
SoundEx,
175175
Space,
176176
Sqrt,
177+
StartsWith,
177178
StrCmp,
178179
Strftime,
179180
StrToDate,
@@ -600,6 +601,7 @@ fn parse_function<'a>(
600601
Token::Ident(_, Keyword::VALUES) => Function::Value,
601602
Token::Ident(_, Keyword::LEAD) => Function::Lead,
602603
Token::Ident(_, Keyword::LAG) => Function::Lag,
604+
Token::Ident(_, Keyword::STARTS_WITH) => Function::StartsWith,
603605

604606
//https://mariadb.com/kb/en/control-flow-functions/
605607
Token::Ident(_, Keyword::IFNULL) => Function::IfNull,

src/keywords.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ BODY
128128
BOOL
129129
BOOLEAN
130130
BOTH
131+
BPCHAR_PATTERN_OPS
131132
BTREE
132133
BY
133134
BYTE
@@ -389,9 +390,12 @@ INSTR
389390
INT
390391
INT1
391392
INT2
393+
INT2_OPS
392394
INT3
393395
INT4
396+
INT4_OPS
394397
INT8
398+
INT8_OPS
395399
INTEGER
396400
INTERSECT
397401
INTERSECTA
@@ -802,6 +806,7 @@ STAGE
802806
START
803807
STARTING
804808
STARTS
809+
STARTS_WITH
805810
STATEMENT
806811
STATS_AUTO_RECALC
807812
STATS_PERSISTENT
@@ -844,6 +849,7 @@ TEMPORARY
844849
TEMPTABLE
845850
TERMINATED
846851
TEXT
852+
TEXT_PATTERN_OPS
847853
THAN
848854
THEN
849855
THREADS
@@ -909,6 +915,7 @@ VALUE
909915
VALUES
910916
VARBINARY
911917
VARCHAR
918+
VARCHAR_PATTERN_OPS
912919
VARCHAR2
913920
VARCHARACTER
914921
VARIABLES

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub fn test_parse_delete_sql_with_schema() {
288288
parse_statement(sql, &mut issues, &options);
289289
assert!(issues.is_ok(), "{}", issues);
290290
}
291+
291292
#[test]
292293
pub fn parse_create_index_sql_with_schema() {
293294
let sql = "CREATE INDEX `idx_test` ON test_schema.test(`col_test`)";
@@ -301,6 +302,19 @@ pub fn parse_create_index_sql_with_schema() {
301302
assert!(issues.is_ok(), "{}", issues);
302303
}
303304

305+
#[test]
306+
pub fn parse_create_index_sql_with_opclass() {
307+
let sql = "CREATE INDEX idx_test ON test(path text_pattern_ops)";
308+
let options = ParseOptions::new()
309+
.dialect(SQLDialect::PostgreSQL)
310+
.arguments(SQLArguments::Dollar)
311+
.warn_unquoted_identifiers(false);
312+
313+
let mut issues = Issues::new(sql);
314+
parse_statement(sql, &mut issues, &options);
315+
assert!(issues.is_ok(), "{}", issues);
316+
}
317+
304318
#[test]
305319
pub fn parse_drop_index_sql_with_schema() {
306320
let sql = "DROP INDEX `idx_test` ON test_schema.test";

src/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<S: Spanned> Spanned for (bool, S) {
122122
}
123123
}
124124

125-
impl<S: Spanned> Spanned for (& str, S) {
125+
impl<S: Spanned> Spanned for (&str, S) {
126126
fn span(&self) -> Span {
127127
self.1.span()
128128
}

0 commit comments

Comments
 (0)