MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / ExecSQLForHosts

Method ExecSQLForHosts

agent/utils/mysql/client/remote.go:478–499  ·  view source on GitHub ↗
(timeout uint)

Source from the content-addressed store, hash-verified

476}
477
478func (r *Remote) ExecSQLForHosts(timeout uint) ([]string, error) {
479 ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
480 defer cancel()
481
482 results, err := r.Client.QueryContext(ctx, "select host from mysql.user where user='root';")
483 if err != nil {
484 return nil, err
485 }
486 if errors.Is(ctx.Err(), context.DeadlineExceeded) {
487 return nil, buserr.New("ErrExecTimeOut")
488 }
489 var rows []string
490 defer func() { _ = results.Close() }()
491 for results.Next() {
492 var host string
493 if err := results.Scan(&host); err != nil {
494 continue
495 }
496 rows = append(rows, host)
497 }
498 return rows, nil
499}
500
501func loadImage(dbType, version string) (string, error) {
502 cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())

Callers 1

ChangePasswordMethod · 0.95

Calls 4

IsMethod · 0.80
NextMethod · 0.80
CloseMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected