sqltypes

package
v0.0.0-...-436d200 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: BSD-3-Clause, BSD-3-Clause Imports: 8 Imported by: 34

Documentation

Overview

Package sqltypes implements interfaces and types that represent SQL values.

DROPBOX NOTE: This is a modified version of vitess's sqltypes module. The original source can be found at https://code.google.com/p/vitess/

Index

Constants

View Source
const (
	NullType       = ValueType(0)
	NumericType    = ValueType(1)
	FractionalType = ValueType(2)
	StringType     = ValueType(3)
	UTF8StringType = ValueType(4)
)

Variables

View Source
var (
	NULL       = Value{}
	DONTESCAPE = byte(255)
)
View Source
var SqlDecodeMap [256]byte

SqlDecodeMap is the reverse of SqlEncodeMap

View Source
var SqlEncodeMap [256]byte

SqlEncodeMap specifies how to escape binary data with '\'. Complies to http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html

Functions

func ConvertAssign

func ConvertAssign(src Value, dest interface{}) error

ConvertAssign copies to the '*dest' the value in 'src'. An error is returned if the coping is done between incompatible Value and dest types. 'dest' must be a pointer type. Note that for anything else than *[]byte the value is copied, however if 'dest' is of type *[]byte it will point to same []byte array as 'src.Raw()' (no copying).

func ConvertAssignDefault

func ConvertAssignDefault(src Value, dest interface{}, defaultValue interface{}) error

ConvertAssign, but with support for default values

func ConvertAssignRow

func ConvertAssignRow(row []Value, dest ...interface{}) error

ConvertAssignRow copies a row of values in the list of destinations. An error is returned if any one of the row's element coping is done between incompatible value and dest types. The list of destinations must contain pointers. Note that for anything else than *[]byte the value is copied, however if the destination is of type *[]byte it will point the same []byte array as the source (no copying).

func ConvertAssignRowNullable

func ConvertAssignRowNullable(row []Value, dest ...interface{}) error

ConverAssignRowNullable is the same as ConvertAssignRow except that it allows nil as a value for the row or any of the row values. In thoses cases, the corresponding values are ignored.

func Uint64EncodeSql

func Uint64EncodeSql(b encoding2.BinaryWriter, num uint64)

Helper function for converting a uint64 to a string suitable for SQL.

Types

type Fractional

type Fractional []byte

Fractional represents fractional types like float and decimal It's functionally equivalent to Numeric other than how it's constructed

func (Fractional) MarshalBinary

func (f Fractional) MarshalBinary() ([]byte, error)

type InnerValue

type InnerValue interface {
	MarshalBinary() ([]byte, error)
	// contains filtered or unexported methods
}

InnerValue defines methods that need to be supported by all non-null value types.

type Numeric

type Numeric []byte

Numeric represents non-fractional SQL number.

func (Numeric) MarshalBinary

func (n Numeric) MarshalBinary() ([]byte, error)

type String

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

String represents any SQL type that needs to be represented using quotes. If isUtf8 is false, it will be hex encoded so it's safe for exception reporting, etc.

func (String) MarshalBinary

func (s String) MarshalBinary() ([]byte, error)

type Value

type Value struct {
	Inner InnerValue
}

Value can store any SQL value. NULL is stored as nil.

func BuildNumeric

func BuildNumeric(val string) (n Value, err error)

BuildNumeric builds a Numeric type that represents any whole number. It normalizes the representation to ensure 1:1 mapping between the number and its representation.

func BuildValue

func BuildValue(goval interface{}) (v Value, err error)

func MakeFractional

func MakeFractional(b []byte) Value

MakeFractional makes a Fractional value from a []byte without validation.

func MakeNumeric

func MakeNumeric(b []byte) Value

MakeNumeric makes a Numeric from a []byte without validation.

func MakeString

func MakeString(b []byte) Value

MakeString makes a String value from a []byte.

func MakeUtf8String

func MakeUtf8String(s string) Value

MakeUtf8String makes a String value from a []byte.

func (Value) EncodeAscii

func (v Value) EncodeAscii(b encoding2.BinaryWriter)

EncodeAscii encodes the value using 7-bit clean ascii bytes.

func (Value) EncodeSql

func (v Value) EncodeSql(b encoding2.BinaryWriter)

EncodeSql encodes the value into an SQL statement. Can be binary.

func (Value) IsFractional

func (v Value) IsFractional() (ok bool)

func (Value) IsNull

func (v Value) IsNull() bool

func (Value) IsNumeric

func (v Value) IsNumeric() (ok bool)

func (Value) IsString

func (v Value) IsString() (ok bool)

func (Value) IsUtf8String

func (v Value) IsUtf8String() (ok bool)

func (Value) MarshalBinary

func (v Value) MarshalBinary() ([]byte, error)

MarshalBinary helps implement BinaryMarshaler interface for Value.

func (Value) Raw

func (v Value) Raw() []byte

Raw returns the raw bytes. All types are currently implemented as []byte.

func (Value) String

func (v Value) String() string

String returns the raw value as a string

func (*Value) UnmarshalBinary

func (v *Value) UnmarshalBinary(data []byte) error

UnmarshalBinary helps implement BinaryUnmarshaler interface for Value.

type ValueType

type ValueType byte

Jump to

Keyboard shortcuts

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