misc

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: Apache-2.0 Imports: 28 Imported by: 3

Documentation

Index

Constants

View Source
const (
	XIDHint         = "XID"
	GlobalLockHint  = "GlobalLock"
	UseDBHint       = "UseDB"
	TraceParentHint = "TraceParent"
	ShadowHint      = "Shadow"
)
View Source
const (
	TimeFormat         = "2006-01-02 15:04:05"
	DateFormat         = "2006-01-02"
	UnixTimeUnitOffset = uint64(time.Millisecond / time.Nanosecond)
)
View Source
const (
	Numeric = "^[0-9]+$"
)

Variables

View Source
var MySQLKeyword = map[string]string{}/* 263 elements not displayed */

Functions

func AesDecryptCBC added in v0.3.0

func AesDecryptCBC(encrypted []byte, key []byte, iv []byte) (decrypted []byte, err error)

func AesDecryptCFB added in v0.3.0

func AesDecryptCFB(encrypted []byte, key []byte) (decrypted []byte, err error)

func AesDecryptECB added in v0.3.0

func AesDecryptECB(encrypted []byte, key []byte) (decrypted []byte, err error)

func AesDecryptGCM added in v0.4.0

func AesDecryptGCM(encrypted []byte, key []byte, iv []byte) (decrypted []byte, err error)

func AesEncryptCBC added in v0.3.0

func AesEncryptCBC(origData []byte, key []byte, iv []byte) (encrypted []byte, err error)

func AesEncryptCFB added in v0.3.0

func AesEncryptCFB(origData []byte, key []byte) (encrypted []byte, err error)

func AesEncryptECB added in v0.3.0

func AesEncryptECB(origData []byte, key []byte) (encrypted []byte, err error)

func AesEncryptGCM added in v0.4.0

func AesEncryptGCM(origData []byte, key []byte, iv []byte) (encrypted []byte, err error)

func AppendDateTime

func AppendDateTime(buf []byte, t time.Time) ([]byte, error)

func AppendLengthEncodedInteger

func AppendLengthEncodedInteger(b []byte, n uint64) []byte

encodes a uint64 value and appends it to the given bytes slice

func Check

func Check(fieldOrTableName string) bool

func CheckAndReplace

func CheckAndReplace(fieldOrTableName string) string

func CheckEscape

func CheckEscape(fieldOrTableName string) bool

func CollectRowKeys

func CollectRowKeys(lockKey, resourceID string) []string

func Compare

func Compare(a, b interface{}) int

func ComputeUnary

func ComputeUnary(op opcode.Op, input interface{}) (interface{}, error)

func CurrentTimeMillis

func CurrentTimeMillis() uint64

CurrentTimeMillis Returns the current Unix timestamp in milliseconds.

func CurrentTimeNano

func CurrentTimeNano() uint64

CurrentTimeNano Returns the current Unix timestamp in nanoseconds.

func DeregisterTLSConfig

func DeregisterTLSConfig(key string)

DeregisterTLSConfig removes the tls.Config associated with key.

func Escape

func Escape(input string, flag EscapeFlag) string

func EscapeSql

func EscapeSql(sql string) string

EscapeSql remove exceptional character

func FirstNonEmptyString

func FirstNonEmptyString(first string, second string, others ...string) string

func FirstNonZeroInt

func FirstNonZeroInt(first, second int, others ...int) int

func FirstNonZeroInt32

func FirstNonZeroInt32(first, second int32, others ...int32) int32

func FirstNonZeroInt64

func FirstNonZeroInt64(first, second int64, others ...int64) int64

func FormatBinaryDateTime

func FormatBinaryDateTime(src []byte, length uint8) (driver.Value, error)

func FormatBinaryTime

func FormatBinaryTime(src []byte, length uint8) (driver.Value, error)

func FormatDate

func FormatDate(tsMillis uint64) string

FormatDate converts to date string tsMillis accurate to the millisecond,otherwise, an error will occur

func FormatTimeMillis

func FormatTimeMillis(tsMillis uint64) string

FormatTimeMillis converts Millisecond to time string tsMillis accurate to the millisecond,otherwise, an error will occur

func GetDefaultFieldLengthAndDecimal

func GetDefaultFieldLengthAndDecimal(tp constant.FieldType) (flen int, decimal int)

