diff --git a/clickhouse_rows.go b/clickhouse_rows.go index b4b7c79d68..4b5342c520 100644 --- a/clickhouse_rows.go +++ b/clickhouse_rows.go @@ -25,14 +25,14 @@ import ( ) type rows struct { - err error - row int - conn *connect - block *proto.Block - totals *proto.Block - errors chan error - stream chan *proto.Block - columns []string + err error + row int + block *proto.Block + totals *proto.Block + errors chan error + stream chan *proto.Block + columns []string + structMap structMap } func (r *rows) Next() (result bool) { @@ -76,7 +76,7 @@ func (r *rows) Scan(dest ...interface{}) error { } func (r *rows) ScanStruct(dest interface{}) error { - values, err := r.conn.structMap.Map("ScanStruct", r.columns, dest, true) + values, err := r.structMap.Map("ScanStruct", r.columns, dest, true) if err != nil { return err } @@ -119,7 +119,7 @@ func (r *row) Err() error { } func (r *row) ScanStruct(dest interface{}) error { - values, err := r.rows.conn.structMap.Map("ScanStruct", r.rows.columns, dest, true) + values, err := r.rows.structMap.Map("ScanStruct", r.rows.columns, dest, true) if err != nil { return err } diff --git a/conn_query.go b/conn_query.go index 1160dd38a7..4066a107be 100644 --- a/conn_query.go +++ b/conn_query.go @@ -32,6 +32,7 @@ func (c *connect) query(ctx context.Context, release func(*connect, error), quer ) if err != nil { + release(c, err) return nil, err } @@ -41,12 +42,14 @@ func (c *connect) query(ctx context.Context, release func(*connect, error), quer } if err = c.sendQuery(body, &options); err != nil { + release(c, err) return nil, err } init, err := c.firstBlock(ctx, onProcess) if err != nil { + release(c, err) return nil, err } @@ -69,11 +72,11 @@ func (c *connect) query(ctx context.Context, release func(*connect, error), quer }() return &rows{ - conn: c, - block: init, - stream: stream, - errors: errors, - columns: init.ColumnsNames(), + block: init, + stream: stream, + errors: errors, + columns: init.ColumnsNames(), + structMap: c.structMap, }, nil }