github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/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 informations. 17 const ( 18 TypeDecimal byte = iota 19 TypeTiny 20 TypeShort 21 TypeLong 22 TypeFloat 23 TypeDouble 24 TypeNull 25 TypeTimestamp 26 TypeLonglong 27 TypeInt24 28 TypeDate 29 TypeDuration /* Original name was TypeTime, renamed to Duration to resolve the conflict with Go type Time.*/ 30 TypeDatetime 31 TypeYear 32 TypeNewDate 33 TypeVarchar 34 TypeBit 35 ) 36 37 // TypeUnspecified is an uninitialized type. TypeDecimal is not used in MySQL. 38 var TypeUnspecified = TypeDecimal 39 40 // MySQL type informations. 41 const ( 42 TypeNewDecimal byte = iota + 0xf6 43 TypeEnum 44 TypeSet 45 TypeTinyBlob 46 TypeMediumBlob 47 TypeLongBlob 48 TypeBlob 49 TypeVarString 50 TypeString 51 TypeGeometry 52 ) 53 54 // IsUninitializedType check if a type code is uninitialized. 55 // TypeDecimal is the old type code for decimal and not be used in the new mysql version. 56 func IsUninitializedType(tp byte) bool { 57 return tp == TypeDecimal 58 } 59 60 // Flag informations. 61 const ( 62 NotNullFlag = 1 /* Field can't be NULL */ 63 PriKeyFlag = 2 /* Field is part of a primary key */ 64 UniqueKeyFlag = 4 /* Field is part of a unique key */ 65 MultipleKeyFlag = 8 /* Field is part of a key */ 66 BlobFlag = 16 /* Field is a blob */ 67 UnsignedFlag = 32 /* Field is unsigned */ 68 ZerofillFlag = 64 /* Field is zerofill */ 69 BinaryFlag = 128 /* Field is binary */ 70 71 EnumFlag = 256 /* Field is an enum */ 72 AutoIncrementFlag = 512 /* Field is an auto increment field */ 73 TimestampFlag = 1024 /* Field is a timestamp */ 74 SetFlag = 2048 /* Field is a set */ 75 NoDefaultValueFlag = 4096 /* Field doesn't have a default value */ 76 OnUpdateNowFlag = 8192 /* Field is set to NOW on UPDATE */ 77 NumFlag = 32768 /* Field is a num (for clients) */ 78 PartKeyFlag = 16384 /* Intern: Part of some keys */ 79 GroupFlag = 32768 /* Intern: Group field */ 80 UniqueFlag = 65536 /* Intern: Used by sql_yacc */ 81 BinCmpFlag = 131072 /* Intern: Used by sql_yacc */ 82 ) 83 84 // TypeInt24 bounds. 85 const ( 86 MaxUint24 = 1<<24 - 1 87 MaxInt24 = 1<<23 - 1 88 MinInt24 = -1 << 23 89 ) 90 91 // HasNotNullFlag checks if NotNullFlag is set. 92 func HasNotNullFlag(flag uint) bool { 93 return (flag & NotNullFlag) > 0 94 } 95 96 // HasNoDefaultValueFlag checks if NoDefaultValueFlag is set. 97 func HasNoDefaultValueFlag(flag uint) bool { 98 return (flag & NoDefaultValueFlag) > 0 99 } 100 101 // HasAutoIncrementFlag checks if AutoIncrementFlag is set. 102 func HasAutoIncrementFlag(flag uint) bool { 103 return (flag & AutoIncrementFlag) > 0 104 } 105 106 // HasUnsignedFlag checks if UnsignedFlag is set. 107 func HasUnsignedFlag(flag uint) bool { 108 return (flag & UnsignedFlag) > 0 109 } 110 111 // HasZerofillFlag checks if ZerofillFlag is set. 112 func HasZerofillFlag(flag uint) bool { 113 return (flag & ZerofillFlag) > 0 114 } 115 116 // HasBinaryFlag checks if BinaryFlag is set. 117 func HasBinaryFlag(flag uint) bool { 118 return (flag & BinaryFlag) > 0 119 } 120 121 // HasPriKeyFlag checks if PriKeyFlag is set. 122 func HasPriKeyFlag(flag uint) bool { 123 return (flag & PriKeyFlag) > 0 124 } 125 126 // HasUniKeyFlag checks if UniqueKeyFlag is set. 127 func HasUniKeyFlag(flag uint) bool { 128 return (flag & UniqueKeyFlag) > 0 129 } 130 131 // HasMultipleKeyFlag checks if MultipleKeyFlag is set. 132 func HasMultipleKeyFlag(flag uint) bool { 133 return (flag & MultipleKeyFlag) > 0 134 } 135 136 // HasTimestampFlag checks if HasTimestampFlag is set. 137 func HasTimestampFlag(flag uint) bool { 138 return (flag & TimestampFlag) > 0 139 } 140 141 // HasOnUpdateNowFlag checks if OnUpdateNowFlag is set. 142 func HasOnUpdateNowFlag(flag uint) bool { 143 return (flag & OnUpdateNowFlag) > 0 144 }