GetDefaultFieldLengthAndDecimal returns the default display length (flen) and decimal length for column. Call this when no Flen assigned in ddl. or column value is calculated from an expression. For example: "select count(*) from t;", the column type is int64 and Flen in ResultField will be 21. See https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html

func GetDefaultFieldLengthAndDecimalForCast

func GetDefaultFieldLengthAndDecimalForCast(tp constant.FieldType) (flen int, decimal int)

GetDefaultFieldLengthAndDecimalForCast returns the default display length (flen) and decimal length for casted column when flen or decimal is not specified.

func GetRowKey

func GetRowKey(resourceID string, tableName string, pk string) string

func GetStmtLabel added in v0.2.0

func GetStmtLabel(stmtNode ast.StmtNode) string

GetStmtLabel generates a label for given statement.

func GetTLSConfigClone

func GetTLSConfigClone(key string) (config *tls.Config)

func GetTransactionID

func GetTransactionID(xid string) int64

func HasGlobalLockHint added in v0.2.1

func HasGlobalLockHint(hints []*ast.TableOptimizerHint) bool

func HasShadowHint added in v0.5.0

func HasShadowHint(hints []*ast.TableOptimizerHint) bool

func HasTraceParentHint added in v0.2.1

func HasTraceParentHint(hints []*ast.TableOptimizerHint) (bool, string)

func HasUseDBHint added in v0.3.0

func HasUseDBHint(hints []*ast.TableOptimizerHint) (bool, string)

func HasXIDHint added in v0.2.1

func HasXIDHint(hints []*ast.TableOptimizerHint) (bool, string)

func IsBlank

func IsBlank(s string) bool

func IsFloat32Equal

func IsFloat32Equal(f1, f2 float32) bool

func IsFloat64Equal

func IsFloat64Equal(f1, f2 float64) bool

func IsIntegerType

func IsIntegerType(tp constant.FieldType) bool

IsIntegerType indicate whether tp is an integer type.

func IsNumeric added in v0.4.1

func IsNumeric(str string) bool

IsNumeric checks if the string contains only numbers. Empty string is valid.

func IsZero

func IsZero(value interface{}) bool

func LenEOFString

func LenEOFString(value string) int

func LenEncIntSize

func LenEncIntSize(i uint64) int

LenEncIntSize returns the number of bytes required to encode a variable-length integer.

func LenEncStringSize

func LenEncStringSize(value string) int

func LenNullString

func LenNullString(value string) int

func MustFirstNonEmptyString

func MustFirstNonEmptyString(first, second string, others ...string) string

func MysqlAppendInParam

func MysqlAppendInParam(size int) string

func MysqlAppendInParamWithValue added in v0.1.1

func MysqlAppendInParamWithValue(values []interface{}) string

func NewXIDHint added in v0.2.1

func NewXIDHint(xid string) *ast.TableOptimizerHint

func PadLeft

func PadLeft(str, pad string, length int) string

func PadRight

func PadRight(str, pad string, length int) string

func ParseBinaryDateTime

func ParseBinaryDateTime(num uint64, data []byte, loc *time.Location) (driver.Value, error)

func ParseDateTime

func ParseDateTime(b []byte, loc *time.Location) (time.Time, error)

func ParseTable added in v0.3.0

func ParseTable(tableName, cutSet string) (string, string)

ParseTable return db, table name. If db is empty, return "".

func PgsqlAppendInParam

func PgsqlAppendInParam(size int) string

func RandomBuf

func RandomBuf(size int) ([]byte, error)

RandomBuf return random salt, seed must be in the range of ascii

func ReadBool

func ReadBool(input string) (value bool, valid bool)

ReadBool Returns the bool value of the input. The 2nd return value indicates if the input was a valid bool value

func ReadByte

func ReadByte(data []byte, pos int) (byte, int, bool)

func ReadBytes

func ReadBytes(data []byte, pos int, size int) ([]byte, int, bool)

func ReadBytesCopy

func ReadBytesCopy(data []byte, pos int, size int) ([]byte, int, bool)

ReadBytesCopy returns a copy of the bytes in the packet. Useful to remember contents of ephemeral packets.

func ReadEOFString

func ReadEOFString(data []byte, pos int) (string, int, bool)

