github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqlparse/sqltypes/type.go (about) 1 /* 2 Copyright 2017 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package sqltypes 18 19 // This file provides wrappers and support 20 // functions for querypb.Type. 21 22 // These bit flags can be used to query on the 23 // common properties of types. 24 type Flag int32 25 26 const ( 27 Flag_NONE Flag = 0 28 Flag_ISINTEGRAL Flag = 256 29 Flag_ISUNSIGNED Flag = 512 30 Flag_ISFLOAT Flag = 1024 31 Flag_ISQUOTED Flag = 2048 32 Flag_ISTEXT Flag = 4096 33 Flag_ISBINARY Flag = 8192 34 ) 35 36 const ( 37 flagIsIntegral = int(Flag_ISINTEGRAL) 38 flagIsUnsigned = int(Flag_ISUNSIGNED) 39 flagIsFloat = int(Flag_ISFLOAT) 40 flagIsQuoted = int(Flag_ISQUOTED) 41 flagIsText = int(Flag_ISTEXT) 42 flagIsBinary = int(Flag_ISBINARY) 43 ) 44 45 // IsIntegral returns true if querypb.Type is an integral 46 // (signed/unsigned) that can be represented using 47 // up to 64 binary bits. 48 func IsIntegral(t Type) bool { 49 return int(t)&flagIsIntegral == flagIsIntegral 50 } 51 52 // IsSigned returns true if querypb.Type is a signed integral. 53 func IsSigned(t Type) bool { 54 return int(t)&(flagIsIntegral|flagIsUnsigned) == flagIsIntegral 55 } 56 57 // IsUnsigned returns true if querypb.Type is an unsigned integral. 58 // Caution: this is not the same as !IsSigned. 59 func IsUnsigned(t Type) bool { 60 return int(t)&(flagIsIntegral|flagIsUnsigned) == flagIsIntegral|flagIsUnsigned 61 } 62 63 // IsFloat returns true is querypb.Type is a floating point. 64 func IsFloat(t Type) bool { 65 return int(t)&flagIsFloat == flagIsFloat 66 } 67 68 // IsQuoted returns true if querypb.Type is a quoted text or binary. 69 func IsQuoted(t Type) bool { 70 return int(t)&flagIsQuoted == flagIsQuoted 71 } 72 73 // IsText returns true if querypb.Type is a text. 74 func IsText(t Type) bool { 75 return int(t)&flagIsText == flagIsText 76 } 77 78 // IsBinary returns true if querypb.Type is a binary. 79 func IsBinary(t Type) bool { 80 return int(t)&flagIsBinary == flagIsBinary 81 } 82 83 // IsNumber returns true if the type is any type of number. 84 func IsNumber(t Type) bool { 85 return IsIntegral(t) || IsFloat(t) || t == Decimal 86 } 87 88 type Type int32 89 90 const ( 91 // NULL_TYPE specifies a NULL type. 92 Type_NULL_TYPE Type = 0 93 // INT8 specifies a TINYINT type. 94 // Properties: 1, IsNumber. 95 Type_INT8 Type = 257 96 // UINT8 specifies a TINYINT UNSIGNED type. 97 // Properties: 2, IsNumber, IsUnsigned. 98 Type_UINT8 Type = 770 99 // INT16 specifies a SMALLINT type. 100 // Properties: 3, IsNumber. 101 Type_INT16 Type = 259 102 // UINT16 specifies a SMALLINT UNSIGNED type. 103 // Properties: 4, IsNumber, IsUnsigned. 104 Type_UINT16 Type = 772 105 // INT24 specifies a MEDIUMINT type. 106 // Properties: 5, IsNumber. 107 Type_INT24 Type = 261 108 // UINT24 specifies a MEDIUMINT UNSIGNED type. 109 // Properties: 6, IsNumber, IsUnsigned. 110 Type_UINT24 Type = 774 111 // INT32 specifies a INTEGER type. 112 // Properties: 7, IsNumber. 113 Type_INT32 Type = 263 114 // UINT32 specifies a INTEGER UNSIGNED type. 115 // Properties: 8, IsNumber, IsUnsigned. 116 Type_UINT32 Type = 776 117 // INT64 specifies a BIGINT type. 118 // Properties: 9, IsNumber. 119 Type_INT64 Type = 265 120 // UINT64 specifies a BIGINT UNSIGNED type. 121 // Properties: 10, IsNumber, IsUnsigned. 122 Type_UINT64 Type = 778 123 // FLOAT32 specifies a FLOAT type. 124 // Properties: 11, IsFloat. 125 Type_FLOAT32 Type = 1035 126 // FLOAT64 specifies a DOUBLE or REAL type. 127 // Properties: 12, IsFloat. 128 Type_FLOAT64 Type = 1036 129 // TIMESTAMP specifies a TIMESTAMP type. 130 // Properties: 13, IsQuoted. 131 Type_TIMESTAMP Type = 2061 132 // DATE specifies a DATE type. 133 // Properties: 14, IsQuoted. 134 Type_DATE Type = 2062 135 // TIME specifies a TIME type. 136 // Properties: 15, IsQuoted. 137 Type_TIME Type = 2063 138 // DATETIME specifies a DATETIME type. 139 // Properties: 16, IsQuoted. 140 Type_DATETIME Type = 2064 141 // YEAR specifies a YEAR type. 142 // Properties: 17, IsNumber, IsUnsigned. 143 Type_YEAR Type = 785 144 // DECIMAL specifies a DECIMAL or NUMERIC type. 145 // Properties: 18, None. 146 Type_DECIMAL Type = 18 147 // TEXT specifies a TEXT type. 148 // Properties: 19, IsQuoted, IsText. 149 Type_TEXT Type = 6163 150 // BLOB specifies a BLOB type. 151 // Properties: 20, IsQuoted, IsBinary. 152 Type_BLOB Type = 10260 153 // VARCHAR specifies a VARCHAR type. 154 // Properties: 21, IsQuoted, IsText. 155 Type_VARCHAR Type = 6165 156 // VARBINARY specifies a VARBINARY type. 157 // Properties: 22, IsQuoted, IsBinary. 158 Type_VARBINARY Type = 10262 159 // CHAR specifies a CHAR type. 160 // Properties: 23, IsQuoted, IsText. 161 Type_CHAR Type = 6167 162 // BINARY specifies a BINARY type. 163 // Properties: 24, IsQuoted, IsBinary. 164 Type_BINARY Type = 10264 165 // BIT specifies a BIT type. 166 // Properties: 25, IsQuoted. 167 Type_BIT Type = 2073 168 // ENUM specifies an ENUM type. 169 // Properties: 26, IsQuoted. 170 Type_ENUM Type = 2074 171 // SET specifies a SET type. 172 // Properties: 27, IsQuoted. 173 Type_SET Type = 2075 174 // TUPLE specifies a a tuple. This cannot 175 // be returned in a QueryResult, but it can 176 // be sent as a bind var. 177 // Properties: 28, None. 178 Type_TUPLE Type = 28 179 // GEOMETRY specifies a GEOMETRY type. 180 // Properties: 29, IsQuoted. 181 Type_GEOMETRY Type = 2077 182 // JSON specifies a JSON type. 183 // Properties: 30, IsQuoted. 184 Type_JSON Type = 2078 185 // EXPRESSION specifies a SQL expression. 186 // This type is for internal use only. 187 // Properties: 31, None. 188 Type_EXPRESSION Type = 31 189 ) 190 191 // Vitess data types. These are idiomatically 192 // named synonyms for the querypb.Type values. 193 const ( 194 Null = Type_NULL_TYPE 195 Int8 = Type_INT8 196 Uint8 = Type_UINT8 197 Int16 = Type_INT16 198 Uint16 = Type_UINT16 199 Int24 = Type_INT24 200 Uint24 = Type_UINT24 201 Int32 = Type_INT32 202 Uint32 = Type_UINT32 203 Int64 = Type_INT64 204 Uint64 = Type_UINT64 205 Float32 = Type_FLOAT32 206 Float64 = Type_FLOAT64 207 Timestamp = Type_TIMESTAMP 208 Date = Type_DATE 209 Time = Type_TIME 210 Datetime = Type_DATETIME 211 Year = Type_YEAR 212 Decimal = Type_DECIMAL 213 Text = Type_TEXT 214 Blob = Type_BLOB 215 VarChar = Type_VARCHAR 216 VarBinary = Type_VARBINARY 217 Char = Type_CHAR 218 Binary = Type_BINARY 219 Bit = Type_BIT 220 Enum = Type_ENUM 221 Set = Type_SET 222 Tuple = Type_TUPLE 223 Geometry = Type_GEOMETRY 224 TypeJSON = Type_JSON 225 Expression = Type_EXPRESSION 226 )