Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: not parse value list as SELECT statement (#2212)
rebelice0f0dfce5cfac
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required_test.go b/plugin/advisor/mysql/advisor_stmt_where_required_test.goindex 2e36238f90..2241bcb616 100644--- a/plugin/advisor/mysql/advisor_stmt_where_required_test.go+++ b/plugin/advisor/mysql/advisor_stmt_where_required_test.go@@ -8,6 +8,17 @@ import (func TestWhereRequirement(t *testing.T) {tests := []advisor.TestCase{+ {+ Statement: "INSERT INTO t values (1)",+ Want: []advisor.Advice{+ {+ Status: advisor.Success,+ Code: advisor.Ok,+ Title: "OK",+ Content: "",+ },+ },+ },{Statement: "DELETE FROM t1",Want: []advisor.Advice{diff --git a/plugin/advisor/pg/advisor_stmt_where_required_test.go b/plugin/advisor/pg/advisor_stmt_where_required_test.goindex 7e86ffbfc9..621ded8743 100644--- a/plugin/advisor/pg/advisor_stmt_where_required_test.go+++ b/plugin/advisor/pg/advisor_stmt_where_required_test.go@@ -8,6 +8,17 @@ import (func TestWhereRequirement(t *testing.T) {tests := []advisor.TestCase{+ {+ Statement: "INSERT INTO t VALUES(1)",+ Want: []advisor.Advice{+ {+ Status: advisor.Success,+ Code: advisor.Ok,+ Title: "OK",+ Content: "",+ },+ },+ },{Statement: "DELETE FROM t1",Want: []advisor.Advice{diff --git a/plugin/parser/engine/pg/convert.go b/plugin/parser/engine/pg/convert.goindex 1d3dccf521..5cd3363fc2 100644--- a/plugin/parser/engine/pg/convert.go+++ b/plugin/parser/engine/pg/convert.go@@ -336,8 +336,11 @@ func convert(node *pgquery.Node, text string) (res ast.Node, err error) {if in.InsertStmt.SelectStmt != nil {if selectNode, ok := in.InsertStmt.SelectStmt.Node.(*pgquery.Node_SelectStmt); ok {- if insertStmt.Select, err = convertSelectStmt(selectNode.SelectStmt); err != nil {- return nil, err+ // PG parser will parse the value list as a SELECT statement.+ if selectNode.SelectStmt.ValuesLists == nil {+ if insertStmt.Select, err = convertSelectStmt(selectNode.SelectStmt); err != nil {+ return nil, err+ }}} else {return nil, parser.NewConvertErrorf("expected SelectStmt but found %t", in.InsertStmt.SelectStmt.Node)diff --git a/plugin/parser/engine/pg/convert_test.go b/plugin/parser/engine/pg/convert_test.goindex 84971315b9..ee9d0a41a4 100644--- a/plugin/parser/engine/pg/convert_test.go+++ b/plugin/parser/engine/pg/convert_test.go@@ -1309,7 +1309,6 @@ func TestInsertStmt(t *testing.T) {Type: ast.TableTypeBaseTable,Name: "tech_book",},- Select: &ast.SelectStmt{},},},textList: []string{diff --git a/tests/sql_review_test.go b/tests/sql_review_test.goindex 3c38a90c8a..bca0e9d32f 100644--- a/tests/sql_review_test.go+++ b/tests/sql_review_test.go@@ -197,6 +197,18 @@ func TestSQLReviewForPostgreSQL(t *testing.T) {},},},+ {+ statement: `INSERT INTO t VALUES (1), (2)`,+ result: []api.TaskCheckResult{+ {+ Status: api.TaskCheckStatusSuccess,+ Namespace: api.BBNamespace,+ Code: common.Ok.Int(),+ Title: "OK",+ Content: "",+ },+ },+ },{statement: `CREATE TABLE tech_book(@@ -542,6 +554,18 @@ func TestSQLReviewForMySQL(t *testing.T) {},},},+ {+ statement: `INSERT INTO t VALUES (1), (2)`,+ result: []api.TaskCheckResult{+ {+ Status: api.TaskCheckStatusSuccess,+ Namespace: api.BBNamespace,+ Code: common.Ok.Int(),+ Title: "OK",+ Content: "",+ },+ },+ },{statement: "DELETE FROM t WHERE a = (SELECT max(id) FROM user WHERE name = 'bytebase')",result: []api.TaskCheckResult{