Skip to content

Commit 03bb10c

Browse files
authored
chore: avoid empty statement to execute (#39)
Co-authored-by: Rick <[email protected]>
1 parent bd42262 commit 03bb10c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

pkg/data_query.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result *
104104
func runMultilineSQL(ctx context.Context, multilineSQL string, db *gorm.DB) (result *server.DataQueryResult, err error) {
105105
lines := strings.Split(multilineSQL, ";")
106106
for _, line := range lines {
107+
if strings.TrimSpace(line) == "" {
108+
continue
109+
}
107110
if result, err = sqlQuery(ctx, line, db); err != nil {
108111
return
109112
}

pkg/data_query_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2025 API Testing Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package pkg
17+
18+
import (
19+
"context"
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestRunMultilineSQL(t *testing.T) {
26+
tests := []struct {
27+
name string
28+
sql string
29+
}{
30+
{
31+
name: "empty",
32+
sql: "",
33+
}, {
34+
name: "multiple blanks",
35+
sql: " ; ",
36+
},
37+
}
38+
for _, test := range tests {
39+
t.Run(test.name, func(t *testing.T) {
40+
result, err := runMultilineSQL(context.TODO(), test.sql, nil)
41+
assert.NoError(t, err)
42+
assert.Nil(t, result)
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)