@@ -347,27 +347,31 @@ where
347347}
348348
349349impl < ' a , W : Write + ' a > RowWriter < ' a , W > {
350- fn finish_inner ( & mut self ) -> io:: Result < ( ) > {
350+ fn finish_inner ( & mut self , complete : bool ) -> io:: Result < ( ) > {
351351 if self . finished {
352352 return Ok ( ( ) ) ;
353353 }
354+
354355 self . finished = true ;
355356
356357 if !self . columns . is_empty ( ) && self . col != 0 {
357358 self . end_row ( ) ?;
358359 }
359360
360- if self . columns . is_empty ( ) {
361- // response to no column query is always an OK packet
362- // we've kept track of the number of rows in col (hacky, I know)
363- self . result . as_mut ( ) . unwrap ( ) . last_end = Some ( Finalizer :: Ok {
364- rows : self . col as u64 ,
365- last_insert_id : 0 ,
366- } ) ;
367- } else {
368- // we wrote out at least one row
369- self . result . as_mut ( ) . unwrap ( ) . last_end = Some ( Finalizer :: Eof ) ;
361+ if complete {
362+ if self . columns . is_empty ( ) {
363+ // response to no column query is always an OK packet
364+ // we've kept track of the number of rows in col (hacky, I know)
365+ self . result . as_mut ( ) . unwrap ( ) . last_end = Some ( Finalizer :: Ok {
366+ rows : self . col as u64 ,
367+ last_insert_id : 0 ,
368+ } ) ;
369+ } else {
370+ // we wrote out at least one row
371+ self . result . as_mut ( ) . unwrap ( ) . last_end = Some ( Finalizer :: Eof ) ;
372+ }
370373 }
374+
371375 Ok ( ( ) )
372376 }
373377
@@ -378,15 +382,26 @@ impl<'a, W: Write + 'a> RowWriter<'a, W> {
378382
379383 /// End this resultset response, and indicate to the client that no more rows are coming.
380384 pub fn finish_one ( mut self ) -> io:: Result < QueryResultWriter < ' a , W > > {
381- self . finish_inner ( ) ?;
385+ self . finish_inner ( true ) ?;
386+
382387 // we know that dropping self will see self.finished == true,
383388 // and so Drop won't try to use self.result.
384389 Ok ( self . result . take ( ) . unwrap ( ) )
385390 }
391+
392+ /// End this resultset response, and indicate to the client there was an error.
393+ pub fn finish_error < E > ( mut self , kind : ErrorKind , msg : & E ) -> io:: Result < ( ) >
394+ where
395+ E : Borrow < [ u8 ] > ,
396+ {
397+ self . finish_inner ( false ) ?;
398+
399+ self . result . take ( ) . unwrap ( ) . error ( kind, msg)
400+ }
386401}
387402
388403impl < ' a , W : Write + ' a > Drop for RowWriter < ' a , W > {
389404 fn drop ( & mut self ) {
390- self . finish_inner ( ) . unwrap ( ) ;
405+ self . finish_inner ( true ) . unwrap ( ) ;
391406 }
392407}
0 commit comments