Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: allow desc and show commands in sql editor read only mode for mysql (#12385)
h3n4l50b02f3bd858
diff --git a/backend/plugin/parser/mysql/query.go b/backend/plugin/parser/mysql/query.goindex 8a9cf6702d..209f264e7b 100644--- a/backend/plugin/parser/mysql/query.go+++ b/backend/plugin/parser/mysql/query.go@@ -53,6 +53,9 @@ type queryValidateListener struct {// EnterQuery is called when production query is entered.func (l *queryValidateListener) EnterQuery(ctx *parser.QueryContext) {+ if !l.valid {+ return+ }if ctx.BeginWork() != nil {l.valid = false}@@ -60,20 +63,29 @@ func (l *queryValidateListener) EnterQuery(ctx *parser.QueryContext) {// EnterSimpleStatement is called when production simpleStatement is entered.func (l *queryValidateListener) EnterSimpleStatement(ctx *parser.SimpleStatementContext) {- if ctx.SelectStatement() == nil && ctx.UtilityStatement() == nil && ctx.SetStatement() == nil {+ if !l.valid {+ return+ }+ if ctx.SelectStatement() == nil && ctx.UtilityStatement() == nil && ctx.SetStatement() == nil && ctx.ShowStatement() == nil {l.valid = false}}// EnterUtilityStatement is called when production utilityStatement is entered.func (l *queryValidateListener) EnterUtilityStatement(ctx *parser.UtilityStatementContext) {- if ctx.ExplainStatement() == nil {+ if !l.valid {+ return+ }+ if ctx.ExplainStatement() == nil && ctx.DescribeStatement() == nil {l.valid = false}}// EnterExplainableStatement is called when production explainableStatement is entered.func (l *queryValidateListener) EnterExplainableStatement(ctx *parser.ExplainableStatementContext) {+ if !l.valid {+ return+ }if ctx.DeleteStatement() != nil || ctx.UpdateStatement() != nil || ctx.InsertStatement() != nil || ctx.ReplaceStatement() != nil {l.valid = false}diff --git a/backend/plugin/parser/mysql/query_test.go b/backend/plugin/parser/mysql/query_test.goindex 1bee6c87a8..adb7c280ca 100644--- a/backend/plugin/parser/mysql/query_test.go+++ b/backend/plugin/parser/mysql/query_test.go@@ -14,6 +14,14 @@ func TestValidateSQLForEditor(t *testing.T) {validate boolerr bool}{+ {+ statement: "SHOW CREATE TABLE bytebase;",+ validate: true,+ },+ {+ statement: "DESC bytebase;",+ validate: true,+ },{statement: "SELECT * FROM t1 WHERE c1 = 1; SELECT * FROM t2;",validate: true,