MCPcopy
hub / github.com/pingcap/tidb / GetSpecifiedColumnValueAndClose

Function GetSpecifiedColumnValueAndClose

dumpling/export/sql.go:782–811  ·  view source on GitHub ↗

GetSpecifiedColumnValueAndClose get columns' values whose name is equal to columnName and close the given rows

(rows *sql.Rows, columnName string)

Source from the content-addressed store, hash-verified

780
781// GetSpecifiedColumnValueAndClose get columns' values whose name is equal to columnName and close the given rows
782func GetSpecifiedColumnValueAndClose(rows *sql.Rows, columnName string) ([]string, error) {
783 if rows == nil {
784 return []string{}, nil
785 }
786 defer rows.Close()
787 var strs []string
788 columns, _ := rows.Columns()
789 addr := make([]any, len(columns))
790 oneRow := make([]sql.NullString, len(columns))
791 fieldIndex := -1
792 for i, col := range columns {
793 if strings.EqualFold(col, columnName) {
794 fieldIndex = i
795 }
796 addr[i] = &oneRow[i]
797 }
798 if fieldIndex == -1 {
799 return strs, nil
800 }
801 for rows.Next() {
802 err := rows.Scan(addr...)
803 if err != nil {
804 return strs, errors.Trace(err)
805 }
806 if oneRow[fieldIndex].Valid {
807 strs = append(strs, oneRow[fieldIndex].String)
808 }
809 }
810 return strs, errors.Trace(rows.Err())
811}
812
813// GetSpecifiedColumnValuesAndClose get columns' values whose name is equal to columnName
814func GetSpecifiedColumnValuesAndClose(rows *sql.Rows, columnName ...string) ([][]string, error) {

Callers 3

GetPdAddrsFunction · 0.85
GetTiDBDDLIDsFunction · 0.85

Calls 4

CloseMethod · 0.65
ColumnsMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65

Tested by 1