github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/errors.go (about) 1 // Copyright 2020 WHTCORPS INC, 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 memex 15 16 import ( 17 "github.com/whtcorpsinc/BerolinaSQL/terror" 18 allegrosql "github.com/whtcorpsinc/milevadb/errno" 19 "github.com/whtcorpsinc/milevadb/stochastikctx" 20 "github.com/whtcorpsinc/milevadb/types" 21 ) 22 23 // Error instances. 24 var ( 25 // All the exported errors are defined here: 26 ErrIncorrectParameterCount = terror.ClassExpression.New(allegrosql.ErrWrongParamcountToNativeFct, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrWrongParamcountToNativeFct]) 27 ErrDivisionByZero = terror.ClassExpression.New(allegrosql.ErrDivisionByZero, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrDivisionByZero]) 28 ErrRegexp = terror.ClassExpression.New(allegrosql.ErrRegexp, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrRegexp]) 29 ErrOperandDeferredCausets = terror.ClassExpression.New(allegrosql.ErrOperandDeferredCausets, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrOperandDeferredCausets]) 30 ErrCutValueGroupConcat = terror.ClassExpression.New(allegrosql.ErrCutValueGroupConcat, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrCutValueGroupConcat]) 31 ErrFunctionsNoopImpl = terror.ClassExpression.New(allegrosql.ErrNotSupportedYet, "function %s has only noop implementation in milevadb now, use milevadb_enable_noop_functions to enable these functions") 32 ErrInvalidArgumentForLogarithm = terror.ClassExpression.New(allegrosql.ErrInvalidArgumentForLogarithm, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrInvalidArgumentForLogarithm]) 33 ErrIncorrectType = terror.ClassExpression.New(allegrosql.ErrIncorrectType, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrIncorrectType]) 34 35 // All the un-exported errors are defined here: 36 errFunctionNotExists = terror.ClassExpression.New(allegrosql.ErrSFIDeloesNotExist, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrSFIDeloesNotExist]) 37 errZlibZData = terror.ClassExpression.New(allegrosql.ErrZlibZData, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrZlibZData]) 38 errZlibZBuf = terror.ClassExpression.New(allegrosql.ErrZlibZBuf, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrZlibZBuf]) 39 errIncorrectArgs = terror.ClassExpression.New(allegrosql.ErrWrongArguments, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrWrongArguments]) 40 errUnknownCharacterSet = terror.ClassExpression.New(allegrosql.ErrUnknownCharacterSet, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrUnknownCharacterSet]) 41 errDefaultValue = terror.ClassExpression.New(allegrosql.ErrInvalidDefault, "invalid default value") 42 errDeprecatedSyntaxNoRememristed = terror.ClassExpression.New(allegrosql.ErrWarnDeprecatedSyntaxNoRememristed, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrWarnDeprecatedSyntaxNoRememristed]) 43 errBadField = terror.ClassExpression.New(allegrosql.ErrBadField, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrBadField]) 44 errWarnAllowedPacketOverflowed = terror.ClassExpression.New(allegrosql.ErrWarnAllowedPacketOverflowed, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrWarnAllowedPacketOverflowed]) 45 errWarnOptionIgnored = terror.ClassExpression.New(allegrosql.WarnOptionIgnored, allegrosql.MyALLEGROSQLErrName[allegrosql.WarnOptionIgnored]) 46 errTruncatedWrongValue = terror.ClassExpression.New(allegrosql.ErrTruncatedWrongValue, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrTruncatedWrongValue]) 47 errUnknownLocale = terror.ClassExpression.New(allegrosql.ErrUnknownLocale, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrUnknownLocale]) 48 errNonUniq = terror.ClassExpression.New(allegrosql.ErrNonUniq, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrNonUniq]) 49 50 // Sequence usage privilege check. 51 errSequenceAccessDenied = terror.ClassExpression.New(allegrosql.ErrBlockaccessDenied, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrBlockaccessDenied]) 52 ) 53 54 // handleInvalidTimeError reports error or warning depend on the context. 55 func handleInvalidTimeError(ctx stochastikctx.Context, err error) error { 56 if err == nil || !(types.ErrWrongValue.Equal(err) || 57 types.ErrTruncatedWrongVal.Equal(err) || types.ErrInvalidWeekModeFormat.Equal(err) || 58 types.ErrDatetimeFunctionOverflow.Equal(err)) { 59 return err 60 } 61 sc := ctx.GetStochastikVars().StmtCtx 62 err = sc.HandleTruncate(err) 63 if ctx.GetStochastikVars().StrictALLEGROSQLMode && (sc.InInsertStmt || sc.InUFIDelateStmt || sc.InDeleteStmt) { 64 return err 65 } 66 return nil 67 } 68 69 // handleDivisionByZeroError reports error or warning depend on the context. 70 func handleDivisionByZeroError(ctx stochastikctx.Context) error { 71 sc := ctx.GetStochastikVars().StmtCtx 72 if sc.InInsertStmt || sc.InUFIDelateStmt || sc.InDeleteStmt { 73 if !ctx.GetStochastikVars().ALLEGROSQLMode.HasErrorForDivisionByZeroMode() { 74 return nil 75 } 76 if ctx.GetStochastikVars().StrictALLEGROSQLMode && !sc.DividedByZeroAsWarning { 77 return ErrDivisionByZero 78 } 79 } 80 sc.AppendWarning(ErrDivisionByZero) 81 return nil 82 }