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 omit semicolon for the last statement in diagnose (#13701)
h3n4l3055285a4c8f
diff --git a/backend/plugin/parser/mysql/diagnose.go b/backend/plugin/parser/mysql/diagnose.goindex 6c8830f880..c1779eaa22 100644--- a/backend/plugin/parser/mysql/diagnose.go+++ b/backend/plugin/parser/mysql/diagnose.go@@ -2,6 +2,8 @@ package mysqlimport ("context"+ "strings"+ "unicode""github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/mysql-parser"@@ -31,6 +33,12 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]ba}func parseMySQLStatement(statement string) *base.SyntaxError {+ trimmedStatement := strings.TrimRightFunc(statement, unicode.IsSpace)+ if !strings.HasSuffix(trimmedStatement, ";") {+ // Add a semicolon to the end of the statement to allow users to omit the semicolon+ // for the last statement in the script.+ statement += ";"+ }inputStream := antlr.NewInputStream(statement)lexer := parser.NewMySQLLexer(inputStream)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)diff --git a/backend/plugin/parser/pg/diagnose.go b/backend/plugin/parser/pg/diagnose.goindex 562775810b..9000506c36 100644--- a/backend/plugin/parser/pg/diagnose.go+++ b/backend/plugin/parser/pg/diagnose.go@@ -2,6 +2,8 @@ package pgimport ("context"+ "strings"+ "unicode""github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/postgresql-parser"@@ -28,8 +30,14 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]ba// parsePostgreSQLStatement parses the given SQL and returns the ParseResult.// Use the PostgreSQL parser based on antlr4.-func parsePostgreSQLStatement(sql string) *base.SyntaxError {- lexer := parser.NewPostgreSQLLexer(antlr.NewInputStream(sql))+func parsePostgreSQLStatement(statement string) *base.SyntaxError {+ trimmedStatement := strings.TrimRightFunc(statement, unicode.IsSpace)+ if !strings.HasSuffix(trimmedStatement, ";") {+ // Add a semicolon to the end of the statement to allow users to omit the semicolon+ // for the last statement in the script.+ statement += ";"+ }+ lexer := parser.NewPostgreSQLLexer(antlr.NewInputStream(statement))stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)p := parser.NewPostgreSQLParser(stream)lexerErrorListener := &base.ParseErrorListener{}diff --git a/backend/plugin/parser/plsql/diagnose.go b/backend/plugin/parser/plsql/diagnose.goindex fe40840697..ce4b41999e 100644--- a/backend/plugin/parser/plsql/diagnose.go+++ b/backend/plugin/parser/plsql/diagnose.go@@ -2,6 +2,8 @@ package plsqlimport ("context"+ "strings"+ "unicode""github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/plsql-parser"@@ -27,8 +29,15 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]ba}// ParsePLSQL parses the given PLSQL.-func parsePLSQLStatement(sql string) *base.SyntaxError {- lexer := parser.NewPlSqlLexer(antlr.NewInputStream(sql))+func parsePLSQLStatement(statement string) *base.SyntaxError {+ trimmedStatement := strings.TrimRightFunc(statement, unicode.IsSpace)+ if !strings.HasSuffix(trimmedStatement, ";") {+ // Add a semicolon to the end of the statement to allow users to omit the semicolon+ // for the last statement in the script.+ statement += ";"+ }++ lexer := parser.NewPlSqlLexer(antlr.NewInputStream(statement))stream := antlr.NewCommonTokenStream(lexer, 0)p := parser.NewPlSqlParser(stream)p.SetVersion12(true)diff --git a/backend/plugin/parser/snowflake/diagnose.go b/backend/plugin/parser/snowflake/diagnose.goindex 0ae934e1cb..c0a8dc3649 100644--- a/backend/plugin/parser/snowflake/diagnose.go+++ b/backend/plugin/parser/snowflake/diagnose.go@@ -2,6 +2,8 @@ package snowflakeimport ("context"+ "strings"+ "unicode""github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/snowsql-parser"@@ -25,6 +27,12 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]ba}func parseSnowflakeStatement(statement string) *base.SyntaxError {+ trimmedStatement := strings.TrimRightFunc(statement, unicode.IsSpace)+ if !strings.HasSuffix(trimmedStatement, ";") {+ // Add a semicolon to the end of the statement to allow users to omit the semicolon+ // for the last statement in the script.+ statement += ";"+ }inputStream := antlr.NewInputStream(statement)lexer := parser.NewSnowflakeLexer(inputStream)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)diff --git a/backend/plugin/parser/tsql/diagnose.go b/backend/plugin/parser/tsql/diagnose.goindex e4a42d8f16..5191b2160d 100644--- a/backend/plugin/parser/tsql/diagnose.go+++ b/backend/plugin/parser/tsql/diagnose.go@@ -2,6 +2,8 @@ package tsqlimport ("context"+ "strings"+ "unicode""github.com/antlr4-go/antlr/v4"parser "github.com/bytebase/tsql-parser"@@ -25,6 +27,12 @@ func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]ba}func parseTSQLStatement(statement string) *base.SyntaxError {+ trimmedStatement := strings.TrimRightFunc(statement, unicode.IsSpace)+ if !strings.HasSuffix(trimmedStatement, ";") {+ // Add a semicolon to the end of the statement to allow users to omit the semicolon+ // for the last statement in the script.+ statement += ";"+ }inputStream := antlr.NewInputStream(statement)lexer := parser.NewTSqlLexer(inputStream)stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)