github.com/XiaoMi/Gaea@v1.2.5/parser/tidb-types/errors.go (about) 1 // Copyright 2016 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package types 15 16 import ( 17 "github.com/XiaoMi/Gaea/mysql" 18 "github.com/XiaoMi/Gaea/parser/terror" 19 parser_types "github.com/XiaoMi/Gaea/parser/types" 20 ) 21 22 var ( 23 // ErrDataTooLong is returned when converts a string value that is longer than field type length. 24 ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long") 25 // ErrIllegalValueForType is returned when value of type is illegal. 26 ErrIllegalValueForType = terror.ClassTypes.New(codeIllegalValueForType, mysql.MySQLErrName[mysql.ErrIllegalValueForType]) 27 // ErrTruncated is returned when data has been truncated during conversion. 28 ErrTruncated = terror.ClassTypes.New(codeTruncated, "Data Truncated") 29 // ErrTruncatedWrongVal is returned when data has been truncated during conversion. 30 ErrTruncatedWrongVal = terror.ClassTypes.New(codeTruncatedWrongValue, msgTruncatedWrongVal) 31 // ErrOverflow is returned when data is out of range for a field type. 32 ErrOverflow = terror.ClassTypes.New(codeOverflow, msgOverflow) 33 // ErrDivByZero is return when do division by 0. 34 ErrDivByZero = terror.ClassTypes.New(codeDivByZero, "Division by 0") 35 // ErrTooBigDisplayWidth is return when display width out of range for column. 36 ErrTooBigDisplayWidth = terror.ClassTypes.New(codeTooBigDisplayWidth, "Too Big Display width") 37 // ErrTooBigFieldLength is return when column length too big for column. 38 ErrTooBigFieldLength = terror.ClassTypes.New(codeTooBigFieldLength, "Too Big Field length") 39 // ErrTooBigSet is returned when too many strings for column. 40 ErrTooBigSet = terror.ClassTypes.New(codeTooBigSet, "Too Big Set") 41 // ErrTooBigScale is returned when type DECIMAL/NUMERIC scale is bigger than mysql.MaxDecimalScale. 42 ErrTooBigScale = terror.ClassTypes.New(codeTooBigScale, mysql.MySQLErrName[mysql.ErrTooBigScale]) 43 // ErrTooBigPrecision is returned when type DECIMAL/NUMERIC precision is bigger than mysql.MaxDecimalWidth 44 ErrTooBigPrecision = terror.ClassTypes.New(codeTooBigPrecision, mysql.MySQLErrName[mysql.ErrTooBigPrecision]) 45 // ErrWrongFieldSpec is return when incorrect column specifier for column. 46 ErrWrongFieldSpec = terror.ClassTypes.New(codeWrongFieldSpec, "Wrong Field Spec") 47 // ErrBadNumber is return when parsing an invalid binary decimal number. 48 ErrBadNumber = terror.ClassTypes.New(codeBadNumber, "Bad Number") 49 // ErrInvalidDefault is returned when meet a invalid default value. 50 ErrInvalidDefault = parser_types.ErrInvalidDefault 51 // ErrCastAsSignedOverflow is returned when positive out-of-range integer, and convert to it's negative complement. 52 ErrCastAsSignedOverflow = terror.ClassTypes.New(codeUnknown, msgCastAsSignedOverflow) 53 // ErrCastNegIntAsUnsigned is returned when a negative integer be casted to an unsigned int. 54 ErrCastNegIntAsUnsigned = terror.ClassTypes.New(codeUnknown, msgCastNegIntAsUnsigned) 55 // ErrMBiggerThanD is returned when precision less than the scale. 56 ErrMBiggerThanD = terror.ClassTypes.New(codeMBiggerThanD, mysql.MySQLErrName[mysql.ErrMBiggerThanD]) 57 // ErrWarnDataOutOfRange is returned when the value in a numeric column that is outside the permissible range of the column data type. 58 // See https://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html for details 59 ErrWarnDataOutOfRange = terror.ClassTypes.New(codeDataOutOfRange, mysql.MySQLErrName[mysql.ErrWarnDataOutOfRange]) 60 // ErrDuplicatedValueInType is returned when enum column has duplicated value. 61 ErrDuplicatedValueInType = terror.ClassTypes.New(codeDuplicatedValueInType, mysql.MySQLErrName[mysql.ErrDuplicatedValueInType]) 62 ) 63 64 const ( 65 codeBadNumber terror.ErrCode = 1 66 67 codeDataTooLong = terror.ErrCode(mysql.ErrDataTooLong) 68 codeIllegalValueForType = terror.ErrCode(mysql.ErrIllegalValueForType) 69 codeTruncated = terror.ErrCode(mysql.WarnDataTruncated) 70 codeOverflow = terror.ErrCode(mysql.ErrDataOutOfRange) 71 codeDivByZero = terror.ErrCode(mysql.ErrDivisionByZero) 72 codeTooBigDisplayWidth = terror.ErrCode(mysql.ErrTooBigDisplaywidth) 73 codeTooBigFieldLength = terror.ErrCode(mysql.ErrTooBigFieldlength) 74 codeTooBigSet = terror.ErrCode(mysql.ErrTooBigSet) 75 codeTooBigScale = terror.ErrCode(mysql.ErrTooBigScale) 76 codeTooBigPrecision = terror.ErrCode(mysql.ErrTooBigPrecision) 77 codeWrongFieldSpec = terror.ErrCode(mysql.ErrWrongFieldSpec) 78 codeTruncatedWrongValue = terror.ErrCode(mysql.ErrTruncatedWrongValue) 79 codeUnknown = terror.ErrCode(mysql.ErrUnknown) 80 codeInvalidDefault = terror.ErrCode(mysql.ErrInvalidDefault) 81 codeMBiggerThanD = terror.ErrCode(mysql.ErrMBiggerThanD) 82 codeDataOutOfRange = terror.ErrCode(mysql.ErrWarnDataOutOfRange) 83 codeDuplicatedValueInType = terror.ErrCode(mysql.ErrDuplicatedValueInType) 84 ) 85 86 var ( 87 msgOverflow = mysql.MySQLErrName[mysql.ErrDataOutOfRange] 88 msgTruncatedWrongVal = mysql.MySQLErrName[mysql.ErrTruncatedWrongValue] 89 msgCastAsSignedOverflow = "Cast to signed converted positive out-of-range integer to it's negative complement" 90 msgCastNegIntAsUnsigned = "Cast to unsigned converted negative integer to it's positive complement" 91 ) 92 93 func init() { 94 typesMySQLErrCodes := map[terror.ErrCode]uint16{ 95 codeDataTooLong: mysql.ErrDataTooLong, 96 codeIllegalValueForType: mysql.ErrIllegalValueForType, 97 codeTruncated: mysql.WarnDataTruncated, 98 codeOverflow: mysql.ErrDataOutOfRange, 99 codeDivByZero: mysql.ErrDivisionByZero, 100 codeTooBigDisplayWidth: mysql.ErrTooBigDisplaywidth, 101 codeTooBigFieldLength: mysql.ErrTooBigFieldlength, 102 codeTooBigSet: mysql.ErrTooBigSet, 103 codeTooBigScale: mysql.ErrTooBigScale, 104 codeTooBigPrecision: mysql.ErrTooBigPrecision, 105 codeWrongFieldSpec: mysql.ErrWrongFieldSpec, 106 codeTruncatedWrongValue: mysql.ErrTruncatedWrongValue, 107 codeUnknown: mysql.ErrUnknown, 108 codeInvalidDefault: mysql.ErrInvalidDefault, 109 codeMBiggerThanD: mysql.ErrMBiggerThanD, 110 codeDataOutOfRange: mysql.ErrWarnDataOutOfRange, 111 codeDuplicatedValueInType: mysql.ErrDuplicatedValueInType, 112 } 113 terror.ErrClassToMySQLCodes[terror.ClassTypes] = typesMySQLErrCodes 114 }