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

hotfix: fix the field index conflict inside the method Scan of ResultSet #305

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
16 changes: 8 additions & 8 deletions result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,31 @@ func (res ResultSet) Scan(v interface{}) error {

// Scan scans the rows into the given value.
func (res ResultSet) scanRow(row *nebula.Row, colNames []string, t reflect.Type) (reflect.Value, error) {
rowValues := row.GetValues()
rowVals := row.GetValues()

val := reflect.New(t).Elem()

for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
for fIdx := 0; fIdx < t.NumField(); fIdx++ {
f := t.Field(fIdx)
tag := f.Tag.Get("nebula")

if tag == "" {
continue
}

i := IndexOf(colNames, tag)
if i == -1 {
cIdx := IndexOf(colNames, tag)
if cIdx == -1 {
// It is possible that the tag is not in the result set
continue
}

rowVal := rowValues[i]
rowVal := rowVals[cIdx]

switch f.Type.Kind() {
case reflect.Int64:
val.Field(i).SetInt(rowVal.GetIVal())
val.Field(fIdx).SetInt(rowVal.GetIVal())
case reflect.String:
val.Field(i).SetString(string(rowVal.GetSVal()))
val.Field(fIdx).SetString(string(rowVal.GetSVal()))
default:
return val, errors.New("scan: not support type")
}
Expand Down
Loading