GetColumnTypes gets *sql.ColumnTypes from a specified table
(tctx *tcontext.Context, db *BaseConn, fields, database, table string)
| 599 | |
| 600 | // GetColumnTypes gets *sql.ColumnTypes from a specified table |
| 601 | func GetColumnTypes(tctx *tcontext.Context, db *BaseConn, fields, database, table string) ([]*sql.ColumnType, error) { |
| 602 | query := fmt.Sprintf("SELECT %s FROM `%s`.`%s` LIMIT 1", fields, escapeString(database), escapeString(table)) |
| 603 | var colTypes []*sql.ColumnType |
| 604 | err := db.QuerySQL(tctx, func(rows *sql.Rows) error { |
| 605 | var err error |
| 606 | colTypes, err = rows.ColumnTypes() |
| 607 | if err == nil { |
| 608 | err = rows.Close() |
| 609 | } |
| 610 | failpoint.Inject("ChaosBrokenMetaConn", func(_ failpoint.Value) { |
| 611 | failpoint.Return(errors.New("connection is closed")) |
| 612 | }) |
| 613 | return errors.Annotatef(err, "sql: %s", query) |
| 614 | }, func() { |
| 615 | colTypes = nil |
| 616 | }, query) |
| 617 | if err != nil { |
| 618 | return nil, err |
| 619 | } |
| 620 | return colTypes, nil |
| 621 | } |
| 622 | |
| 623 | // GetPrimaryKeyAndColumnTypes gets all primary columns and their types in ordinal order |
| 624 | func GetPrimaryKeyAndColumnTypes(tctx *tcontext.Context, conn *BaseConn, meta TableMeta) ([]string, []string, error) { |
no test coverage detected