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

Method bindStmtArgs

IceFireDB-SQLProxy/pkg/mysql/server/stmt.go:169–292  ·  view source on GitHub ↗
(s *Stmt, nullBitmap, paramTypes, paramValues []byte)

Source from the content-addressed store, hash-verified

167}
168
169func (c *Conn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte) error {
170 args := s.Args
171
172 pos := 0
173
174 var v []byte
175 var n int = 0
176 var isNull bool
177 var err error
178
179 for i := 0; i < s.Params; i++ {
180 if nullBitmap[i>>3]&(1<<(uint(i)%8)) > 0 {
181 args[i] = nil
182 continue
183 }
184
185 tp := paramTypes[i<<1]
186 isUnsigned := (paramTypes[(i<<1)+1] & 0x80) > 0
187
188 switch tp {
189 case MYSQL_TYPE_NULL:
190 args[i] = nil
191 continue
192
193 case MYSQL_TYPE_TINY:
194 if len(paramValues) < (pos + 1) {
195 return ErrMalformPacket
196 }
197
198 if isUnsigned {
199 args[i] = paramValues[pos]
200 } else {
201 args[i] = int8(paramValues[pos])
202 }
203
204 pos++
205 continue
206
207 case MYSQL_TYPE_SHORT, MYSQL_TYPE_YEAR:
208 if len(paramValues) < (pos + 2) {
209 return ErrMalformPacket
210 }
211
212 if isUnsigned {
213 args[i] = binary.LittleEndian.Uint16(paramValues[pos : pos+2])
214 } else {
215 args[i] = int16(binary.LittleEndian.Uint16(paramValues[pos : pos+2]))
216 }
217 pos += 2
218 continue
219
220 case MYSQL_TYPE_INT24, MYSQL_TYPE_LONG:
221 if len(paramValues) < (pos + 4) {
222 return ErrMalformPacket
223 }
224
225 if isUnsigned {
226 args[i] = binary.LittleEndian.Uint32(paramValues[pos : pos+4])

Callers 1

handleStmtExecuteMethod · 0.95

Calls 1

LengthEncodedStringFunction · 0.50

Tested by

no test coverage detected