clickhouse_ping.go 537 B

12345678910111213141516171819202122232425262728
  1. package clickhouse
  2. import (
  3. "context"
  4. "database/sql/driver"
  5. "github.com/ClickHouse/clickhouse-go/lib/protocol"
  6. )
  7. func (ch *clickhouse) Ping(ctx context.Context) error {
  8. return ch.ping(ctx)
  9. }
  10. func (ch *clickhouse) ping(ctx context.Context) error {
  11. if ch.conn.closed {
  12. return driver.ErrBadConn
  13. }
  14. ch.logf("-> ping")
  15. finish := ch.watchCancel(ctx)
  16. defer finish()
  17. if err := ch.encoder.Uvarint(protocol.ClientPing); err != nil {
  18. return err
  19. }
  20. if err := ch.encoder.Flush(); err != nil {
  21. return err
  22. }
  23. return ch.process()
  24. }