Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use tidb yacc parser to diagnose (#16189)

h3n4l1ada1f3bdc8f
diff --git a/backend/plugin/parser/mysql/diagnose.go b/backend/plugin/parser/mysql/diagnose.go
index c888c283c0..cb0d32a7c6 100644
--- a/backend/plugin/parser/mysql/diagnose.go
+++ b/backend/plugin/parser/mysql/diagnose.go
@@ -15,7 +15,6 @@ import (
func init() {
base.RegisterDiagnoseFunc(store.Engine_MYSQL, Diagnose)
base.RegisterDiagnoseFunc(store.Engine_MARIADB, Diagnose)
- base.RegisterDiagnoseFunc(store.Engine_TIDB, Diagnose)
base.RegisterDiagnoseFunc(store.Engine_OCEANBASE, Diagnose)
base.RegisterDiagnoseFunc(store.Engine_CLICKHOUSE, Diagnose)
}
diff --git a/backend/plugin/parser/tidb/diagnose.go b/backend/plugin/parser/tidb/diagnose.go
new file mode 100644
index 0000000000..bebd58d612
--- /dev/null
+++ b/backend/plugin/parser/tidb/diagnose.go
@@ -0,0 +1,28 @@
+package tidb
+
+import (
+ "context"
+ "errors"
+
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+ "github.com/bytebase/bytebase/proto/generated-go/store"
+)
+
+func init() {
+ base.RegisterDiagnoseFunc(store.Engine_TIDB, Diagnose)
+}
+
+func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error) {
+ diagnostics := make([]base.Diagnostic, 0)
+ _, err := ParseTiDB(statement, "", "")
+ var syntaxError *base.SyntaxError
+ if err != nil {
+ if errors.As(err, &syntaxError) {
+ diagnostics = append(diagnostics, base.ConvertSyntaxErrorToDiagnostic(syntaxError, statement))
+ } else {
+ return nil, err
+ }
+ }
+
+ return diagnostics, nil
+}