Skip to content

Commit a4724a0

Browse files
committed
ability to send multiple resultsets from handleQuery
1 parent 0c5789d commit a4724a0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

server/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Handler interface {
1313
UseDB(dbName string) error
1414
//handle COM_QUERY command, like SELECT, INSERT, UPDATE, etc...
1515
//If Result has a Resultset (SELECT, SHOW, etc...), we will send this as the response, otherwise, we will send Result
16-
HandleQuery(query string) (*Result, error)
16+
HandleQuery(query string) ([]*Result, error)
1717
//handle COM_FILED_LIST command
1818
HandleFieldList(table string, fieldWildcard string) ([]*Field, error)
1919
//handle COM_STMT_PREPARE, params is the param number for this statement, columns is the column number

server/resp.go

+20
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,26 @@ func (c *Conn) writeValue(value interface{}) error {
185185
} else {
186186
return c.writeOK(v)
187187
}
188+
case []*Result:
189+
if len(v) == 0 {
190+
return c.writeValue(nil)
191+
}
192+
193+
c.status |= SERVER_MORE_RESULTS_EXISTS
194+
195+
for i, res := range v {
196+
if i == len(v) - 1 {
197+
c.status &= ^SERVER_MORE_RESULTS_EXISTS
198+
}
199+
200+
if err := c.writeValue(res); err != nil {
201+
c.status &= ^SERVER_MORE_RESULTS_EXISTS
202+
203+
return err
204+
}
205+
}
206+
207+
return nil
188208
case []*Field:
189209
return c.writeFieldList(v)
190210
case *Stmt:

0 commit comments

Comments
 (0)