func ReadLenEncInt

func ReadLenEncInt(data []byte, pos int) (uint64, int, bool)

func ReadLenEncString

func ReadLenEncString(data []byte, pos int) (string, int, bool)

func ReadLenEncStringAsBytes

func ReadLenEncStringAsBytes(data []byte, pos int) ([]byte, int, bool)

func ReadLenEncStringAsBytesCopy

func ReadLenEncStringAsBytesCopy(data []byte, pos int) ([]byte, int, bool)

func ReadLengthEncodedInteger

func ReadLengthEncodedInteger(b []byte) (uint64, bool, int)

returns the number read, whether the value is NULL and the number of bytes read

func ReadLengthEncodedString

func ReadLengthEncodedString(b []byte) ([]byte, bool, int, error)

returns the string read as a bytes slice, whether the value is NULL, the number of bytes read and an error, in case the string is longer than the input slice

func ReadNullString

func ReadNullString(data []byte, pos int) (string, int, bool)

func ReadUint16

func ReadUint16(data []byte, pos int) (uint16, int, bool)

func ReadUint32

func ReadUint32(data []byte, pos int) (uint32, int, bool)

func ReadUint64

func ReadUint64(data []byte, pos int) (uint64, int, bool)

func RegisterTLSConfig

func RegisterTLSConfig(key string, config *tls.Config) error

RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. Use the key as a value in the DSN where tls=value.

Note: The provided tls.Config is exclusively owned by the driver after registering it.

rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile("/path/ca-cert.pem")
if err != nil {
    log.Fatal(err)
}
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
    log.Fatal("Failed to append PEM.")
}
clientCert := make([]tls.Certificate, 0, 1)
certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
if err != nil {
    log.Fatal(err)
}
clientCert = append(clientCert, certs)
misc.RegisterTLSConfig("custom", &tls.Config{
    RootCAs: rootCertPool,
    Certificates: clientCert,
})
db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")

func SkipLenEncString

func SkipLenEncString(data []byte, pos int) (int, bool)

func SkipLengthEncodedString

func SkipLengthEncodedString(b []byte) (int, error)

returns the number of bytes skipped and an error, in case the string is longer than the input slice

func SortInt32s

func SortInt32s(s []int32)

func StringToInt

func StringToInt(b []byte) int

treats string value as unsigned integer representation

func Uint64ToBytes

func Uint64ToBytes(n uint64) []byte

func Uint64ToString

func Uint64ToString(n uint64) []byte

func Unescape

func Unescape(s string, ignores ...rune) string

func Wrap

func Wrap(sb *strings.Builder, wrap byte, origin string)

func WriteByte

func WriteByte(data []byte, pos int, value byte) int

func WriteEOFString

func WriteEOFString(data []byte, pos int, value string) int

func WriteEscape

func WriteEscape(sb *strings.Builder, input string, flag EscapeFlag)

func WriteLenEncInt

func WriteLenEncInt(data []byte, pos int, i uint64) int

func WriteLenEncString

func WriteLenEncString(data []byte, pos int, value string) int

func WriteNullString

func WriteNullString(data []byte, pos int, value string) int

func WriteUint16

func WriteUint16(data []byte, pos int, value uint16) int

func WriteUint32

func WriteUint32(data []byte, pos int, value uint32) int

func WriteUint64

func WriteUint64(data []byte, pos int, value uint64) int

func WriteZeroes

func WriteZeroes(data []byte, pos int, len int) int

Types

type EscapeFlag

type EscapeFlag uint8
const (
	EscapeSingleQuote EscapeFlag
	EscapeDoubleQuote
	EscapeLike
)

type RawBytes

type RawBytes []byte

type Scanner

type Scanner interface {
	// Scan assigns a value from a database driver.
	//
	// The src value will be of one of the following types:
	//
	//    int64
	//    float64
	//    bool
	//    []byte
	//    string
	//    time.Time
	//    nil - for NULL values
	//
	// An error should be returned if the value cannot be stored
	// without loss of information.
	//
	// Reference types such as []byte are only valid until the next call to Scan
	// and should not be retained. Their underlying memory is owned by the driver.
	// If retention is necessary, copy their values before the next call to Scan.
	Scan(src interface{}) error
}

Scanner is an interface used by Scan.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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