QuerySQL defines query statement, and connect to real DB.
(tctx *tcontext.Context, handleOneRow func(*sql.Rows) error, reset func(), query string, args ...any)
| 30 | |
| 31 | // QuerySQL defines query statement, and connect to real DB. |
| 32 | func (conn *BaseConn) QuerySQL(tctx *tcontext.Context, handleOneRow func(*sql.Rows) error, reset func(), query string, args ...any) error { |
| 33 | retryTime := 0 |
| 34 | err := utils.WithRetry(tctx, func() (err error) { |
| 35 | retryTime++ |
| 36 | if retryTime > 1 && conn.rebuildConnFn != nil { |
| 37 | conn.DBConn, err = conn.rebuildConnFn(conn.DBConn, false) |
| 38 | if err != nil { |
| 39 | return |
| 40 | } |
| 41 | } |
| 42 | err = simpleQueryWithArgs(tctx, conn.DBConn, handleOneRow, query, args...) |
| 43 | if err != nil { |
| 44 | tctx.L().Info("cannot execute query", zap.Int("retryTime", retryTime), zap.String("sql", query), |
| 45 | zap.Any("args", args), zap.Error(err)) |
| 46 | reset() |
| 47 | return err |
| 48 | } |
| 49 | return nil |
| 50 | }, conn.backOffer) |
| 51 | conn.backOffer.Reset() |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | // QuerySQLWithColumns defines query statement, and connect to real DB and get results for special column names |
| 56 | func (conn *BaseConn) QuerySQLWithColumns(tctx *tcontext.Context, columns []string, query string, args ...any) ([][]string, error) { |
no test coverage detected