| 437 | } |
| 438 | |
| 439 | func (r *Remote) LoadFormatCollation(timeout uint) ([]dto.MysqlFormatCollationOption, error) { |
| 440 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) |
| 441 | defer cancel() |
| 442 | |
| 443 | rows, err := r.Client.QueryContext(ctx, "SELECT CHARACTER_SET_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS ORDER BY CHARACTER_SET_NAME, COLLATION_NAME;") |
| 444 | if errors.Is(ctx.Err(), context.DeadlineExceeded) { |
| 445 | return nil, buserr.New("ErrExecTimeOut") |
| 446 | } |
| 447 | if err != nil { |
| 448 | return nil, err |
| 449 | } |
| 450 | defer func() { _ = rows.Close() }() |
| 451 | |
| 452 | formatMap := make(map[string][]string) |
| 453 | for rows.Next() { |
| 454 | var item FormatCollation |
| 455 | if err := rows.Scan(&item.Format, &item.Collation); err != nil { |
| 456 | return nil, err |
| 457 | } |
| 458 | if !item.Format.Valid { |
| 459 | continue |
| 460 | } |
| 461 | if _, ok := formatMap[item.Format.String]; !ok { |
| 462 | formatMap[item.Format.String] = []string{item.Collation.String} |
| 463 | } else { |
| 464 | formatMap[item.Format.String] = append(formatMap[item.Format.String], item.Collation.String) |
| 465 | } |
| 466 | } |
| 467 | options := []dto.MysqlFormatCollationOption{} |
| 468 | for key, val := range formatMap { |
| 469 | options = append(options, dto.MysqlFormatCollationOption{ |
| 470 | Format: key, |
| 471 | Collations: val, |
| 472 | }) |
| 473 | } |
| 474 | |
| 475 | return options, nil |
| 476 | } |
| 477 | |
| 478 | func (r *Remote) ExecSQLForHosts(timeout uint) ([]string, error) { |
| 479 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) |