@@ -29,38 +29,32 @@ Query.prototype.start = function() {
29
29
this . emit ( 'packet' , new Packets . ComQueryPacket ( this . sql ) ) ;
30
30
} ;
31
31
32
- Query . prototype . determinePacket = function ( firstByte , parser ) {
33
- if ( firstByte === 0 ) {
34
- // If we have a resultSet and got one eofPacket
35
- if ( this . _resultSet && this . _resultSet . eofPackets . length === 1 ) {
36
- // Then this is a RowDataPacket with an empty string in the first column.
37
- // See: https://github.com/mysqljs/mysql/issues/222
38
- } else if ( this . _resultSet && this . _resultSet . resultSetHeaderPacket
39
- && this . _resultSet . resultSetHeaderPacket . fieldCount !== null ) {
40
- return Packets . FieldPacket ;
41
- } else {
42
- return undefined ;
32
+ Query . prototype . determinePacket = function determinePacket ( byte , parser ) {
33
+ var resultSet = this . _resultSet ;
34
+
35
+ if ( ! resultSet ) {
36
+ switch ( byte ) {
37
+ case 0x00 : return Packets . OkPacket ;
38
+ case 0xff : return Packets . ErrorPacket ;
39
+ default : return Packets . ResultSetHeaderPacket ;
43
40
}
44
41
}
45
42
46
- if ( firstByte === 255 ) {
47
- return undefined ;
43
+ if ( resultSet . eofPackets . length === 0 ) {
44
+ return ( resultSet . fieldPackets . length < resultSet . resultSetHeaderPacket . fieldCount )
45
+ ? Packets . FieldPacket
46
+ : Packets . EofPacket ;
48
47
}
49
48
50
- // EofPacket's are 5 bytes in mysql >= 4.1
51
- // This is the only / best way to differentiate their firstByte from a 9
52
- // byte length coded binary.
53
- if ( firstByte === 0xfe && parser . packetLength ( ) < 9 ) {
54
- return Packets . EofPacket ;
49
+ if ( byte === 0xff ) {
50
+ return Packets . ErrorPacket ;
55
51
}
56
52
57
- if ( ! this . _resultSet ) {
58
- return Packets . ResultSetHeaderPacket ;
53
+ if ( byte === 0xfe && parser . packetLength ( ) < 9 ) {
54
+ return Packets . EofPacket ;
59
55
}
60
56
61
- return ( this . _resultSet . eofPackets . length === 0 )
62
- ? Packets . FieldPacket
63
- : Packets . RowDataPacket ;
57
+ return Packets . RowDataPacket ;
64
58
} ;
65
59
66
60
Query . prototype [ 'OkPacket' ] = function ( packet ) {
@@ -95,11 +89,10 @@ Query.prototype['ErrorPacket'] = function(packet) {
95
89
} ;
96
90
97
91
Query . prototype [ 'ResultSetHeaderPacket' ] = function ( packet ) {
98
- this . _resultSet = new ResultSet ( packet ) ;
99
-
100
- // used by LOAD DATA LOCAL INFILE queries
101
92
if ( packet . fieldCount === null ) {
102
93
this . _sendLocalDataFile ( packet . extra ) ;
94
+ } else {
95
+ this . _resultSet = new ResultSet ( packet ) ;
103
96
}
104
97
} ;
105
98
0 commit comments