@@ -200,7 +200,7 @@ func (c *Client) ChangeDb(dbname string) (err os.Error) {
200
200
}
201
201
// Read result from server
202
202
c .sequence ++
203
- _ , err = c .getResult (PACKET_OK | PACKET_ERROR )
203
+ _ , err = c .getResult (PACKET_OK | PACKET_ERROR , nil )
204
204
return
205
205
}
206
206
@@ -232,7 +232,12 @@ func (c *Client) Query(sql string) (err os.Error) {
232
232
}
233
233
// Read result from server
234
234
c .sequence ++
235
- _ , err = c .getResult (PACKET_OK | PACKET_ERROR | PACKET_RESULT )
235
+ _ , err = c .getResult (PACKET_OK | PACKET_ERROR | PACKET_RESULT , nil )
236
+ if err != nil || c .result == nil {
237
+ return
238
+ }
239
+ // Store fields
240
+ err = c .getFields ()
236
241
return
237
242
}
238
243
@@ -248,14 +253,8 @@ func (c *Client) StoreResult() (result *Result, err os.Error) {
248
253
if c .result .mode != RESULT_UNUSED {
249
254
return nil , & ClientError {CR_COMMANDS_OUT_OF_SYNC , CR_COMMANDS_OUT_OF_SYNC_STR }
250
255
}
251
- // Set client and storage mode
252
- c .result .c = c
256
+ // Set storage mode
253
257
c .result .mode = RESULT_STORED
254
- // Store fields
255
- err = c .getFields ()
256
- if err != nil {
257
- return
258
- }
259
258
// Store all rows
260
259
err = c .getAllRows ()
261
260
if err != nil {
@@ -277,14 +276,8 @@ func (c *Client) UseResult() (result *Result, err os.Error) {
277
276
if c .result .mode != RESULT_UNUSED {
278
277
return nil , & ClientError {CR_COMMANDS_OUT_OF_SYNC , CR_COMMANDS_OUT_OF_SYNC_STR }
279
278
}
280
- // Set client and storage mode
281
- c .result .c = c
279
+ // Set storage mode
282
280
c .result .mode = RESULT_USED
283
- // Store fields
284
- err = c .getFields ()
285
- if err != nil {
286
- return
287
- }
288
281
return c .result , nil
289
282
}
290
283
@@ -296,14 +289,6 @@ func (c *Client) FreeResult() (err os.Error) {
296
289
if ! c .checkResult () {
297
290
return & ClientError {CR_NO_RESULT_SET , CR_NO_RESULT_SET_STR }
298
291
}
299
- // Check that result was used/stored
300
- if c .result .mode == RESULT_UNUSED {
301
- // Read fields
302
- err = c .getFields ()
303
- if err != nil {
304
- return
305
- }
306
- }
307
292
// Check for unread rows
308
293
if ! c .result .allRead {
309
294
// Read all rows
@@ -346,7 +331,7 @@ func (c *Client) NextResult() (more bool, err os.Error) {
346
331
}
347
332
// Read result from server
348
333
c .sequence ++
349
- _ , err = c .getResult (PACKET_OK | PACKET_ERROR | PACKET_RESULT )
334
+ _ , err = c .getResult (PACKET_OK | PACKET_ERROR | PACKET_RESULT , nil )
350
335
return
351
336
}
352
337
@@ -556,7 +541,7 @@ func (c *Client) connect() (err os.Error) {
556
541
}
557
542
// Read result from server
558
543
c .sequence ++
559
- eof , err := c .getResult (PACKET_OK | PACKET_ERROR | PACKET_EOF )
544
+ eof , err := c .getResult (PACKET_OK | PACKET_ERROR | PACKET_EOF , nil )
560
545
// If eof need to authenticate with a 3.23 password
561
546
if eof {
562
547
c .sequence ++
@@ -573,7 +558,7 @@ func (c *Client) connect() (err os.Error) {
573
558
c .log (1 , "[%d] Sent old password packet" , p .sequence )
574
559
// Read result
575
560
c .sequence ++
576
- _ , err = c .getResult (PACKET_OK | PACKET_ERROR )
561
+ _ , err = c .getResult (PACKET_OK | PACKET_ERROR , nil )
577
562
}
578
563
return
579
564
}
@@ -778,7 +763,7 @@ func (c *Client) getFields() (err os.Error) {
778
763
// Read fields till EOF is returned
779
764
for {
780
765
c .sequence ++
781
- eof , err := c .getResult (PACKET_FIELD | PACKET_EOF )
766
+ eof , err := c .getResult (PACKET_FIELD | PACKET_EOF , nil )
782
767
if err != nil {
783
768
return
784
769
}
@@ -798,7 +783,7 @@ func (c *Client) getRow() (eof bool, err os.Error) {
798
783
}
799
784
// Read next row packet or EOF
800
785
c .sequence ++
801
- eof , err = c .getResult (PACKET_ROW | PACKET_EOF )
786
+ eof , err = c .getResult (PACKET_ROW | PACKET_EOF , nil )
802
787
return
803
788
}
804
789
@@ -817,7 +802,7 @@ func (c *Client) getAllRows() (err os.Error) {
817
802
}
818
803
819
804
// Get result
820
- func (c * Client ) getResult (types packetType ) (eof bool , err os.Error ) {
805
+ func (c * Client ) getResult (types packetType , s * Statement ) (eof bool , err os.Error ) {
821
806
// Log read result
822
807
c .log (1 , "Reading result packet from server" )
823
808
// Get result packet
@@ -842,6 +827,10 @@ func (c *Client) getResult(types packetType) (eof bool, err os.Error) {
842
827
err = c .processFieldResult (p .(* packetField ))
843
828
case * packetRowData :
844
829
err = c .processRowResult (p .(* packetRowData ))
830
+ case * packetPrepareOK :
831
+ err = s .processPrepareOKResult (p .(* packetPrepareOK ))
832
+ case * packetParameter :
833
+ err = s .processParamResult (p .(* packetParameter ))
845
834
}
846
835
return
847
836
}
@@ -925,6 +914,7 @@ func (c *Client) processResultSetResult(p *packetResultSet) (err os.Error) {
925
914
}
926
915
// Create new result
927
916
c .result = & Result {
917
+ c : c ,
928
918
fieldCount : p .fieldCount ,
929
919
}
930
920
return
0 commit comments