MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / write

Method write

IceFireDB-SQLProxy/pkg/mysql/client/stmt.go:50–172  ·  view source on GitHub ↗
(args ...any)

Source from the content-addressed store, hash-verified

48}
49
50func (s *Stmt) write(args ...any) error {
51 paramsNum := s.params
52
53 if len(args) != paramsNum {
54 return fmt.Errorf("argument mismatch, need %d but got %d", s.params, len(args))
55 }
56
57 paramTypes := make([]byte, paramsNum<<1)
58 paramValues := make([][]byte, paramsNum)
59
60 // NULL-bitmap, length: (num-params+7)
61 nullBitmap := make([]byte, (paramsNum+7)>>3)
62
63 length := 1 + 4 + 1 + 4 + ((paramsNum + 7) >> 3) + 1 + (paramsNum << 1)
64
65 var newParamBoundFlag byte = 0
66
67 for i := range args {
68 if args[i] == nil {
69 nullBitmap[i/8] |= (1 << (uint(i) % 8))
70 paramTypes[i<<1] = MYSQL_TYPE_NULL
71 continue
72 }
73
74 newParamBoundFlag = 1
75
76 switch v := args[i].(type) {
77 case int8:
78 paramTypes[i<<1] = MYSQL_TYPE_TINY
79 paramValues[i] = []byte{byte(v)}
80 case int16:
81 paramTypes[i<<1] = MYSQL_TYPE_SHORT
82 paramValues[i] = Uint16ToBytes(uint16(v))
83 case int32:
84 paramTypes[i<<1] = MYSQL_TYPE_LONG
85 paramValues[i] = Uint32ToBytes(uint32(v))
86 case int:
87 paramTypes[i<<1] = MYSQL_TYPE_LONGLONG
88 paramValues[i] = Uint64ToBytes(uint64(v))
89 case int64:
90 paramTypes[i<<1] = MYSQL_TYPE_LONGLONG
91 paramValues[i] = Uint64ToBytes(uint64(v))
92 case uint8:
93 paramTypes[i<<1] = MYSQL_TYPE_TINY
94 paramTypes[(i<<1)+1] = 0x80
95 paramValues[i] = []byte{v}
96 case uint16:
97 paramTypes[i<<1] = MYSQL_TYPE_SHORT
98 paramTypes[(i<<1)+1] = 0x80
99 paramValues[i] = Uint16ToBytes(v)
100 case uint32:
101 paramTypes[i<<1] = MYSQL_TYPE_LONG
102 paramTypes[(i<<1)+1] = 0x80
103 paramValues[i] = Uint32ToBytes(v)
104 case uint:
105 paramTypes[i<<1] = MYSQL_TYPE_LONGLONG
106 paramTypes[(i<<1)+1] = 0x80
107 paramValues[i] = Uint64ToBytes(uint64(v))

Callers 1

ExecuteMethod · 0.95

Calls 6

Uint16ToBytesFunction · 0.50
Uint32ToBytesFunction · 0.50
Uint64ToBytesFunction · 0.50
PutLengthEncodedIntFunction · 0.50
ResetSequenceMethod · 0.45
WritePacketMethod · 0.45

Tested by

no test coverage detected