From b29ed6156c915e5f0273f5bbb0728cc9eec1fd59 Mon Sep 17 00:00:00 2001 From: Alexandr Mayorskiy Date: Tue, 10 Nov 2020 18:12:48 +0300 Subject: [PATCH] ability to send multiple resultsets from handleQuery --- mysql/result.go | 13 +++++++++++++ mysql/resultset.go | 2 ++ server/resp.go | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql/result.go b/mysql/result.go index 797a4af75..2c8e539ff 100644 --- a/mysql/result.go +++ b/mysql/result.go @@ -19,3 +19,16 @@ func (r *Result) Close() { r.Resultset = nil } } + +func (r *Result) ChainResultSet(rs *Resultset) { + if r.Resultset == nil { + r.Resultset = rs + return + } + + var lastRS *Resultset + + for lastRS = r.Resultset; lastRS.Next != nil; lastRS = lastRS.Next {} + + lastRS.Next = rs +} diff --git a/mysql/resultset.go b/mysql/resultset.go index 2da6e3b5f..5e4cf8f23 100644 --- a/mysql/resultset.go +++ b/mysql/resultset.go @@ -17,6 +17,8 @@ type Resultset struct { RawPkg []byte RowDatas []RowData + + Next *Resultset } var ( diff --git a/server/resp.go b/server/resp.go index db8632394..46ca6f9fa 100644 --- a/server/resp.go +++ b/server/resp.go @@ -181,7 +181,20 @@ func (c *Conn) writeValue(value interface{}) error { return c.writeOK(nil) case *Result: if v != nil && v.Resultset != nil { - return c.writeResultset(v.Resultset) + for rs := v.Resultset; rs != nil; rs = rs.Next { + if rs.Next != nil { + c.status |= SERVER_MORE_RESULTS_EXISTS + } + + err := c.writeResultset(rs) + c.status &= ^SERVER_MORE_RESULTS_EXISTS + + if err != nil { + return err + } + } + + return nil } else { return c.writeOK(v) }