github.com/pingcap/tidb/parser@v0.0.0-20231013125129-93a834a6bf8d/mysql/type.go (about) 1 // Copyright 2015 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 mysql 15 16 // MySQL type information. 17 const ( 18 TypeUnspecified byte = 0 19 TypeTiny byte = 1 // TINYINT 20 TypeShort byte = 2 // SMALLINT 21 TypeLong byte = 3 // INT 22 TypeFloat byte = 4 23 TypeDouble byte = 5 24 TypeNull byte = 6 25 TypeTimestamp byte = 7 26 TypeLonglong byte = 8 // BIGINT 27 TypeInt24 byte = 9 // MEDIUMINT 28 TypeDate byte = 10 29 /* TypeDuration original name was TypeTime, renamed to TypeDuration to resolve the conflict with Go type Time.*/ 30 TypeDuration byte = 11 31 TypeDatetime byte = 12 32 TypeYear byte = 13 33 TypeNewDate byte = 14 34 TypeVarchar byte = 15 35 TypeBit byte = 16 36 37 TypeJSON byte = 0xf5 38 TypeNewDecimal byte = 0xf6 39 TypeEnum byte = 0xf7 40 TypeSet byte = 0xf8 41 TypeTinyBlob byte = 0xf9 42 TypeMediumBlob byte = 0xfa 43 TypeLongBlob byte = 0xfb 44 TypeBlob byte = 0xfc 45 TypeVarString byte = 0xfd 46 TypeString byte = 0xfe /* TypeString is char type */ 47 TypeGeometry byte = 0xff 48 ) 49 50 // Flag information. 51 const ( 52 NotNullFlag uint = 1 << 0 /* Field can't be NULL */ 53 PriKeyFlag uint = 1 << 1 /* Field is part of a primary key */ 54 UniqueKeyFlag uint = 1 << 2 /* Field is part of a unique key */ 55 MultipleKeyFlag uint = 1 << 3 /* Field is part of a key */ 56 BlobFlag uint = 1 << 4 /* Field is a blob */ 57 UnsignedFlag uint = 1 << 5 /* Field is unsigned */ 58 ZerofillFlag uint = 1 << 6 /* Field is zerofill */ 59 BinaryFlag uint = 1 << 7 /* Field is binary */ 60 EnumFlag uint = 1 << 8 /* Field is an enum */ 61 AutoIncrementFlag uint = 1 << 9 /* Field is an auto increment field */ 62 TimestampFlag uint = 1 << 10 /* Field is a timestamp */ 63 SetFlag uint = 1 << 11 /* Field is a set */ 64 NoDefaultValueFlag uint = 1 << 12 /* Field doesn't have a default value */ 65 OnUpdateNowFlag uint = 1 << 13 /* Field is set to NOW on UPDATE */ 66 PartKeyFlag uint = 1 << 14 /* Intern: Part of some keys */ 67 NumFlag uint = 1 << 15 /* Field is a num (for clients) */ 68 69 GroupFlag uint = 1 << 15 /* Internal: Group field */ 70 UniqueFlag uint = 1 << 16 /* Internal: Used by sql_yacc */ 71 BinCmpFlag uint = 1 << 17 /* Internal: Used by sql_yacc */ 72 ParseToJSONFlag uint = 1 << 18 /* Internal: Used when we want to parse string to JSON in CAST */ 73 IsBooleanFlag uint = 1 << 19 /* Internal: Used for telling boolean literal from integer */ 74 PreventNullInsertFlag uint = 1 << 20 /* Prevent this Field from inserting NULL values */ 75 EnumSetAsIntFlag uint = 1 << 21 /* Internal: Used for inferring enum eval type. */ 76 DropColumnIndexFlag uint = 1 << 22 /* Internal: Used for indicate the column is being dropped with index */ 77 GeneratedColumnFlag uint = 1 << 23 /* Internal: TiFlash will check this flag and add a placeholder for this column */ 78 UnderScoreCharsetFlag uint = 1 << 24 /* Internal: Indicate whether charset is specified by underscore like _latin1'abc' */ 79 ) 80 81 // TypeInt24 bounds. 82 const ( 83 MaxUint24 = 1<<24 - 1 84 MaxInt24 = 1<<23 - 1 85 MinInt24 = -1 << 23 86 ) 87 88 // HasDropColumnWithIndexFlag checks if DropColumnIndexFlag is set. 89 func HasDropColumnWithIndexFlag(flag uint) bool { 90 return (flag & DropColumnIndexFlag) > 0 91 } 92 93 // HasNotNullFlag checks if NotNullFlag is set. 94 func HasNotNullFlag(flag uint) bool { 95 return (flag & NotNullFlag) > 0 96 } 97 98 // HasNoDefaultValueFlag checks if NoDefaultValueFlag is set. 99 func HasNoDefaultValueFlag(flag uint) bool { 100 return (flag & NoDefaultValueFlag) > 0 101 } 102 103 // HasAutoIncrementFlag checks if AutoIncrementFlag is set. 104 func HasAutoIncrementFlag(flag uint) bool { 105 return (flag & AutoIncrementFlag) > 0 106 } 107 108 // HasUnsignedFlag checks if UnsignedFlag is set. 109 func HasUnsignedFlag(flag uint) bool { 110 return (flag & UnsignedFlag) > 0 111 } 112 113 // HasZerofillFlag checks if ZerofillFlag is set. 114 func HasZerofillFlag(flag uint) bool { 115 return (flag & ZerofillFlag) > 0 116 } 117 118 // HasBinaryFlag checks if BinaryFlag is set. 119 func HasBinaryFlag(flag uint) bool { 120 return (flag & BinaryFlag) > 0 121 } 122 123 // HasPriKeyFlag checks if PriKeyFlag is set. 124 func HasPriKeyFlag(flag uint) bool { 125 return (flag & PriKeyFlag) > 0 126 } 127 128 // HasUniKeyFlag checks if UniqueKeyFlag is set. 129 func HasUniKeyFlag(flag uint) bool { 130 return (flag & UniqueKeyFlag) > 0 131 } 132 133 // HasMultipleKeyFlag checks if MultipleKeyFlag is set. 134 func HasMultipleKeyFlag(flag uint) bool { 135 return (flag & MultipleKeyFlag) > 0 136 } 137 138 // HasTimestampFlag checks if HasTimestampFlag is set. 139 func HasTimestampFlag(flag uint) bool { 140 return (flag & TimestampFlag) > 0 141 } 142 143 // HasOnUpdateNowFlag checks if OnUpdateNowFlag is set. 144 func HasOnUpdateNowFlag(flag uint) bool { 145 return (flag & OnUpdateNowFlag) > 0 146 } 147 148 // HasParseToJSONFlag checks if ParseToJSONFlag is set. 149 func HasParseToJSONFlag(flag uint) bool { 150 return (flag & ParseToJSONFlag) > 0 151 } 152 153 // HasIsBooleanFlag checks if IsBooleanFlag is set. 154 func HasIsBooleanFlag(flag uint) bool { 155 return (flag & IsBooleanFlag) > 0 156 } 157 158 // HasPreventNullInsertFlag checks if PreventNullInsertFlag is set. 159 func HasPreventNullInsertFlag(flag uint) bool { 160 return (flag & PreventNullInsertFlag) > 0 161 } 162 163 // HasEnumSetAsIntFlag checks if EnumSetAsIntFlag is set. 164 func HasEnumSetAsIntFlag(flag uint) bool { 165 return (flag & EnumSetAsIntFlag) > 0 166 }