diff --git a/mysql/resultset.go b/mysql/resultset.go index eee819aee..f1fa19316 100644 --- a/mysql/resultset.go +++ b/mysql/resultset.go @@ -79,6 +79,9 @@ func (r *Resultset) Reset(fieldsCount int) { } } +// RowNumber is returning the number of rows in the [Resultset]. +// +// For a nil [Resultset] 0 is returned. func (r *Resultset) RowNumber() int { if r == nil { return 0 @@ -86,7 +89,13 @@ func (r *Resultset) RowNumber() int { return len(r.Values) } +// ColumnNumber is returning the number of fields in the [Resultset]. +// +// For a nil [Resultset] 0 is returned. func (r *Resultset) ColumnNumber() int { + if r == nil { + return 0 + } return len(r.Fields) } diff --git a/mysql/resultset_test.go b/mysql/resultset_test.go new file mode 100644 index 000000000..b844a2127 --- /dev/null +++ b/mysql/resultset_test.go @@ -0,0 +1,10 @@ +package mysql + +import "testing" + +func TestColumnNumber(t *testing.T) { + r := Result{} + // Make sure ColumnNumber doesn't panic if ResultSet is nil + // https://github.com/go-mysql-org/go-mysql/issues/964 + r.ColumnNumber() +}