diff --git a/session/errors.go b/session/errors.go index 153dd6914..4b560bc6e 100644 --- a/session/errors.go +++ b/session/errors.go @@ -20,19 +20,15 @@ package session import ( "fmt" // "strconv" - "strings" "github.com/hanchuanchuan/goInception/config" "github.com/hanchuanchuan/goInception/mysql" "github.com/hanchuanchuan/goInception/terror" - log "github.com/sirupsen/logrus" ) //go:generate stringer -type=ErrorCode type ErrorCode int -var ErrorsMessage = map[ErrorCode]string{} - var ( ErrWrongValueForVar = terror.ClassVariable.New(mysql.ErrWrongValueForVar, mysql.MySQLErrName[mysql.ErrWrongValueForVar]) @@ -667,11 +663,14 @@ func GetErrorLevel(code ErrorCode) uint8 { } } -func GetErrorMessage(ErrorCode ErrorCode) string { - if v, ok := ErrorsMessage[ErrorCode]; ok { - return v +// GetErrorMessage 获取审核信息,默认为英文 +func GetErrorMessage(code ErrorCode, lang string) string { + if lang == "zh_cn" { + if v, ok := ErrorsChinese[code]; ok { + return v + } } - if v, ok := ErrorsDefault[ErrorCode]; ok { + if v, ok := ErrorsDefault[code]; ok { return v } return "Invalid error code!" @@ -691,7 +690,7 @@ func (e *SQLError) Error() string { // NewErr generates a SQL error, with an error code and default format specifier defined in MySQLErrName. func NewErr(errCode ErrorCode, args ...interface{}) *SQLError { e := &SQLError{Code: errCode} - e.Message = fmt.Sprintf(GetErrorMessage(errCode), args...) + e.Message = fmt.Sprintf(GetErrorMessage(errCode, "en_us"), args...) return e } @@ -702,18 +701,6 @@ func NewErrf(format string, args ...interface{}) *SQLError { return e } -func SetLanguage(langStr string) { - lang := strings.Replace(strings.ToLower(langStr), "-", "_", 1) - if lang == "zh_cn" { - ErrorsMessage = ErrorsChinese - } else { - ErrorsMessage = ErrorsDefault - if lang != "en_us" { - log.Warning("Lang set Error! use default en-US.") - } - } -} - func (e ErrorCode) String() string { switch e { case ER_ERROR_FIRST: diff --git a/session/parser.go b/session/parser.go index 932474e66..bdb526b4b 100644 --- a/session/parser.go +++ b/session/parser.go @@ -418,7 +418,7 @@ func (s *session) checkFilter(event *replication.RowsEvent, if currentThreadID == 0 && s.DBType == DBTypeMariaDB { if record.ErrLevel != 1 { - record.AppendErrorNo(ErrNotFoundThreadId, s.DBVersion) + record.AppendErrorNo(s.Inc.Lang, ErrNotFoundThreadId, s.DBVersion) } return true } else if record.ThreadId != currentThreadID { @@ -459,7 +459,7 @@ func (s *session) checkUpdateFilter(event *replication.RowsEvent, if currentThreadID == 0 && s.DBType == DBTypeMariaDB { if record.ErrLevel != 1 { - record.AppendErrorNo(ErrNotFoundThreadId, s.DBVersion) + record.AppendErrorNo(s.Inc.Lang, ErrNotFoundThreadId, s.DBVersion) } return true, multiTable } else if record.ThreadId != currentThreadID { diff --git a/session/session.go b/session/session.go index 705156281..f5ad97865 100644 --- a/session/session.go +++ b/session/session.go @@ -21,6 +21,13 @@ import ( "crypto/tls" "encoding/json" "fmt" + "net" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + "github.com/hanchuanchuan/goInception/ast" "github.com/hanchuanchuan/goInception/config" "github.com/hanchuanchuan/goInception/domain" @@ -54,12 +61,6 @@ import ( log "github.com/sirupsen/logrus" "go.uber.org/zap" "golang.org/x/net/context" - "net" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" "github.com/jinzhu/gorm" ) diff --git a/session/session_inception.go b/session/session_inception.go index e98d6e416..cb2ab3d5a 100644 --- a/session/session_inception.go +++ b/session/session_inception.go @@ -138,7 +138,11 @@ type sourceOptions struct { sslCert string // 客户端公共密钥证书 sslKey string // 客户端私钥文件 + // 事务支持,一次执行多少条 tranBatch int + + // // 扩展参数,支持一次性会话设置 + // extendParams string } // ExplainInfo 执行计划信息 @@ -495,10 +499,10 @@ func (s *session) executeInc(ctx context.Context, sql string) (recordSets []sqle s.myRecord.Sql = currentSql if s.opt != nil && s.opt.Print { - s.printSets.Append(2, currentSql, "", GetErrorMessage(ER_HAVE_BEGIN)) + s.printSets.Append(2, currentSql, "", s.getErrorMessage(ER_HAVE_BEGIN)) } else if s.opt != nil && s.opt.split { s.addNewSplitNode() - s.splitSets.Append(currentSql, GetErrorMessage(ER_HAVE_BEGIN)) + s.splitSets.Append(currentSql, s.getErrorMessage(ER_HAVE_BEGIN)) } else { s.recordSets.Append(s.myRecord) } @@ -618,7 +622,7 @@ func (s *session) executeInc(ctx context.Context, sql string) (recordSets []sqle s.SetMyProcessInfo(currentSql, time.Now(), float64(i)/float64(lineCount+1)) // 交互式命令行 - if !need { + if _, ok := stmtNode.(*ast.InceptionSetStmt); !need && !ok { if s.opt != nil { return nil, errors.New("无效操作!不支持本地操作和远程操作混用!") } @@ -680,7 +684,12 @@ func (s *session) executeInc(ctx context.Context, sql string) (recordSets []sqle if s.opt != nil && s.opt.Print { // s.printSets.Append(2, "", "", strings.TrimSpace(s.myRecord.Buf.String())) } else { - s.recordSets.Append(s.myRecord) + // 远程操作时隐藏本地的set命令 + if _, ok := stmtNode.(*ast.InceptionSetStmt); ok && s.myRecord.ErrLevel == 0 { + log.Info(currentSql) + } else { + s.recordSets.Append(s.myRecord) + } } } @@ -889,7 +898,14 @@ func (s *session) processCommand(ctx context.Context, stmtNode ast.StmtNode, } case *ast.InceptionSetStmt: - return s.executeInceptionSet(node, currentSql) + if s.haveBegin { + _, err := s.executeInceptionSet(node, currentSql) + if err != nil { + s.AppendErrorMessage(err.Error()) + } + } else { + return s.executeInceptionSet(node, currentSql) + } case *ast.ExplainStmt: s.executeInceptionShow(currentSql) @@ -5994,6 +6010,15 @@ func (s *session) executeInceptionSet(node *ast.InceptionSetStmt, sql string) ([ return nil, errors.New("无效参数") } + if v.IsGlobal && s.haveBegin { + return nil, errors.New("全局变量仅支持单独设置") + } + + // 非本地模式时,只使用全局设置 + if !s.haveBegin { + v.IsGlobal = true + } + var value *ast.ValueExpr switch expr := v.Value.(type) { @@ -6011,7 +6036,10 @@ func (s *session) executeInceptionSet(node *ast.InceptionSetStmt, sql string) ([ cnf := config.GetGlobalConfig() if v.IsLevel { - err := s.setLevelValue(reflect.TypeOf(cnf.IncLevel), reflect.ValueOf(&cnf.IncLevel).Elem(), v.Name, value) + if s.haveBegin { + return nil, errors.New("暂不支持会话级的自定义审核级别") + } + err := s.setVariableValue(reflect.TypeOf(cnf.IncLevel), reflect.ValueOf(&cnf.IncLevel).Elem(), v.Name, value) if err != nil { return nil, err } @@ -6028,29 +6056,43 @@ func (s *session) executeInceptionSet(node *ast.InceptionSetStmt, sql string) ([ var err error switch prefix { case "osc": - err = s.setVariableValue(reflect.TypeOf(cnf.Osc), reflect.ValueOf(&cnf.Osc).Elem(), v.Name, value) + var object *config.Osc + if v.IsGlobal { + object = &cnf.Osc + } else { + object = &s.Osc + } + err = s.setVariableValue(reflect.TypeOf(*object), reflect.ValueOf(object).Elem(), v.Name, value) if err != nil { return nil, err } + case "ghost": - err = s.setVariableValue(reflect.TypeOf(cnf.Ghost), reflect.ValueOf(&cnf.Ghost).Elem(), v.Name, value) + var object *config.Ghost + if v.IsGlobal { + object = &cnf.Ghost + } else { + object = &s.Ghost + } + err = s.setVariableValue(reflect.TypeOf(*object), reflect.ValueOf(object).Elem(), v.Name, value) if err != nil { return nil, err } + default: if prefix == "version" { return nil, errors.New("只读变量") } - - err = s.setVariableValue(reflect.TypeOf(cnf.Inc), reflect.ValueOf(&cnf.Inc).Elem(), v.Name, value) + var object *config.Inc + if v.IsGlobal { + object = &cnf.Inc + } else { + object = &s.Inc + } + err = s.setVariableValue(reflect.TypeOf(*object), reflect.ValueOf(object).Elem(), v.Name, value) if err != nil { return nil, err } - - // 错误信息语言设置 - if prefix == "lang" { - SetLanguage(value.GetString()) - } } } @@ -6060,10 +6102,6 @@ func (s *session) executeInceptionSet(node *ast.InceptionSetStmt, sql string) ([ func (s *session) setVariableValue(t reflect.Type, values reflect.Value, name string, value *ast.ValueExpr) error { - // t := reflect.TypeOf(*(obj)) - // // values := reflect.ValueOf(obj).Elem() - // values := reflect.ValueOf(obj).Elem() - found := false for i := 0; i < values.NumField(); i++ { if values.Field(i).CanInterface() { //判断是否为可导出字段 @@ -6333,7 +6371,7 @@ func splitWhere(where ast.ExprNode) []ast.ExprNode { } // checkColumnName: 检查列是否存在 -func checkColumnName(expr ast.ExprNode, colNames []string) (colIndex int, err error) { +func (s *session) checkColumnName(expr ast.ExprNode, colNames []string) (colIndex int, err error) { colIndex = -1 if e, ok := expr.(*ast.ColumnNameExpr); ok { found := false @@ -6344,19 +6382,19 @@ func checkColumnName(expr ast.ExprNode, colNames []string) (colIndex int, err er } } if !found { - return colIndex, errors.New(fmt.Sprintf(GetErrorMessage(ER_COLUMN_NOT_EXISTED), e.Name.Name.String())) + return colIndex, errors.New(fmt.Sprintf(s.getErrorMessage(ER_COLUMN_NOT_EXISTED), e.Name.Name.String())) } } return colIndex, nil } // filterExprNode: 条件筛选 -func filterExprNode(expr ast.ExprNode, colNames []string, values []string) (bool, error) { +func (s *session) filterExprNode(expr ast.ExprNode, colNames []string, values []string) (bool, error) { switch x := expr.(type) { case *ast.BinaryOperationExpr: switch x.Op { case opcode.EQ: - colIndex, err := checkColumnName(x.L, colNames) + colIndex, err := s.checkColumnName(x.L, colNames) if err != nil { return false, err } @@ -6373,7 +6411,7 @@ func filterExprNode(expr ast.ExprNode, colNames []string, values []string) (bool return false, errors.New("不支持的操作") } case *ast.PatternLikeExpr: - colIndex, err := checkColumnName(x.Expr, colNames) + colIndex, err := s.checkColumnName(x.Expr, colNames) if err != nil { return false, err } @@ -6398,9 +6436,9 @@ func filterExprNode(expr ast.ExprNode, colNames []string, values []string) (bool } // filter: 条件筛选 -func filter(expr []ast.ExprNode, colNames []string, value []string) (bool, error) { +func (s *session) filter(expr []ast.ExprNode, colNames []string, value []string) (bool, error) { for _, e := range expr { - ok, err := filterExprNode(e, colNames, value) + ok, err := s.filterExprNode(e, colNames, value) if err != nil { return false, err } @@ -6437,8 +6475,8 @@ func (s *session) executeLocalShowLevels(node *ast.ShowStmt) ([]sqlexec.RecordSe name := code.String() if v, ok := s.incLevel[name]; ok { if len(filters) > 0 { - ok, err := filter(filters, names, []string{ - name, strconv.Itoa(int(v)), GetErrorMessage(code), + ok, err := s.filter(filters, names, []string{ + name, strconv.Itoa(int(v)), s.getErrorMessage(code), }) if err != nil { return nil, err @@ -6447,58 +6485,14 @@ func (s *session) executeLocalShowLevels(node *ast.ShowStmt) ([]sqlexec.RecordSe continue } } - res.Append(name, int64(v), GetErrorMessage(code)) - - // if len(like) == 0 { - // if len(filters) > 0 { - // ok, err := filter(filters, names, []string{ - // name, string(v), GetErrorMessage(code), - // }) - // if err != nil { - // return nil, err - // } - // if !ok { - // continue - // } - // } - - // res.Append(name, int64(v), GetErrorMessage(code)) - // } else { - // match := stringutil.DoMatch(name, patChars, patTypes) - // if match && !node.Pattern.Not { - // if len(filters) > 0 { - // ok, err := filter(filters, names, []string{ - // name, string(v), GetErrorMessage(code), - // }) - // if err != nil { - // return nil, err - // } - // if !ok { - // continue - // } - // } - // res.Append(name, int64(v), GetErrorMessage(code)) - // } else if !match && node.Pattern.Not { - // if len(filters) > 0 { - // ok, err := filter(filters, names, []string{ - // name, string(v), GetErrorMessage(code), - // }) - // if err != nil { - // return nil, err - // } - // if !ok { - // continue - // } - // } - // res.Append(name, int64(v), GetErrorMessage(code)) - // } - // } + res.Append(name, int64(v), s.getErrorMessage(code)) } } s.sessionVars.StmtCtx.AddAffectedRows(uint64(res.rc.count)) return res.Rows(), nil } + func (s *session) executeLocalShowOscProcesslist(node *ast.ShowOscStmt) ([]sqlexec.RecordSet, error) { pl := s.sessionManager.ShowOscProcessList() @@ -6886,7 +6880,7 @@ func (s *session) getExplainInfo(sql string, sqlId string) { s.AppendErrorNo(ER_UDPATE_TOO_MUCH_ROWS, r.AffectedRows, s.Inc.MaxUpdateRows) if newRecord != nil { - newRecord.AppendErrorNo(ER_UDPATE_TOO_MUCH_ROWS, + newRecord.AppendErrorNo(s.Inc.Lang, ER_UDPATE_TOO_MUCH_ROWS, r.AffectedRows, s.Inc.MaxUpdateRows) } } @@ -6938,9 +6932,6 @@ func (s *session) getRealRowCount(sql string, sqlId string) { } } - // log.Info(sql) - // log.Info(value) - r.AffectedRows = value // if newRecord != nil { // newRecord.AffectedRows = r.AffectedRows @@ -7186,9 +7177,6 @@ func (s *session) checkUpdate(node *ast.UpdateStmt, sql string) { s.checkItem(l.Expr, tableInfoList) } - // log.Infof("%#v", node.TableRefs) - // log.Infof("%#v", node.TableRefs.TableRefs) - s.checkSelectItem(node.TableRefs.TableRefs, node.Where != nil) // if node.TableRefs.TableRefs.On != nil { // s.checkItem(node.TableRefs.TableRefs.On.Expr, tableInfoList) @@ -7660,25 +7648,25 @@ func (r *Record) AppendErrorMessage(msg string) { r.Buf.WriteString("\n") } -func (r *Record) AppendErrorNo(number ErrorCode, values ...interface{}) { +func (r *Record) AppendErrorNo(lang string, number ErrorCode, values ...interface{}) { r.ErrLevel = uint8(Max(int(r.ErrLevel), int(GetErrorLevel(number)))) if len(values) == 0 { - r.Buf.WriteString(GetErrorMessage(number)) + r.Buf.WriteString(GetErrorMessage(number, lang)) } else { - r.Buf.WriteString(fmt.Sprintf(GetErrorMessage(number), values...)) + r.Buf.WriteString(fmt.Sprintf(GetErrorMessage(number, lang), values...)) } r.Buf.WriteString("\n") } // AppendWarning 添加警告. 错误级别指定为警告 -func (r *Record) AppendWarning(number ErrorCode, values ...interface{}) { +func (r *Record) AppendWarning(lang string, number ErrorCode, values ...interface{}) { r.ErrLevel = uint8(Max(int(r.ErrLevel), 1)) if len(values) == 0 { - r.Buf.WriteString(GetErrorMessage(number)) + r.Buf.WriteString(GetErrorMessage(number, lang)) } else { - r.Buf.WriteString(fmt.Sprintf(GetErrorMessage(number), values...)) + r.Buf.WriteString(fmt.Sprintf(GetErrorMessage(number, lang), values...)) } r.Buf.WriteString("\n") } @@ -7701,7 +7689,7 @@ func (s *session) AppendWarning(number ErrorCode, values ...interface{}) { } else if s.stage == StageExec { s.myRecord.Buf.WriteString("Execute: ") } - s.myRecord.AppendWarning(number, values...) + s.myRecord.AppendWarning(s.Inc.Lang, number, values...) s.recordSets.MaxLevel = uint8(Max(int(s.recordSets.MaxLevel), int(s.myRecord.ErrLevel))) } @@ -7729,9 +7717,9 @@ func (s *session) AppendErrorNo(number ErrorCode, values ...interface{}) { r.Buf.WriteString("Execute: ") } if len(values) == 0 { - r.Buf.WriteString(GetErrorMessage(number)) + r.Buf.WriteString(s.getErrorMessage(number)) } else { - r.Buf.WriteString(fmt.Sprintf(GetErrorMessage(number), values...)) + r.Buf.WriteString(fmt.Sprintf(s.getErrorMessage(number), values...)) } r.Buf.WriteString("\n") } @@ -8582,3 +8570,8 @@ func (s *session) checkSetStmt(node *ast.SetStmt) { func (s *session) IgnoreCase() bool { return s.LowerCaseTableNames > 0 } + +// getErrorMessage 获取审核信息 +func (s *session) getErrorMessage(code ErrorCode) string { + return GetErrorMessage(code, s.Inc.Lang) +} diff --git a/session/session_inception_common_test.go b/session/session_inception_common_test.go index 61d3115e2..fb44e756f 100644 --- a/session/session_inception_common_test.go +++ b/session/session_inception_common_test.go @@ -138,8 +138,6 @@ func (s *testCommon) initSetUp(c *C) { inc.SqlSafeUpdates = 0 inc.EnableDropTable = true - session.SetLanguage("en-US") - s.defaultInc = *inc s.remoteBackupTable = "$_$Inception_backup_information$_$" diff --git a/session/session_inception_print_test.go b/session/session_inception_print_test.go index 6ffdc8544..adb053717 100644 --- a/session/session_inception_print_test.go +++ b/session/session_inception_print_test.go @@ -39,12 +39,9 @@ func (s *testSessionPrintSuite) SetUpSuite(c *C) { s.initSetUp(c) - // config.GetGlobalConfig().Inc.Lang = "zh-CN" - // session.SetLanguage("zh-CN") config.GetGlobalConfig().Inc.Lang = "en-US" config.GetGlobalConfig().Inc.EnableFingerprint = true config.GetGlobalConfig().Inc.SqlSafeUpdates = 0 - session.SetLanguage("en-US") if s.tk == nil { s.tk = testkit.NewTestKitWithInit(c, s.store) diff --git a/session/session_inception_split_test.go b/session/session_inception_split_test.go index 215fbfdfb..d7b6e60ef 100644 --- a/session/session_inception_split_test.go +++ b/session/session_inception_split_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/hanchuanchuan/goInception/config" - "github.com/hanchuanchuan/goInception/session" "github.com/hanchuanchuan/goInception/util/testkit" . "github.com/pingcap/check" ) @@ -40,12 +39,9 @@ func (s *testSessionSplitSuite) SetUpSuite(c *C) { s.initSetUp(c) - // config.GetGlobalConfig().Inc.Lang = "zh-CN" - // session.SetLanguage("zh-CN") config.GetGlobalConfig().Inc.Lang = "en-US" config.GetGlobalConfig().Inc.EnableFingerprint = true config.GetGlobalConfig().Inc.SqlSafeUpdates = 0 - session.SetLanguage("en-US") if s.tk == nil { s.tk = testkit.NewTestKitWithInit(c, s.store) diff --git a/session/session_inception_test.go b/session/session_inception_test.go index 848cb2c0c..09e331f4d 100644 --- a/session/session_inception_test.go +++ b/session/session_inception_test.go @@ -105,6 +105,43 @@ func (s *testSessionIncSuite) testErrorCode(c *C, sql string, errors ...*session s.rows = res.Rows() } +func (s *testSessionIncSuite) testSQLError(c *C, sql string, errors ...*session.SQLError) { + if s.tk == nil { + s.tk = testkit.NewTestKitWithInit(c, s.store) + } + + res := s.runCheck(sql) + + errCode := 0 + if len(errors) > 0 { + for _, e := range errors { + level := session.GetErrorLevel(e.Code) + if int(level) > errCode { + errCode = int(level) + } + } + } + + allErrors := []string{} + for _, row := range res.Rows()[1:] { + if v, ok := row[4].(string); ok { + allErrors = append(allErrors, strings.TrimSpace(v)) + } + } + + errMsgs := []string{} + for _, e := range errors { + errMsgs = append(errMsgs, e.Error()) + } + + c.Assert(len(errMsgs), Equals, len(allErrors), Commentf("%v", res.Rows())) + + for index, err := range allErrors { + c.Assert(err, Equals, errMsgs[index], Commentf("%v", res.Rows())) + } + +} + func (s *testSessionIncSuite) testAffectedRows(c *C, affectedRows ...int) { if len(s.rows) == 0 { return @@ -2716,3 +2753,43 @@ func (s *testSessionIncSuite) TestDisplayWidth(c *C) { session.NewErrf("Too big display width for column '%s' (max = 255).", "c1")) } + +// TestSetVariables 设置会话级变量进行审核 +func (s *testSessionIncSuite) TestSetSessionVariables(c *C) { + sql := "" + + s.mustRunExec(c, "drop table if exists t1;") + + config.GetGlobalConfig().Inc.CheckTableComment = true + sql = `create table t1(id int primary key);` + s.testErrorCode(c, sql, + session.NewErr(session.ER_TABLE_MUST_HAVE_COMMENT, "t1")) + + sql = `inception set check_table_comment = 0; + create table t1(id int primary key);` + s.testErrorCode(c, sql) + + sql = `inception set check_table_comment = "123"; + create table t1(id int primary key);` + + s.testSQLError(c, sql, + session.NewErrf("[variable:1231]Variable 'check_table_comment' can't be set to the value of '123'."), + session.NewErr(session.ER_TABLE_MUST_HAVE_COMMENT, "t1")) + + sql = `inception set level er_table_must_have_comment = 2;` + s.testSQLError(c, sql, + session.NewErrf("暂不支持会话级的自定义审核级别.")) + + sql = `inception set global check_table_comment = 1;` + s.testSQLError(c, sql, + session.NewErrf("全局变量仅支持单独设置.")) + + sql = `inception set lang = 'zh_cn'; + create table t1(id int primary key); + inception set lang = 'en_us'; + create table t2(id int primary key);` + s.testSQLError(c, sql, + session.NewErrf("表 't1' 需要设置注释."), + session.NewErrf("Set comments for table 't2'.")) + +} diff --git a/session/tidb_check.go b/session/tidb_check.go index 35bb64e3c..a9b3b959a 100644 --- a/session/tidb_check.go +++ b/session/tidb_check.go @@ -64,7 +64,7 @@ func (s *session) checkAutoIncrement(stmt *ast.CreateTableStmt) { for _, colDef := range stmt.Cols { var hasAutoIncrement bool for i, op := range colDef.Options { - ok, err := checkAutoIncrementOp(colDef, i) + ok, err := s.checkAutoIncrementOp(colDef, i) if err != nil { s.AppendErrorMessage(err.Error()) // return @@ -125,7 +125,7 @@ func isConstraintKeyTp(constraints []*ast.Constraint, colDef *ast.ColumnDef) boo return false } -func checkAutoIncrementOp(colDef *ast.ColumnDef, num int) (bool, error) { +func (s *session) checkAutoIncrementOp(colDef *ast.ColumnDef, num int) (bool, error) { var hasAutoIncrement bool if colDef.Options[num].Tp == ast.ColumnOptionAutoIncrement { @@ -136,7 +136,7 @@ func checkAutoIncrementOp(colDef *ast.ColumnDef, num int) (bool, error) { for _, op := range colDef.Options[num+1:] { if op.Tp == ast.ColumnOptionDefaultValue && !op.Expr.GetDatum().IsNull() { return hasAutoIncrement, - errors.Errorf(fmt.Sprintf(GetErrorMessage(ER_INVALID_DEFAULT), colDef.Name.Name.O)) + errors.Errorf(fmt.Sprintf(s.getErrorMessage(ER_INVALID_DEFAULT), colDef.Name.Name.O)) } } } @@ -147,7 +147,7 @@ func checkAutoIncrementOp(colDef *ast.ColumnDef, num int) (bool, error) { for _, op := range colDef.Options[num+1:] { if op.Tp == ast.ColumnOptionAutoIncrement { return hasAutoIncrement, - errors.Errorf(fmt.Sprintf(GetErrorMessage(ER_INVALID_DEFAULT), colDef.Name.Name.O)) + errors.Errorf(fmt.Sprintf(s.getErrorMessage(ER_INVALID_DEFAULT), colDef.Name.Name.O)) } } } diff --git a/tidb-server/main.go b/tidb-server/main.go index ee1dc3dba..ebff3ee4c 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -336,9 +336,6 @@ func setGlobalVars() { statsLeaseDuration := parseDuration(cfg.Performance.StatsLease) session.SetStatsLease(statsLeaseDuration) - // 设置错误信息语言 - session.SetLanguage(cfg.Inc.Lang) - domain.RunAutoAnalyze = cfg.Performance.RunAutoAnalyze statistics.FeedbackProbability = cfg.Performance.FeedbackProbability statistics.MaxQueryFeedbackCount = int(cfg.Performance.QueryFeedbackLimit)