From 96406d2e3cd1c9b27b219b250ce5c15a64480baa Mon Sep 17 00:00:00 2001 From: Nelson-He Date: Wed, 13 Jul 2022 16:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E8=83=BD=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=E5=92=8C=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/client/client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 39c061c..8ecfdb2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -29,6 +29,8 @@ var ( openGaussSignature = regexp.MustCompile(`(?i)openGauss ([\d\.]+)\s`) openGaussType = "openGauss" + + createFuncProc = regexp.MustCompile(`(?i)create(\s)+(or(\s)+replace(\s)+)?(function|procedure)`) ) type Client struct { @@ -353,9 +355,10 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) client.lastQueryTime = time.Now().UTC() }() - // we just allow one statment per exectution + // we just allow one statment per exectution, except for procedure and function semicolonIndex := strings.Index(strings.TrimSpace(query), ";") - if semicolonIndex != -1 && semicolonIndex < len(query)-1 { + if semicolonIndex != -1 && semicolonIndex < len(query)-1 && + createFuncProc.FindAllStringSubmatch(query, -1) == nil { return nil, errors.New("only one statment allowed to execute per query") } -- Gitee