Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended ExecuteSelectStreaming #596

Merged
merged 7 commits into from
Nov 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support streaming resultsets in writeResultset
Reinier Schoof committed Jun 28, 2021
commit ed5efdb1b3f456a61c90940305d9921f5a5393a0
6 changes: 6 additions & 0 deletions client/resp.go
Original file line number Diff line number Diff line change
@@ -306,6 +306,9 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *Result,
result.Reset(int(columnCount))
}

// this is a streaming resultset
result.Resultset.Streaming = true

if err := c.readResultColumns(result); err != nil {
return errors.Trace(err)
}
@@ -320,6 +323,9 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *Result,
return errors.Trace(err)
}

// this resultset is done streaming
result.Resultset.StreamingDone = true

return nil
}

3 changes: 3 additions & 0 deletions mysql/resultset.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ type Resultset struct {
RawPkg []byte

RowDatas []RowData

Streaming bool
StreamingDone bool
}

var (
13 changes: 13 additions & 0 deletions server/resp.go
Original file line number Diff line number Diff line change
@@ -116,6 +116,13 @@ func (c *Conn) writeAuthMoreDataFastAuth() error {
}

func (c *Conn) writeResultset(r *Resultset) error {
// for a streaming resultset, that handled rowdata separately in a callback
// of type SelectPerRowCallback, we can suffice by ending the stream with
// an EOF
if r.StreamingDone {
return c.writeEOF()
}

columnLen := PutLengthEncodedInt(uint64(len(r.Fields)))

data := make([]byte, 4, 1024)
@@ -137,6 +144,12 @@ func (c *Conn) writeResultset(r *Resultset) error {
return err
}

// streaming resultsets handle rowdata in a separate callback of type
// SelectPerRowCallback so we're done here
if r.Streaming {
return nil
}

for _, v := range r.RowDatas {
data = data[0:4]
data = append(data, v...)