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