Skip to content

Commit

Permalink
hotfix: fix the field index conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Hao committed Jan 18, 2024
1 parent 3fe0bb1 commit d0e572a
Showing 1 changed file with 8 additions and 8 deletions.
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

0 comments on commit d0e572a

Please sign in to comment.