Skip to content

Commit ccb5486

Browse files
committed
feat(rule): add detection for Event SQL in rule checks
- Enhance the checkEventScheduler rule to also detect Event SQL statements - Implement a new IsEventSQL utility function for identifying Event-related SQL
1 parent e4c828b commit ccb5486

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sqle/driver/mysql/rule/rule.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5434,7 +5434,8 @@ func avoidSet(input *RuleHandlerInput) error {
54345434
}
54355435

54365436
func checkEventScheduler(input *RuleHandlerInput) error {
5437-
if utils.IsOpenEventScheduler(input.Node.Text()) {
5437+
if utils.IsOpenEventScheduler(input.Node.Text()) ||
5438+
utils.IsEventSQL(input.Node.Text()) {
54385439
addResult(input.Res, input.Rule, input.Rule.Name)
54395440
}
54405441
return nil

sqle/utils/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,18 @@ func IsOpenEventScheduler(sql string) bool {
213213
reg := regexp.MustCompile(pattern)
214214
return reg.MatchString(strings.TrimSpace(sql))
215215
}
216+
217+
// TODO: 暂时使用正则表达式匹配event,后续会修改语法树进行匹配event
218+
func IsEventSQL(sql string) bool {
219+
createPattern := `^CREATE\s+(DEFINER\s?=.+?)?EVENT`
220+
createRe := regexp.MustCompile(createPattern)
221+
alterPattern := `^ALTER\s+(DEFINER\s?=.+?)?EVENT`
222+
alterRe := regexp.MustCompile(alterPattern)
223+
224+
sql = strings.ToUpper(strings.TrimSpace(sql))
225+
if createRe.MatchString(sql) {
226+
return true
227+
} else {
228+
return alterRe.MatchString(sql)
229+
}
230+
}

0 commit comments

Comments
 (0)