MCPcopy Index your code
hub / github.com/pingcap/tidb / QuerySQLWithColumns

Method QuerySQLWithColumns

dumpling/export/conn.go:56–85  ·  view source on GitHub ↗

QuerySQLWithColumns defines query statement, and connect to real DB and get results for special column names

(tctx *tcontext.Context, columns []string, query string, args ...any)

Source from the content-addressed store, hash-verified

54
55// QuerySQLWithColumns defines query statement, and connect to real DB and get results for special column names
56func (conn *BaseConn) QuerySQLWithColumns(tctx *tcontext.Context, columns []string, query string, args ...any) ([][]string, error) {
57 retryTime := 0
58 var results [][]string
59 err := utils.WithRetry(tctx, func() (err error) {
60 retryTime++
61 if retryTime > 1 && conn.rebuildConnFn != nil {
62 conn.DBConn, err = conn.rebuildConnFn(conn.DBConn, false)
63 if err != nil {
64 tctx.L().Warn("rebuild connection failed", zap.Error(err))
65 return
66 }
67 }
68 rows, err := conn.DBConn.QueryContext(tctx, query, args...)
69 if err != nil {
70 tctx.L().Info("cannot execute query", zap.Int("retryTime", retryTime), zap.String("sql", query),
71 zap.Any("args", args), zap.Error(err))
72 return errors.Annotatef(err, "sql: %s", query)
73 }
74 results, err = GetSpecifiedColumnValuesAndClose(rows, columns...)
75 if err != nil {
76 tctx.L().Info("cannot execute query", zap.Int("retryTime", retryTime), zap.String("sql", query),
77 zap.Any("args", args), zap.Error(err))
78 results = nil
79 return errors.Annotatef(err, "sql: %s", query)
80 }
81 return err
82 }, conn.backOffer)
83 conn.backOffer.Reset()
84 return results, err
85}
86
87// ExecSQL defines exec statement, and connect to real DB.
88func (conn *BaseConn) ExecSQL(tctx *tcontext.Context, canRetryFunc func(sql.Result, error) error, query string, args ...any) error {

Callers 5

ShowCreateSequenceFunction · 0.80
GetPrimaryKeyColumnsFunction · 0.80
getNumericIndexFunction · 0.80
buildSelectFieldFunction · 0.80

Calls 8

WithRetryFunction · 0.92
WarnMethod · 0.80
ErrorMethod · 0.65
QueryContextMethod · 0.65
StringMethod · 0.65
ResetMethod · 0.65
LMethod · 0.45

Tested by

no test coverage detected