types

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnspecifiedLength = -1
)

UnspecifiedLength is unspecified length.

View Source
const VarStorageLen = -1

VarStorageLen indicates this column is a variable length column.

Variables

View Source
var (
	// ErrInvalidDefault is returned when meet a invalid default value.
	ErrInvalidDefault = terror.ClassTypes.NewStd(mysql.ErrInvalidDefault)
	// ErrDataOutOfRange is returned when meet a value out of range.
	ErrDataOutOfRange = terror.ClassTypes.NewStd(mysql.ErrDataOutOfRange)
	// ErrTruncatedWrongValue is returned when meet a value bigger than
	// 99999999999999999999999999999999999999999999999999999999999999999 during parsing.
	ErrTruncatedWrongValue = terror.ClassTypes.NewStd(mysql.ErrTruncatedWrongValue)
	// ErrIllegalValueForType is returned when strconv.ParseFloat meet strconv.ErrRange during parsing.
	ErrIllegalValueForType = terror.ClassTypes.NewStd(mysql.ErrIllegalValueForType)
)
View Source
var (
	TiDBStrictIntegerDisplayWidth bool
)

TiDBStrictIntegerDisplayWidth represent whether return warnings when integerType with (length) was parsed. The default is `false`, it will be parsed as warning, and the result in show-create-table will ignore the display length when it set to `true`. This is for compatibility with MySQL 8.0 in which integer max display length is deprecated, referring this issue #6688 for more details.

Functions

func HasCharset

func HasCharset(ft *FieldType) bool

HasCharset indicates if a COLUMN has an associated charset. Returning false here prevents some information statements(like `SHOW CREATE TABLE`) from attaching a CHARACTER SET clause to the column.

func IsTypeBlob

func IsTypeBlob(tp byte) bool

IsTypeBlob returns a boolean indicating whether the tp is a blob type.

func IsTypeChar

func IsTypeChar(tp byte) bool

IsTypeChar returns a boolean indicating whether the tp is the char type like a string type or a varchar type.

func StrToType

func StrToType(ts string) (tp byte)

StrToType convert a string to type enum. Args:

ts: type string

func TypeStr

func TypeStr(tp byte) (r string)

TypeStr converts tp to a string.

func TypeToStr

func TypeToStr(tp byte, cs string) (r string)

TypeToStr converts a field to a string. It is used for converting Text to Blob, or converting Char to Binary. Args:

tp: type enum
cs: charset

Types

type EvalType

type EvalType byte

EvalType indicates the specified types that arguments and result of a built-in function should be.

const (
	// ETInt represents type INT in evaluation.
	ETInt EvalType = iota
	// ETReal represents type REAL in evaluation.
	ETReal
	// ETDecimal represents type DECIMAL in evaluation.
	ETDecimal
	// ETString represents type STRING in evaluation.
	ETString
	// ETDatetime represents type DATETIME in evaluation.
	ETDatetime
	// ETTimestamp represents type TIMESTAMP in evaluation.
	ETTimestamp
	// ETDuration represents type DURATION in evaluation.
	ETDuration
	// ETJson represents type JSON in evaluation.
	ETJson
)

func (EvalType) IsStringKind

func (et EvalType) IsStringKind() bool

IsStringKind returns true for ETString, ETDatetime, ETTimestamp, ETDuration, ETJson EvalTypes.

type FieldType

type FieldType struct {
	// contains filtered or unexported fields
}

FieldType records field type information.

func NewFieldType

func NewFieldType(tp byte) *FieldType

NewFieldType returns a FieldType, with a type and other information about field type.

func (*FieldType) AddFlag

func (ft *FieldType) AddFlag(flag uint)

AddFlag adds a flag to the FieldType.

func (*FieldType) AndFlag

func (ft *FieldType) AndFlag(flag uint)

AndFlag and the flag of the FieldType.

func (*FieldType) ArrayType

func (ft *FieldType) ArrayType() *FieldType

ArrayType return the type of the array.

func (*FieldType) CleanElemIsBinaryLit

func (ft *FieldType) CleanElemIsBinaryLit()

CleanElemIsBinaryLit cleans the binary literal flag of the element at index idx.

func (*FieldType) Clone

func (ft *FieldType) Clone() *FieldType

Clone returns a copy of itself.

func (*FieldType) CompactStr

func (ft *FieldType) CompactStr() string

CompactStr only considers tp/CharsetBin/flen/Deimal. This is used for showing column type in infoschema.

func (*FieldType) DelFlag

func (ft *FieldType) DelFlag(flag uint)

DelFlag delete the flag of the FieldType.

func (*FieldType) Equal

func (ft *FieldType) Equal(other *FieldType) bool

Equal checks whether two FieldType objects are equal.

func (*FieldType) EvalType

func (ft *FieldType) EvalType() EvalType

EvalType gets the type in evaluation.

func (*FieldType) FormatAsCastType

func (ft *FieldType) FormatAsCastType(w io.Writer, explicitCharset bool)

FormatAsCastType is used for write AST back to string.

func (*FieldType) GetCharset

func (ft *FieldType) GetCharset() string

GetCharset returns the field's charset

func (*FieldType) GetCollate

func (ft *FieldType) GetCollate() string

GetCollate returns the collation of the field.

func (*FieldType) GetDecimal

