File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -915,20 +915,29 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
915915 }
916916
917917 case []byte :
918- paramTypes [i + i ] = fieldTypeString
919- paramTypes [i + i + 1 ] = 0x00
920-
921- if len (v ) < mc .maxPacketAllowed - pos - len (paramValues )- (len (args )- (i + 1 ))* 64 {
922- paramValues = appendLengthEncodedInteger (paramValues ,
923- uint64 (len (v )),
924- )
925- paramValues = append (paramValues , v ... )
926- } else {
927- if err := stmt .writeCommandLongData (i , v ); err != nil {
928- return err
918+ // Common case (non-nil value) first
919+ if v != nil {
920+ paramTypes [i + i ] = fieldTypeString
921+ paramTypes [i + i + 1 ] = 0x00
922+
923+ if len (v ) < mc .maxPacketAllowed - pos - len (paramValues )- (len (args )- (i + 1 ))* 64 {
924+ paramValues = appendLengthEncodedInteger (paramValues ,
925+ uint64 (len (v )),
926+ )
927+ paramValues = append (paramValues , v ... )
928+ } else {
929+ if err := stmt .writeCommandLongData (i , v ); err != nil {
930+ return err
931+ }
929932 }
933+ continue
930934 }
931935
936+ // Handle []byte(nil) as a NULL value
937+ nullMask |= 1 << uint (i )
938+ paramTypes [i + i ] = fieldTypeNULL
939+ paramTypes [i + i + 1 ] = 0x00
940+
932941 case string :
933942 paramTypes [i + i ] = fieldTypeString
934943 paramTypes [i + i + 1 ] = 0x00
You can’t perform that action at this time.
0 commit comments