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

mysql: Fix ColumnNumber() panic with nil Resultset #968

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions mysql/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,23 @@ 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
}
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)
}

Expand Down
10 changes: 10 additions & 0 deletions mysql/resultset_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
Loading