github.com/XiaoMi/Gaea@v1.2.5/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 TypeDecimal byte = 0 19 TypeTiny byte = 1 20 TypeShort byte = 2 21 TypeLong byte = 3 22 TypeFloat byte = 4 23 TypeDouble byte = 5 24 TypeNull byte = 6 25 TypeTimestamp byte = 7 26 TypeLonglong byte = 8 27 TypeInt24 byte = 9 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 47 TypeGeometry byte = 0xff 48 ) 49 50 // TypeUnspecified is an uninitialized type. TypeDecimal is not used in MySQL. 51 const TypeUnspecified = TypeDecimal 52 53 // Flag information. 54 const ( 55 NotNullFlag uint = 1 << 0 /* Field can't be NULL */ 56 PriKeyFlag uint = 1 << 1 /* Field is part of a primary key */ 57 UniqueKeyFlag uint = 1 << 2 /* Field is part of a unique key */ 58 MultipleKeyFlag uint = 1 << 3 /* Field is part of a key */ 59 BlobFlag uint = 1 << 4 /* Field is a blob */ 60 UnsignedFlag uint = 1 << 5 /* Field is unsigned */ 61 ZerofillFlag uint = 1 << 6 /* Field is zerofill */ 62 BinaryFlag uint = 1 << 7 /* Field is binary */ 63 EnumFlag uint = 1 << 8 /* Field is an enum */ 64 AutoIncrementFlag uint = 1 << 9 /* Field is an auto increment field */ 65 TimestampFlag uint = 1 << 10 /* Field is a timestamp */ 66 SetFlag uint = 1 << 11 /* Field is a set */ 67 NoDefaultValueFlag uint = 1 << 12 /* Field doesn't have a default value */ 68 OnUpdateNowFlag uint = 1 << 13 /* Field is set to NOW on UPDATE */ 69 PartKeyFlag uint = 1 << 14 /* Intern: Part of some keys */ 70 NumFlag uint = 1 << 15 /* Field is a num (for clients) */ 71 72 GroupFlag uint = 1 << 15 /* Internal: Group field */ 73 UniqueFlag uint = 1 << 16 /* Internal: Used by sql_yacc */ 74 BinCmpFlag uint = 1 << 17 /* Internal: Used by sql_yacc */ 75 ParseToJSONFlag uint = 1 << 18 /* Internal: Used when we want to parse string to JSON in CAST */ 76 IsBooleanFlag uint = 1 << 19 /* Internal: Used for telling boolean literal from integer */ 77 PreventNullInsertFlag uint = 1 << 20 /* Prevent this Field from inserting NULL values */ 78 ) 79 80 // TypeInt24 bounds. 81 const ( 82 MaxUint24 = 1<<24 - 1 83 MaxInt24 = 1<<23 - 1 84 MinInt24 = -1 << 23 85 ) 86 87 // HasNotNullFlag checks if NotNullFlag is set. 88 func HasNotNullFlag(flag uint) bool { 89 return (flag & NotNullFlag) > 0 90 } 91 92 // HasNoDefaultValueFlag checks if NoDefaultValueFlag is set. 93 func HasNoDefaultValueFlag(flag uint) bool { 94 return (flag & NoDefaultValueFlag) > 0 95 } 96 97 // HasAutoIncrementFlag checks if AutoIncrementFlag is set. 98 func HasAutoIncrementFlag(flag uint) bool { 99 return (flag & AutoIncrementFlag) > 0 100 } 101 102 // HasUnsignedFlag checks if UnsignedFlag is set. 103 func HasUnsignedFlag(flag uint) bool { 104 return (flag & UnsignedFlag) > 0 105 } 106 107 // HasZerofillFlag checks if ZerofillFlag is set. 108 func HasZerofillFlag(flag uint) bool { 109 return (flag & ZerofillFlag) > 0 110 } 111 112 // HasBinaryFlag checks if BinaryFlag is set. 113 func HasBinaryFlag(flag uint) bool { 114 return (flag & BinaryFlag) > 0 115 } 116 117 // HasPriKeyFlag checks if PriKeyFlag is set. 118 func HasPriKeyFlag(flag uint) bool { 119 return (flag & PriKeyFlag) > 0 120 } 121 122 // HasUniKeyFlag checks if UniqueKeyFlag is set. 123 func HasUniKeyFlag(flag uint) bool { 124 return (flag & UniqueKeyFlag) > 0 125 } 126 127 // HasMultipleKeyFlag checks if MultipleKeyFlag is set. 128 func HasMultipleKeyFlag(flag uint) bool { 129 return (flag & MultipleKeyFlag) > 0 130 } 131 132 // HasTimestampFlag checks if HasTimestampFlag is set. 133 func HasTimestampFlag(flag uint) bool { 134 return (flag & TimestampFlag) > 0 135 } 136 137 // HasOnUpdateNowFlag checks if OnUpdateNowFlag is set. 138 func HasOnUpdateNowFlag(flag uint) bool { 139 return (flag & OnUpdateNowFlag) > 0 140 } 141 142 // HasParseToJSONFlag checks if ParseToJSONFlag is set. 143 func HasParseToJSONFlag(flag uint) bool { 144 return (flag & ParseToJSONFlag) > 0 145 } 146 147 // HasIsBooleanFlag checks if IsBooleanFlag is set. 148 func HasIsBooleanFlag(flag uint) bool { 149 return (flag & IsBooleanFlag) > 0 150 } 151 152 // HasPreventNullInsertFlag checks if PreventNullInsertFlag is set. 153 func HasPreventNullInsertFlag(flag uint) bool { 154 return (flag & PreventNullInsertFlag) > 0 155 }