From 463b3662c9a818b5bca8449a7304f86e85d28946 Mon Sep 17 00:00:00 2001 From: HarrisChu <1726587+HarrisChu@users.noreply.github.com> Date: Tue, 22 Jun 2021 14:04:48 +0800 Subject: [PATCH] pre-check use statement --- pkg/client/clientpool.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/client/clientpool.go b/pkg/client/clientpool.go index b3143ef2..b8aaa70b 100644 --- a/pkg/client/clientpool.go +++ b/pkg/client/clientpool.go @@ -122,13 +122,19 @@ func (p *ClientPool) Close() { } func (p *ClientPool) Init() error { + i := p.getActiveConnIdx() + if i == -1 { + return fmt.Errorf("no available session.") + } if p.postStart != nil && p.postStart.Commands != nil { - if i := p.getActiveConnIdx(); i != -1 { - if err := p.exec(i, *p.postStart.Commands); err != nil { - return err - } + if err := p.exec(i, *p.postStart.Commands); err != nil { + return err } } + // pre-check for use space statement + if err := p.exec(i, fmt.Sprintf("USE `%s`;", p.space)); err != nil { + return err + } for i := 0; i < p.concurrency; i++ { go func(i int) {