diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-07-04 21:10:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-04 15:10:46 +0200 |
commit | 760af187ba65948f22e96dafb2cc364e163ab204 (patch) | |
tree | 274b7ef7a19c0e34749a809435f0571345dc6fd0 /vendor/xorm.io/xorm/scan.go | |
parent | 32fd11395b7631cd226783a98b86e55192bd99ca (diff) | |
download | gitea-760af187ba65948f22e96dafb2cc364e163ab204.tar.gz gitea-760af187ba65948f22e96dafb2cc364e163ab204.zip |
Upgrade xorm to v1.1.1 (#16339)
Diffstat (limited to 'vendor/xorm.io/xorm/scan.go')
-rw-r--r-- | vendor/xorm.io/xorm/scan.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/xorm.io/xorm/scan.go b/vendor/xorm.io/xorm/scan.go new file mode 100644 index 0000000000..e19037a058 --- /dev/null +++ b/vendor/xorm.io/xorm/scan.go @@ -0,0 +1,67 @@ +// Copyright 2021 The Xorm Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package xorm + +import ( + "database/sql" + + "xorm.io/xorm/core" +) + +func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) { + var scanResults = make([]interface{}, len(fields)) + for i := 0; i < len(fields); i++ { + var s sql.NullString + scanResults[i] = &s + } + + if err := rows.Scan(scanResults...); err != nil { + return nil, err + } + + result := make(map[string]string, len(fields)) + for ii, key := range fields { + s := scanResults[ii].(*sql.NullString) + result[key] = s.String + } + return result, nil +} + +func (engine *Engine) row2mapBytes(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string][]byte, error) { + var scanResults = make([]interface{}, len(fields)) + for i := 0; i < len(fields); i++ { + var s sql.NullString + scanResults[i] = &s + } + + if err := rows.Scan(scanResults...); err != nil { + return nil, err + } + + result := make(map[string][]byte, len(fields)) + for ii, key := range fields { + s := scanResults[ii].(*sql.NullString) + result[key] = []byte(s.String) + } + return result, nil +} + +func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fields []string) ([]string, error) { + results := make([]string, 0, len(fields)) + var scanResults = make([]interface{}, len(fields)) + for i := 0; i < len(fields); i++ { + var s sql.NullString + scanResults[i] = &s + } + + if err := rows.Scan(scanResults...); err != nil { + return nil, err + } + + for i := 0; i < len(fields); i++ { + results = append(results, scanResults[i].(*sql.NullString).String) + } + return results, nil +} |