Skip to content

Commit 6c3f3a6

Browse files
authored
server: Correct the check for Resultset (#983)
1 parent ffd15ad commit 6c3f3a6

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

mysql/result.go

+7
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ func (r *Result) Close() {
3434
r.Resultset = nil
3535
}
3636
}
37+
38+
func (r *Result) HasResultset() bool {
39+
if r.Resultset != nil && len(r.Resultset.Fields) > 0 {
40+
return true
41+
}
42+
return false
43+
}

mysql/result_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package mysql
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestHasResultset_false(t *testing.T) {
10+
r := NewResultReserveResultset(0)
11+
b := r.HasResultset()
12+
require.Equal(t, false, b)
13+
}
14+
15+
func TestHasResultset_true(t *testing.T) {
16+
r := NewResultReserveResultset(1)
17+
b := r.HasResultset()
18+
require.Equal(t, true, b)
19+
}

server/resp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (c *Conn) WriteValue(value interface{}) error {
230230
case nil:
231231
return c.writeOK(nil)
232232
case *Result:
233-
if v != nil && v.Resultset != nil {
233+
if v != nil && v.HasResultset() {
234234
return c.writeResultset(v.Resultset)
235235
} else {
236236
return c.writeOK(v)

0 commit comments

Comments
 (0)