Example #1
0
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
	"github.com/pingcap/tidb/mysql"
	"github.com/pingcap/tidb/terror"
)

var (
	// ErrDataTooLong is returned when converts a string value that is longer than field type length.
	ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long")
)

const (
	codeDataTooLong terror.ErrCode = terror.ErrCode(mysql.ErrDataTooLong)
)

func init() {
	typesMySQLErrCodes := map[terror.ErrCode]uint16{
		codeDataTooLong: mysql.ErrDataTooLong,
	}
	terror.ErrClassToMySQLCodes[terror.ClassTypes] = typesMySQLErrCodes
}
Example #2
0
	// ErrDataTooLong is returned when converts a string value that is longer than field type length.
	ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long")
	// ErrTruncated is returned when data has been truncated during convertion.
	ErrTruncated = terror.ClassTypes.New(codeTruncated, "Data Truncated")
	// ErrOverflow is returned when data is out of range for a field type.
	ErrOverflow = terror.ClassTypes.New(codeOverflow, "Data Out Of Range")
	// ErrDivByZero is return when do division by 0.
	ErrDivByZero = terror.ClassTypes.New(codeDivByZero, "Division by 0")
	// ErrBadNumber is return when parsing an invalid binary decimal number.
	ErrBadNumber = terror.ClassTypes.New(codeBadNumber, "Bad Number")
)

const (
	codeBadNumber terror.ErrCode = 1

	codeDataTooLong terror.ErrCode = terror.ErrCode(mysql.ErrDataTooLong)
	codeTruncated   terror.ErrCode = terror.ErrCode(mysql.WarnDataTruncated)
	codeOverflow    terror.ErrCode = terror.ErrCode(mysql.ErrWarnDataOutOfRange)
	codeDivByZero   terror.ErrCode = terror.ErrCode(mysql.ErrDivisionByZero)
)

func init() {
	typesMySQLErrCodes := map[terror.ErrCode]uint16{
		codeDataTooLong: mysql.ErrDataTooLong,
		codeTruncated:   mysql.WarnDataTruncated,
		codeOverflow:    mysql.ErrWarnDataOutOfRange,
		codeDivByZero:   mysql.ErrDivisionByZero,
	}
	terror.ErrClassToMySQLCodes[terror.ClassTypes] = typesMySQLErrCodes
}