Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sql-parse"
version = "0.25.0"
version = "0.26.0"
edition = "2021"
authors = ["Jakob Truelsen <antialize@gmail.com>"]
keywords = [ "mysql", "postgresql", "sql", "lexer", "parser" ]
Expand Down
4 changes: 1 addition & 3 deletions src/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,7 @@ fn parse_alter_table<'a>(
match parser.token {
Token::Ident(_, Keyword::DEFAULT) => {
let drop_default_span = parser.consume().join_span(&set_span);
AlterColumnAction::DropDefault {
drop_default_span,
}
AlterColumnAction::DropDefault { drop_default_span }
}
Token::Ident(_, Keyword::NOT) => {
let drop_not_null_span = set_span.join_span(
Expand Down
23 changes: 21 additions & 2 deletions src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,31 @@ fn parse_create_index<'a>(
gist_span.join_span(&using_span),
));
}

let l_paren_span = parser.consume_token(Token::LParen)?;
let mut column_names = Vec::new();
column_names.push(parser.consume_plain_identifier()?);
while parser.skip_token(Token::Comma).is_some() {
loop {
column_names.push(parser.consume_plain_identifier()?);
if let Token::Ident(
_,
Keyword::TEXT_PATTERN_OPS
| Keyword::VARCHAR_PATTERN_OPS
| Keyword::BPCHAR_PATTERN_OPS
| Keyword::INT8_OPS
| Keyword::INT4_OPS
| Keyword::INT2_OPS,
) = &parser.token
{
let range = parser.consume();
if !parser.options.dialect.is_postgresql() {
parser.err("Opclasses not supporetd", &range);
}
}
if parser.skip_token(Token::Comma).is_none() {
break;
}
}

let r_paren_span = parser.consume_token(Token::RParen)?;

let mut where_ = None;
Expand Down
2 changes: 2 additions & 0 deletions src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub enum Function<'a> {
SoundEx,
Space,
Sqrt,
StartsWith,
StrCmp,
Strftime,
StrToDate,
Expand Down Expand Up @@ -600,6 +601,7 @@ fn parse_function<'a>(
Token::Ident(_, Keyword::VALUES) => Function::Value,
Token::Ident(_, Keyword::LEAD) => Function::Lead,
Token::Ident(_, Keyword::LAG) => Function::Lag,
Token::Ident(_, Keyword::STARTS_WITH) => Function::StartsWith,

//https://mariadb.com/kb/en/control-flow-functions/
Token::Ident(_, Keyword::IFNULL) => Function::IfNull,
Expand Down
7 changes: 7 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ BODY
BOOL
BOOLEAN
BOTH
BPCHAR_PATTERN_OPS
BTREE
BY
BYTE
Expand Down Expand Up @@ -389,9 +390,12 @@ INSTR
INT
INT1
INT2
INT2_OPS
INT3
INT4
INT4_OPS
INT8
INT8_OPS
INTEGER
INTERSECT
INTERSECTA
Expand Down Expand Up @@ -802,6 +806,7 @@ STAGE
START
STARTING
STARTS
STARTS_WITH
STATEMENT
STATS_AUTO_RECALC
STATS_PERSISTENT
Expand Down Expand Up @@ -844,6 +849,7 @@ TEMPORARY
TEMPTABLE
TERMINATED
TEXT
TEXT_PATTERN_OPS
THAN
THEN
THREADS
Expand Down Expand Up @@ -909,6 +915,7 @@ VALUE
VALUES
VARBINARY
VARCHAR
VARCHAR_PATTERN_OPS
VARCHAR2
VARCHARACTER
VARIABLES
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ pub fn test_parse_delete_sql_with_schema() {
parse_statement(sql, &mut issues, &options);
assert!(issues.is_ok(), "{}", issues);
}

#[test]
pub fn parse_create_index_sql_with_schema() {
let sql = "CREATE INDEX `idx_test` ON test_schema.test(`col_test`)";
Expand All @@ -301,6 +302,19 @@ pub fn parse_create_index_sql_with_schema() {
assert!(issues.is_ok(), "{}", issues);
}

#[test]
pub fn parse_create_index_sql_with_opclass() {
let sql = "CREATE INDEX idx_test ON test(path text_pattern_ops)";
let options = ParseOptions::new()
.dialect(SQLDialect::PostgreSQL)
.arguments(SQLArguments::Dollar)
.warn_unquoted_identifiers(false);

let mut issues = Issues::new(sql);
parse_statement(sql, &mut issues, &options);
assert!(issues.is_ok(), "{}", issues);
}

#[test]
pub fn parse_drop_index_sql_with_schema() {
let sql = "DROP INDEX `idx_test` ON test_schema.test";
Expand Down
2 changes: 1 addition & 1 deletion src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<S: Spanned> Spanned for (bool, S) {
}
}

impl<S: Spanned> Spanned for (& str, S) {
impl<S: Spanned> Spanned for (&str, S) {
fn span(&self) -> Span {
self.1.span()
}
Expand Down