@@ -92,7 +92,7 @@ func (mc *mysqlConn) writePacket(data *[]byte) error {
92
92
if mc .server .keepalive > 0 {
93
93
mc .lastCmdTime = time .Now ()
94
94
}
95
-
95
+
96
96
// Write packet
97
97
n , e := mc .netConn .Write (* data )
98
98
if e != nil || n != len (* data ) {
@@ -218,7 +218,7 @@ func (mc *mysqlConn) writeAuthPacket() (e error) {
218
218
// Calculate packet length and make buffer with that size
219
219
pktLen := 4 + 4 + 1 + 23 + len (mc .cfg .user ) + 1 + 1 + len (scrambleBuff ) + len (mc .cfg .dbname ) + 1
220
220
data := make ([]byte , 0 , pktLen + 4 )
221
-
221
+
222
222
// Add the packet header
223
223
data = append (data , uint24ToBytes (uint32 (pktLen ))... )
224
224
data = append (data , mc .sequence )
@@ -302,17 +302,17 @@ func (mc *mysqlConn) writeCommandPacket(command commandType, args ...interface{}
302
302
default :
303
303
return fmt .Errorf ("Unknown command: %d" , command )
304
304
}
305
-
305
+
306
306
pktLen := 1 + len (arg )
307
- data := make ([]byte , 0 , pktLen + 4 )
308
-
307
+ data := make ([]byte , 0 , pktLen + 4 )
308
+
309
309
// Add the packet header
310
310
data = append (data , uint24ToBytes (uint32 (pktLen ))... )
311
311
data = append (data , mc .sequence )
312
-
312
+
313
313
// Add command byte
314
314
data = append (data , byte (command ))
315
-
315
+
316
316
// Add arg
317
317
data = append (data , arg ... )
318
318
@@ -590,7 +590,7 @@ func (mc *mysqlConn) readRows(columnsCount int) (rows []*[][]byte, e error) {
590
590
591
591
// Append nil if field is NULL
592
592
if isNull {
593
- row [i ] = nil
593
+ row [i ] = nil
594
594
}
595
595
pos += n
596
596
}
@@ -710,7 +710,7 @@ func (stmt mysqlStmt) buildExecutePacket(args *[]driver.Value) (e error) {
710
710
711
711
// Reset packet-sequence
712
712
stmt .mc .sequence = 0
713
-
713
+
714
714
pktLen := 1 + 4 + 1 + 4 + (stmt .paramCount + 7 )/ 8 + 1 + argsLen * 2
715
715
paramValues := make ([][]byte , 0 , argsLen )
716
716
paramTypes := make ([]byte , 0 , argsLen * 2 )
@@ -722,49 +722,49 @@ func (stmt mysqlStmt) buildExecutePacket(args *[]driver.Value) (e error) {
722
722
if (* args )[i ] == nil {
723
723
bitMask += 1 << uint (i )
724
724
}
725
-
725
+
726
726
// cache types and values
727
727
switch (* args )[i ].(type ) {
728
728
case nil :
729
729
paramTypes = append (paramTypes , []byte {
730
730
byte (FIELD_TYPE_NULL ),
731
731
0x0 }... )
732
732
continue
733
-
733
+
734
734
case []byte :
735
- paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_STRING ),0x0 }... )
735
+ paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_STRING ), 0x0 }... )
736
736
val := (* args )[i ].([]byte )
737
737
valLen = len (val )
738
738
lcb := lengthCodedBinaryToBytes (uint64 (valLen ))
739
- pktLen += len (lcb ) + valLen
739
+ pktLen += len (lcb ) + valLen
740
740
paramValues = append (paramValues , lcb )
741
741
paramValues = append (paramValues , val )
742
742
continue
743
-
743
+
744
744
case time.Time :
745
745
// Format to string for time+date Fields
746
746
// Data is packed in case reflect.String below
747
747
(* args )[i ] = (* args )[i ].(time.Time ).Format (TIME_FORMAT )
748
748
}
749
-
749
+
750
750
pv = reflect .ValueOf ((* args )[i ])
751
751
switch pv .Kind () {
752
752
case reflect .Int64 :
753
- paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_LONGLONG ),0x0 }... )
753
+ paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_LONGLONG ), 0x0 }... )
754
754
val := int64ToBytes (pv .Int ())
755
755
pktLen += len (val )
756
756
paramValues = append (paramValues , val )
757
757
continue
758
-
758
+
759
759
case reflect .Float64 :
760
- paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_DOUBLE ),0x0 }... )
760
+ paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_DOUBLE ), 0x0 }... )
761
761
val := float64ToBytes (pv .Float ())
762
762
pktLen += len (val )
763
763
paramValues = append (paramValues , val )
764
764
continue
765
-
765
+
766
766
case reflect .Bool :
767
- paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_TINY ),0x0 }... )
767
+ paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_TINY ), 0x0 }... )
768
768
val := pv .Bool ()
769
769
pktLen ++
770
770
if val {
@@ -773,28 +773,28 @@ func (stmt mysqlStmt) buildExecutePacket(args *[]driver.Value) (e error) {
773
773
paramValues = append (paramValues , []byte {byte (0 )})
774
774
}
775
775
continue
776
-
776
+
777
777
case reflect .String :
778
- paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_STRING ),0x0 }... )
778
+ paramTypes = append (paramTypes , []byte {byte (FIELD_TYPE_STRING ), 0x0 }... )
779
779
val := []byte (pv .String ())
780
780
valLen = len (val )
781
781
lcb := lengthCodedBinaryToBytes (uint64 (valLen ))
782
782
pktLen += valLen + len (lcb )
783
783
paramValues = append (paramValues , lcb )
784
784
paramValues = append (paramValues , val )
785
785
continue
786
-
786
+
787
787
default :
788
788
return fmt .Errorf ("Invalid Value: %s" , pv .Kind ().String ())
789
789
}
790
790
}
791
-
791
+
792
792
data := make ([]byte , 0 , pktLen + 4 )
793
-
793
+
794
794
// Add the packet header
795
795
data = append (data , uint24ToBytes (uint32 (pktLen ))... )
796
796
data = append (data , stmt .mc .sequence )
797
-
797
+
798
798
// code [1 byte]
799
799
data = append (data , byte (COM_STMT_EXECUTE ))
800
800
@@ -806,29 +806,29 @@ func (stmt mysqlStmt) buildExecutePacket(args *[]driver.Value) (e error) {
806
806
807
807
// iteration_count [4 bytes]
808
808
data = append (data , uint32ToBytes (1 )... )
809
-
809
+
810
810
// append nullBitMap [(param_count+7)/8 bytes]
811
- if stmt .paramCount > 0 {
811
+ if stmt .paramCount > 0 {
812
812
// Convert bitMask to bytes
813
813
nullBitMap := make ([]byte , (stmt .paramCount + 7 )/ 8 )
814
814
for i = 0 ; i < len (nullBitMap ); i ++ {
815
815
nullBitMap [i ] = byte (bitMask >> uint (i * 8 ))
816
816
}
817
-
817
+
818
818
data = append (data , nullBitMap ... )
819
819
}
820
820
821
821
// newParameterBoundFlag 1 [1 byte]
822
822
data = append (data , byte (1 ))
823
-
823
+
824
824
// type of parameters [n*2 byte]
825
825
data = append (data , paramTypes ... )
826
-
826
+
827
827
// values for the parameters [n byte]
828
828
for _ , paramValue := range paramValues {
829
829
data = append (data , paramValue ... )
830
830
}
831
-
831
+
832
832
return stmt .mc .writePacket (& data )
833
833
}
834
834
0 commit comments