Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add not ilike statements support #609

Merged
merged 2 commits into from
Dec 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions encryptor/searchable_query_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (filter *SearchableQueryFilter) FilterSearchableComparisons(statement sqlpa
// ChangeSearchableOperator change the operator of ComparisonExpr to EqualStr|NotEqualStr depending on expr.Operator
func (filter *SearchableQueryFilter) ChangeSearchableOperator(expr *sqlparser.ComparisonExpr) {
switch expr.Operator {
case sqlparser.EqualStr, sqlparser.NullSafeEqualStr, sqlparser.LikeStr:
case sqlparser.EqualStr, sqlparser.NullSafeEqualStr, sqlparser.LikeStr, sqlparser.ILikeStr:
expr.Operator = sqlparser.EqualStr
case sqlparser.NotEqualStr, sqlparser.NotLikeStr:
case sqlparser.NotEqualStr, sqlparser.NotLikeStr, sqlparser.NotILikeStr:
expr.Operator = sqlparser.NotEqualStr
}
}
Expand Down
1 change: 1 addition & 0 deletions sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ const (
LikeStr = "like"
ILikeStr = "ilike"
NotLikeStr = "not like"
NotILikeStr = "not ilike"
RegexpStr = "regexp"
NotRegexpStr = "not regexp"
JSONExtractOp = "->"
Expand Down
19 changes: 17 additions & 2 deletions sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,13 +1365,20 @@ var (
dialect: postgresql.NewPostgreSQLDialect(),
}, { // PostgreSQL format
input: "select * from dual where val ilike 'test%'",
output: "select * from dual where val ilike 'test%'",
dialect: postgresql.NewPostgreSQLDialect(),
}, {
input: "select * from dual where val not ilike 'test%'",
dialect: postgresql.NewPostgreSQLDialect(),
}, {
input: "SELECT * FROM dual WHERE val ILIKE 'test%'",
output: "select * from dual where val ilike 'test%'",
dialect: postgresql.NewPostgreSQLDialect(),
}}
}, {
input: "SELECT * FROM dual WHERE val NOT ILIKE 'test%'",
output: "select * from dual where val not ilike 'test%'",
dialect: postgresql.NewPostgreSQLDialect(),
},
}
)

func TestValid(t *testing.T) {
Expand Down Expand Up @@ -2233,10 +2240,18 @@ var (
input: "select * from dual where val ilike 'test%'",
output: "MySQL dialect doesn't support `ILIKE` statement at position 43",
dialect: mysql.NewMySQLDialect(),
}, {
input: "select * from dual where val not ilike 'test%'",
output: "MySQL dialect doesn't support `ILIKE` statement at position 47",
dialect: mysql.NewMySQLDialect(),
}, {
input: "SELECT * FROM dual WHERE val ILIKE 'test%'",
output: "MySQL dialect doesn't support `ILIKE` statement at position 43",
dialect: mysql.NewMySQLDialect(),
}, {
input: "SELECT * FROM dual WHERE val NOT ILIKE 'test%'",
output: "MySQL dialect doesn't support `ILIKE` statement at position 47",
dialect: mysql.NewMySQLDialect(),
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion sqlparser/sql.go

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

2 changes: 1 addition & 1 deletion sqlparser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ condition:
yylex.Error("MySQL dialect doesn't support `ILIKE` statement")
return 1
}
$$ = &ComparisonExpr{Left: $1, Operator: NotLikeStr, Right: $4, Escape: $5}
$$ = &ComparisonExpr{Left: $1, Operator: NotILikeStr, Right: $4, Escape: $5}
}
| value_expression REGEXP value_expression
{
Expand Down