Skip to content

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

chore: mysql query taking set statement (#10787)

Danny Xu6bc99205f700
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index fbe264765a..7b8c296714 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -360,9 +360,10 @@ func getConnectionID(ctx context.Context, conn *sql.Conn) (string, error) {
func (driver *Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, singleSQL base.SingleSQL, queryContext *db.QueryContext) (*v1pb.QueryResult, error) {
statement := strings.TrimLeft(strings.TrimRight(singleSQL.Text, " \n\t;"), " \n\t")
isExplain := strings.HasPrefix(statement, "EXPLAIN")
+ isSet, _ := regexp.MatchString(`(?i)^SET\s+?`, statement)
stmt := statement
- if !isExplain && queryContext.Limit > 0 {
+ if !isExplain && !isSet && queryContext.Limit > 0 {
stmt = getStatementWithResultLimit(stmt, queryContext.Limit)
}
diff --git a/backend/plugin/parser/mysql/query.go b/backend/plugin/parser/mysql/query.go
index 1a1b5387c0..8a9cf6702d 100644
--- a/backend/plugin/parser/mysql/query.go
+++ b/backend/plugin/parser/mysql/query.go
@@ -60,7 +60,7 @@ 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 {
+ if ctx.SelectStatement() == nil && ctx.UtilityStatement() == nil && ctx.SetStatement() == nil {
l.valid = false
}
}
diff --git a/backend/plugin/parser/mysql/query_test.go b/backend/plugin/parser/mysql/query_test.go
index a6df8e5a2c..45ec2b1c3f 100644
--- a/backend/plugin/parser/mysql/query_test.go
+++ b/backend/plugin/parser/mysql/query_test.go
@@ -87,6 +87,10 @@ func TestValidateSQLForEditor(t *testing.T) {
statement: `create table t (a int);`,
validate: false,
},
+ {
+ statement: `SET max_execution_time = 1000; select * from t`,
+ validate: true,
+ },
}
for _, test := range tests {