Documentation ¶
Overview ¶
Package sqltypes implements interfaces and types that represent SQL values.
Index ¶
- Constants
- Variables
- func IsBinary(t Type) bool
- func IsFloat(t Type) bool
- func IsIntegral(t Type) bool
- func IsQuoted(t Type) bool
- func IsSigned(t Type) bool
- func IsText(t Type) bool
- func IsUnsigned(t Type) bool
- type BinWriter
- type Flag
- type Type
- type Value
- func (v Value) Bytes() []byte
- func (v Value) EncodeASCII(b BinWriter)
- func (v Value) EncodeSQL(b BinWriter)
- func (v Value) Len() int
- func (v Value) ParseFloat64() (val float64, err error)
- func (v Value) ParseInt64() (val int64, err error)
- func (v Value) ParseUint64() (val uint64, err error)
- func (v Value) Raw() []byte
- func (v Value) String() string
- func (v Value) ToNative() interface{}
- func (v Value) Type() Type
Constants ¶
const ( Null = Type_NULL_TYPE Int8 = Type_INT8 Uint8 = Type_UINT8 Int16 = Type_INT16 Uint16 = Type_UINT16 Int24 = Type_INT24 Uint24 = Type_UINT24 Int32 = Type_INT32 Uint32 = Type_UINT32 Int64 = Type_INT64 Uint64 = Type_UINT64 Float32 = Type_FLOAT32 Float64 = Type_FLOAT64 Timestamp = Type_TIMESTAMP Date = Type_DATE Time = Type_TIME Datetime = Type_DATETIME Year = Type_YEAR Decimal = Type_DECIMAL Text = Type_TEXT Blob = Type_BLOB VarChar = Type_VARCHAR VarBinary = Type_VARBINARY Char = Type_CHAR Binary = Type_BINARY Bit = Type_BIT Enum = Type_ENUM Set = Type_SET Tuple = Type_TUPLE Geometry = Type_GEOMETRY TypeJSON = Type_JSON Expression = Type_EXPRESSION )
Vitess data types. These are idiomatically named synonyms for the querypb.Type values.
Variables ¶
var ( // NULL represents the NULL value. NULL = Value{} // DontEscape tells you if a character should not be escaped. DontEscape = byte(255) )
var SQLDecodeMap [256]int32
SQLDecodeMap is the reverse of SQLEncodeMap
var SQLEncodeMap [256]int32
SQLEncodeMap specifies how to escape binary data with '\'. Complies to http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html
Functions ¶
func IsIntegral ¶
IsIntegral returns true if querypb.Type is an integral (signed/unsigned) that can be represented using up to 64 binary bits.
func IsUnsigned ¶
IsUnsigned returns true if querypb.Type is an unsigned integral. Caution: this is not the same as !IsSigned.
Types ¶
type BinWriter ¶
BinWriter interface is used for encoding values. Types like bytes.Buffer conform to this interface. We expect the writer objects to be in-memory buffers. So, we don't expect the write operations to fail.
type Type ¶
type Type int32
const ( // NULL_TYPE specifies a NULL type. Type_NULL_TYPE Type = 0 // INT8 specifies a TINYINT type. // Properties: 1, IsNumber. Type_INT8 Type = 257 // UINT8 specifies a TINYINT UNSIGNED type. // Properties: 2, IsNumber, IsUnsigned. Type_UINT8 Type = 770 // INT16 specifies a SMALLINT type. // Properties: 3, IsNumber. Type_INT16 Type = 259 // UINT16 specifies a SMALLINT UNSIGNED type. // Properties: 4, IsNumber, IsUnsigned. Type_UINT16 Type = 772 // INT24 specifies a MEDIUMINT type. // Properties: 5, IsNumber. Type_INT24 Type = 261 // UINT24 specifies a MEDIUMINT UNSIGNED type. // Properties: 6, IsNumber, IsUnsigned. Type_UINT24 Type = 774 // INT32 specifies a INTEGER type. // Properties: 7, IsNumber. Type_INT32 Type = 263 // UINT32 specifies a INTEGER UNSIGNED type. // Properties: 8, IsNumber, IsUnsigned. Type_UINT32 Type = 776 // INT64 specifies a BIGINT type. // Properties: 9, IsNumber. Type_INT64 Type = 265 // UINT64 specifies a BIGINT UNSIGNED type. // Properties: 10, IsNumber, IsUnsigned. Type_UINT64 Type = 778 // FLOAT32 specifies a FLOAT type. // Properties: 11, IsFloat. Type_FLOAT32 Type = 1035 // FLOAT64 specifies a DOUBLE or REAL type. // Properties: 12, IsFloat. Type_FLOAT64 Type = 1036 // TIMESTAMP specifies a TIMESTAMP type. // Properties: 13, IsQuoted. Type_TIMESTAMP Type = 2061 // DATE specifies a DATE type. // Properties: 14, IsQuoted. Type_DATE Type = 2062 // TIME specifies a TIME type. // Properties: 15, IsQuoted. Type_TIME Type = 2063 // DATETIME specifies a DATETIME type. // Properties: 16, IsQuoted. Type_DATETIME Type = 2064 // YEAR specifies a YEAR type. // Properties: 17, IsNumber, IsUnsigned. Type_YEAR Type = 785 // DECIMAL specifies a DECIMAL or NUMERIC type. // Properties: 18, None. Type_DECIMAL Type = 18 // TEXT specifies a TEXT type. // Properties: 19, IsQuoted, IsText. Type_TEXT Type = 6163 // BLOB specifies a BLOB type. // Properties: 20, IsQuoted, IsBinary. Type_BLOB Type = 10260 // VARCHAR specifies a VARCHAR type. // Properties: 21, IsQuoted, IsText. Type_VARCHAR Type = 6165 // VARBINARY specifies a VARBINARY type. // Properties: 22, IsQuoted, IsBinary. Type_VARBINARY Type = 10262 // CHAR specifies a CHAR type. // Properties: 23, IsQuoted, IsText. Type_CHAR Type = 6167 // BINARY specifies a BINARY type. // Properties: 24, IsQuoted, IsBinary. Type_BINARY Type = 10264 // BIT specifies a BIT type. // Properties: 25, IsQuoted. Type_BIT Type = 2073 // ENUM specifies an ENUM type. // Properties: 26, IsQuoted. Type_ENUM Type = 2074 // SET specifies a SET type. // Properties: 27, IsQuoted. Type_SET Type = 2075 // TUPLE specifies a a tuple. This cannot // be returned in a QueryResult, but it can // be sent as a bind var. // Properties: 28, None. Type_TUPLE Type = 28 // GEOMETRY specifies a GEOMETRY type. // Properties: 29, IsQuoted. Type_GEOMETRY Type = 2077 // JSON specifies a JSON type. // Properties: 30, IsQuoted. Type_JSON Type = 2078 // EXPRESSION specifies a SQL expression. // This type is for internal use only. // Properties: 31, None. Type_EXPRESSION Type = 31 )
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value can store any SQL value. If the value represents an integral type, the bytes are always stored as a cannonical representation that matches how MySQL returns such values.
func MakeTrusted ¶
MakeTrusted makes a new Value based on the type. If the value is an integral, then val must be in its cannonical form. This function should only be used if you know the value and type conform to the rules. Every place this function is called, a comment is needed that explains why it's justified. Functions within this package are exempt.
func (Value) Bytes ¶
Bytes returns a copy of the raw data. All types are currently implemented as []byte. Use this function instead of Raw if you can't be sure about maintaining the read-only requirements of the bytes.
func (Value) EncodeASCII ¶
EncodeASCII encodes the value using 7-bit clean ascii bytes.
func (Value) ParseFloat64 ¶
ParseFloat64 will parse a Value into an float64. It does not check the type. TODO(sougou): deprecate this function in favor of a more type-aware implemention in arithmetic.
func (Value) ParseInt64 ¶
ParseInt64 will parse a Value into an int64. It does not check the type. TODO(sougou): deprecate this function in favor of a more type-aware implemention in arithmetic.
func (Value) ParseUint64 ¶
ParseUint64 will parse a Value into a uint64. It does not check the type. TODO(sougou): deprecate this function in favor of a more type-aware implemention in arithmetic.
func (Value) Raw ¶
Raw returns the raw bytes. All types are currently implemented as []byte. You should avoid using this function. If you do, you should treat the bytes as read-only.