From a8ddcde8832405f237ef1f57cb7fc48ff18c19d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E5=9D=A4=E5=AE=89?= Date: Mon, 3 Apr 2023 02:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96func=20(session=20*Session)?= =?UTF-8?q?=20slice2Bean=E6=96=B9=E6=B3=95=E4=B8=AD=E7=9A=84strings.ToLowe?= =?UTF-8?q?r=E4=BB=A5=E5=8F=8A=E5=87=8F=E5=B0=91map=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=92=8C=E8=AE=BF=E9=97=AE=E6=AC=A1=E6=95=B0=EF=BC=88=E5=AF=B9?= =?UTF-8?q?=E5=BA=94issue:https://gitea.com/xorm/xorm/issues/2243=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- session.go | 13 +------------ session_find.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/session.go b/session.go index d232d30d..67fedd70 100644 --- a/session.go +++ b/session.go @@ -710,20 +710,9 @@ func (session *Session) slice2Bean(scanResults []interface{}, allColum *AllColum buildAfterProcessors(session, bean) - tempMap := make(map[string]int) var pk schemas.PK for i, field := range allColum.Fields { - var idx int - var ok bool - - if idx, ok = tempMap[field.LowerFieldName]; !ok { - idx = 0 - } else { - idx++ - } - tempMap[field.LowerFieldName] = idx - - col, fieldValue, err := getField(dataStruct, table, field.FieldName, idx) + col, fieldValue, err := getField(dataStruct, table, field.FieldName, field.TempIndex) if _, ok := err.(ErrFieldIsNotExist); ok { continue } else if err != nil { diff --git a/session_find.go b/session_find.go index 483b4d71..e0b8d295 100644 --- a/session_find.go +++ b/session_find.go @@ -167,6 +167,7 @@ type QueryedField struct { FieldName string LowerFieldName string ColumnType *sql.ColumnType + TempIndex int } type AllColumn struct { @@ -190,6 +191,22 @@ func ParseQueryRows(fieldNames []string, types []*sql.ColumnType) *AllColumn { } allColumn.Fields = fields + + tempMap := make(map[string]int) + for _, field := range fields { + var idx int + var ok bool + + if idx, ok = tempMap[field.LowerFieldName]; !ok { + idx = 0 + } else { + idx++ + } + + tempMap[field.LowerFieldName] = idx + field.TempIndex = idx + } + return &allColumn }