func (ft *FieldType) GetDecimal() int

GetDecimal returns the decimal of the FieldType.

func (*FieldType) GetElem

func (ft *FieldType) GetElem(idx int) string

GetElem returns the element of the FieldType.

func (*FieldType) GetElemIsBinaryLit

func (ft *FieldType) GetElemIsBinaryLit(idx int) bool

GetElemIsBinaryLit returns the binary literal flag of the element at index idx.

func (*FieldType) GetElems

func (ft *FieldType) GetElems() []string

GetElems returns the elements of the FieldType.

func (*FieldType) GetFlag

func (ft *FieldType) GetFlag() uint

GetFlag returns the flag of the FieldType.

func (*FieldType) GetFlen

func (ft *FieldType) GetFlen() int

GetFlen returns the length of the field.

func (*FieldType) GetType

func (ft *FieldType) GetType() byte

GetType returns the type of the FieldType.

func (*FieldType) Hybrid

func (ft *FieldType) Hybrid() bool

Hybrid checks whether a type is a hybrid type, which can represent different types of value in specific context.

func (*FieldType) InfoSchemaStr

func (ft *FieldType) InfoSchemaStr() string

InfoSchemaStr joins the CompactStr with unsigned flag and returns a string.

func (*FieldType) Init

func (ft *FieldType) Init(tp byte)

Init initializes the FieldType data.

func (*FieldType) IsArray

func (ft *FieldType) IsArray() bool

IsArray return true if the filed type is array.

func (*FieldType) IsDecimalValid

func (ft *FieldType) IsDecimalValid() bool

IsDecimalValid checks whether the decimal is valid.

func (*FieldType) IsVarLengthType

func (ft *FieldType) IsVarLengthType() bool

IsVarLengthType Determine whether the column type is a variable-length type

func (*FieldType) MarshalJSON

func (ft *FieldType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the FieldType to JSON.

func (*FieldType) MemoryUsage

func (ft *FieldType) MemoryUsage() (sum int64)

MemoryUsage return the memory usage of FieldType

func (*FieldType) PartialEqual

func (ft *FieldType) PartialEqual(other *FieldType, unsafe bool) bool

PartialEqual checks whether two FieldType objects are equal. If unsafe is true and the objects is string type, PartialEqual will ignore flen. See https://github.com/pingcap/tidb/issues/35490#issuecomment-1211658886 for more detail.

func (*FieldType) Restore

func (ft *FieldType) Restore(ctx *format.RestoreCtx) error

Restore implements Node interface.

func (*FieldType) RestoreAsCastType

func (ft *FieldType) RestoreAsCastType(ctx *format.RestoreCtx, explicitCharset bool)

RestoreAsCastType is used for write AST back to string.

func (*FieldType) SetArray

func (ft *FieldType) SetArray(array bool)

SetArray sets the array field of the FieldType.

func (*FieldType) SetCharset

func (ft *FieldType) SetCharset(charset string)

SetCharset sets the charset of the FieldType.

func (*FieldType) SetCollate

func (ft *FieldType) SetCollate(collate string)

SetCollate sets the collation of the FieldType.

func (*FieldType) SetDecimal

func (ft *FieldType) SetDecimal(decimal int)

SetDecimal sets the decimal of the FieldType.

func (*FieldType) SetDecimalUnderLimit

func (ft *FieldType) SetDecimalUnderLimit(decimal int)

SetDecimalUnderLimit sets the decimal of the field to the value of the argument

func (*FieldType) SetElem

func (ft *FieldType) SetElem(idx int, element string)

SetElem sets the element of the FieldType.

func (*FieldType) SetElemWithIsBinaryLit

func (ft *FieldType) SetElemWithIsBinaryLit(idx int, element string, isBinaryLit bool)

SetElemWithIsBinaryLit sets the element of the FieldType.

func (*FieldType) SetElems

func (ft *FieldType) SetElems(elems []string)

SetElems sets the elements of the FieldType.

func (*FieldType) SetFlag

func (ft *FieldType) SetFlag(flag uint)

SetFlag sets the flag of the FieldType.

func (*FieldType) SetFlen

func (ft *FieldType) SetFlen(flen int)

SetFlen sets the length of the field.

func (*FieldType) SetFlenUnderLimit

func (ft *FieldType) SetFlenUnderLimit(flen int)

SetFlenUnderLimit sets the length of the field to the value of the argument

func (*FieldType) SetType

func (ft *FieldType) SetType(tp byte)

SetType sets the type of the FieldType.

func (*FieldType) StorageLength

func (ft *FieldType) StorageLength() int

StorageLength is the length of stored value for the type.

func (*FieldType) String

func (ft *FieldType) String() string

String joins the information of FieldType and returns a string. Note: when flen or decimal is unspecified, this function will use the default value instead of -1.

func (*FieldType) ToggleFlag

func (ft *FieldType) ToggleFlag(flag uint)

ToggleFlag toggle the flag of the FieldType.

func (*FieldType) UnmarshalJSON

func (ft *FieldType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*FieldType) UpdateFlenAndDecimalUnderLimit

func (ft *FieldType) UpdateFlenAndDecimalUnderLimit(old *FieldType, deltaDecimal int, deltaFlen int)

UpdateFlenAndDecimalUnderLimit updates the length and decimal to the value of the argument

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL