mirror of
https://github.com/go-gitea/gitea
synced 2025-07-06 10:37:20 +00:00
update mssql drive to last working version 20180314172330-6a30f4e59a44 (#7306)
This commit is contained in:
committed by
Lunny Xiao
parent
aeb8f7aad8
commit
1e46eedce7
74
vendor/github.com/denisenkom/go-mssqldb/uniqueidentifier.go
generated
vendored
Normal file
74
vendor/github.com/denisenkom/go-mssqldb/uniqueidentifier.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
package mssql
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UniqueIdentifier [16]byte
|
||||
|
||||
func (u *UniqueIdentifier) Scan(v interface{}) error {
|
||||
reverse := func(b []byte) {
|
||||
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
}
|
||||
|
||||
switch vt := v.(type) {
|
||||
case []byte:
|
||||
if len(vt) != 16 {
|
||||
return errors.New("mssql: invalid UniqueIdentifier length")
|
||||
}
|
||||
|
||||
var raw UniqueIdentifier
|
||||
|
||||
copy(raw[:], vt)
|
||||
|
||||
reverse(raw[0:4])
|
||||
reverse(raw[4:6])
|
||||
reverse(raw[6:8])
|
||||
*u = raw
|
||||
|
||||
return nil
|
||||
case string:
|
||||
if len(vt) != 36 {
|
||||
return errors.New("mssql: invalid UniqueIdentifier string length")
|
||||
}
|
||||
|
||||
b := []byte(vt)
|
||||
for i, c := range b {
|
||||
switch c {
|
||||
case '-':
|
||||
b = append(b[:i], b[i+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
_, err := hex.Decode(u[:], []byte(b))
|
||||
return err
|
||||
default:
|
||||
return fmt.Errorf("mssql: cannot convert %T to UniqueIdentifier", v)
|
||||
}
|
||||
}
|
||||
|
||||
func (u UniqueIdentifier) Value() (driver.Value, error) {
|
||||
reverse := func(b []byte) {
|
||||
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
}
|
||||
|
||||
raw := make([]byte, len(u))
|
||||
copy(raw, u[:])
|
||||
|
||||
reverse(raw[0:4])
|
||||
reverse(raw[4:6])
|
||||
reverse(raw[6:8])
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
func (u UniqueIdentifier) String() string {
|
||||
return fmt.Sprintf("%X-%X-%X-%X-%X", u[0:4], u[4:6], u[6:8], u[8:10], u[10:])
|
||||
}
|
Reference in New Issue
Block a user