Documentation ¶
Index ¶
- Constants
- Variables
- func AesDecryptCBC(encrypted []byte, key []byte, iv []byte) (decrypted []byte, err error)
- func AesDecryptCFB(encrypted []byte, key []byte) (decrypted []byte, err error)
- func AesDecryptECB(encrypted []byte, key []byte) (decrypted []byte, err error)
- func AesDecryptGCM(encrypted []byte, key []byte, iv []byte) (decrypted []byte, err error)
- func AesEncryptCBC(origData []byte, key []byte, iv []byte) (encrypted []byte, err error)
- func AesEncryptCFB(origData []byte, key []byte) (encrypted []byte, err error)
- func AesEncryptECB(origData []byte, key []byte) (encrypted []byte, err error)
- func AesEncryptGCM(origData []byte, key []byte, iv []byte) (encrypted []byte, err error)
- func AppendDateTime(buf []byte, t time.Time) ([]byte, error)
- func AppendLengthEncodedInteger(b []byte, n uint64) []byte
- func Check(fieldOrTableName string) bool
- func CheckAndReplace(fieldOrTableName string) string
- func CheckEscape(fieldOrTableName string) bool
- func CollectRowKeys(lockKey, resourceID string) []string
- func Compare(a, b interface{}) int
- func ComputeUnary(op opcode.Op, input interface{}) (interface{}, error)
- func CurrentTimeMillis() uint64
- func CurrentTimeNano() uint64
- func DeregisterTLSConfig(key string)
- func Escape(input string, flag EscapeFlag) string
- func EscapeSql(sql string) string
- func FirstNonEmptyString(first string, second string, others ...string) string
- func FirstNonZeroInt(first, second int, others ...int) int
- func FirstNonZeroInt32(first, second int32, others ...int32) int32
- func FirstNonZeroInt64(first, second int64, others ...int64) int64
- func FormatBinaryDateTime(src []byte, length uint8) (driver.Value, error)
- func FormatBinaryTime(src []byte, length uint8) (driver.Value, error)
- func FormatDate(tsMillis uint64) string
- func FormatTimeMillis(tsMillis uint64) string
- func GetDefaultFieldLengthAndDecimal(tp constant.FieldType) (flen int, decimal int)
- func GetDefaultFieldLengthAndDecimalForCast(tp constant.FieldType) (flen int, decimal int)
- func GetRowKey(resourceID string, tableName string, pk string) string
- func GetStmtLabel(stmtNode ast.StmtNode) string
- func GetTLSConfigClone(key string) (config *tls.Config)
- func GetTransactionID(xid string) int64
- func HasGlobalLockHint(hints []*ast.TableOptimizerHint) bool
- func HasTraceParentHint(hints []*ast.TableOptimizerHint) (bool, string)
- func HasUseDBHint(hints []*ast.TableOptimizerHint) (bool, string)
- func HasXIDHint(hints []*ast.TableOptimizerHint) (bool, string)
- func IsBlank(s string) bool
- func IsFloat32Equal(f1, f2 float32) bool
- func IsFloat64Equal(f1, f2 float64) bool
- func IsIntegerType(tp constant.FieldType) bool
- func IsZero(value interface{}) bool
- func LenEOFString(value string) int
- func LenEncIntSize(i uint64) int
- func LenEncStringSize(value string) int
- func LenNullString(value string) int
- func MustFirstNonEmptyString(first, second string, others ...string) string
- func MysqlAppendInParam(size int) string
- func MysqlAppendInParamWithValue(values []interface{}) string
- func NewXIDHint(xid string) *ast.TableOptimizerHint
- func PadLeft(str, pad string, length int) string
- func PadRight(str, pad string, length int) string
- func ParseBinaryDateTime(num uint64, data []byte, loc *time.Location) (driver.Value, error)
- func ParseDateTime(b []byte, loc *time.Location) (time.Time, error)
- func ParseTable(tableName, cutSet string) (string, string)
- func PgsqlAppendInParam(size int) string
- func RandomBuf(size int) ([]byte, error)
- func ReadBool(input string) (value bool, valid bool)
- func ReadByte(data []byte, pos int) (byte, int, bool)
- func ReadBytes(data []byte, pos int, size int) ([]byte, int, bool)
- func ReadBytesCopy(data []byte, pos int, size int) ([]byte, int, bool)
- func ReadEOFString(data []byte, pos int) (string, int, bool)
- func ReadLenEncInt(data []byte, pos int) (uint64, int, bool)
- func ReadLenEncString(data []byte, pos int) (string, int, bool)
- func ReadLenEncStringAsBytes(data []byte, pos int) ([]byte, int, bool)
- func ReadLenEncStringAsBytesCopy(data []byte, pos int) ([]byte, int, bool)
- func ReadLengthEncodedInteger(b []byte) (uint64, bool, int)
- func ReadLengthEncodedString(b []byte) ([]byte, bool, int, error)
- func ReadNullString(data []byte, pos int) (string, int, bool)
- func ReadUint16(data []byte, pos int) (uint16, int, bool)
- func ReadUint32(data []byte, pos int) (uint32, int, bool)
- func ReadUint64(data []byte, pos int) (uint64, int, bool)
- func RegisterTLSConfig(key string, config *tls.Config) error
- func SkipLenEncString(data []byte, pos int) (int, bool)
- func SkipLengthEncodedString(b []byte) (int, error)
- func SortInt32s(s []int32)
- func StringToInt(b []byte) int
- func Uint64ToBytes(n uint64) []byte
- func Uint64ToString(n uint64) []byte
- func Unescape(s string, ignores ...rune) string
- func Wrap(sb *strings.Builder, wrap byte, origin string)
- func WriteByte(data []byte, pos int, value byte) int
- func WriteEOFString(data []byte, pos int, value string) int
- func WriteEscape(sb *strings.Builder, input string, flag EscapeFlag)
- func WriteLenEncInt(data []byte, pos int, i uint64) int
- func WriteLenEncString(data []byte, pos int, value string) int
- func WriteNullString(data []byte, pos int, value string) int
- func WriteUint16(data []byte, pos int, value uint16) int
- func WriteUint32(data []byte, pos int, value uint32) int
- func WriteUint64(data []byte, pos int, value uint64) int
- func WriteZeroes(data []byte, pos int, len int) int
- type EscapeFlag
- type RawBytes
- type Scanner
Constants ¶
const ( XIDHint = "XID" GlobalLockHint = "GlobalLock" UseDBHint = "UseDB" TraceParentHint = "TraceParent" )
const ( TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" UnixTimeUnitOffset = uint64(time.Millisecond / time.Nanosecond) )
Variables ¶
var MySQLKeyword = map[string]string{}/* 263 elements not displayed */
Functions ¶
func AesDecryptCBC ¶ added in v0.3.0
func AesDecryptCFB ¶ added in v0.3.0
func AesDecryptECB ¶ added in v0.3.0
func AesDecryptGCM ¶ added in v0.4.0
func AesEncryptCBC ¶ added in v0.3.0
func AesEncryptCFB ¶ added in v0.3.0
func AesEncryptECB ¶ added in v0.3.0
func AesEncryptGCM ¶ added in v0.4.0
func AppendLengthEncodedInteger ¶
encodes a uint64 value and appends it to the given bytes slice
func CheckAndReplace ¶
func CheckEscape ¶
func CollectRowKeys ¶
func ComputeUnary ¶
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 FirstNonEmptyString ¶
func FirstNonZeroInt ¶
func FirstNonZeroInt32 ¶
func FirstNonZeroInt64 ¶
func FormatBinaryDateTime ¶
func FormatDate ¶
FormatDate converts to date string tsMillis accurate to the millisecond,otherwise, an error will occur
func FormatTimeMillis ¶
FormatTimeMillis converts Millisecond to time string tsMillis accurate to the millisecond,otherwise, an error will occur
func GetDefaultFieldLengthAndDecimal ¶
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 ¶
GetDefaultFieldLengthAndDecimalForCast returns the default display length (flen) and decimal length for casted column when flen or decimal is not specified.
func GetStmtLabel ¶ added in v0.2.0
GetStmtLabel generates a label for given statement.
func GetTLSConfigClone ¶
func GetTransactionID ¶
func HasGlobalLockHint ¶ added in v0.2.1
func HasGlobalLockHint(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 IsFloat32Equal ¶
func IsFloat64Equal ¶
func IsIntegerType ¶
IsIntegerType indicate whether tp is an integer type.
func LenEOFString ¶
func LenEncIntSize ¶
LenEncIntSize returns the number of bytes required to encode a variable-length integer.
func LenEncStringSize ¶
func LenNullString ¶
func MustFirstNonEmptyString ¶
func MysqlAppendInParam ¶
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 ParseBinaryDateTime ¶
func ParseTable ¶ added in v0.3.0
ParseTable return db, table name. If db is empty, return "".
func PgsqlAppendInParam ¶
func ReadBool ¶
ReadBool Returns the bool value of the input. The 2nd return value indicates if the input was a valid bool value
func ReadBytesCopy ¶
ReadBytesCopy returns a copy of the bytes in the packet. Useful to remember contents of ephemeral packets.
func ReadLenEncStringAsBytes ¶
func ReadLengthEncodedInteger ¶
returns the number read, whether the value is NULL and the number of bytes read
func ReadLengthEncodedString ¶
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 RegisterTLSConfig ¶
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 SkipLengthEncodedString ¶
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 ¶
treats string value as unsigned integer representation
func Uint64ToBytes ¶
func Uint64ToString ¶
func WriteEscape ¶
func WriteEscape(sb *strings.Builder, input string, flag EscapeFlag)
Types ¶
type EscapeFlag ¶
type EscapeFlag uint8
const ( EscapeSingleQuote EscapeFlag EscapeDoubleQuote EscapeLike )
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.