diff --git a/pkg/data_query.go b/pkg/data_query.go index d24ea18..9d75f02 100644 --- a/pkg/data_query.go +++ b/pkg/data_query.go @@ -104,6 +104,9 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result * func runMultilineSQL(ctx context.Context, multilineSQL string, db *gorm.DB) (result *server.DataQueryResult, err error) { lines := strings.Split(multilineSQL, ";") for _, line := range lines { + if strings.TrimSpace(line) == "" { + continue + } if result, err = sqlQuery(ctx, line, db); err != nil { return } diff --git a/pkg/data_query_test.go b/pkg/data_query_test.go new file mode 100644 index 0000000..55b350b --- /dev/null +++ b/pkg/data_query_test.go @@ -0,0 +1,45 @@ +/* +Copyright 2025 API Testing Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package pkg + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRunMultilineSQL(t *testing.T) { + tests := []struct { + name string + sql string + }{ + { + name: "empty", + sql: "", + }, { + name: "multiple blanks", + sql: " ; ", + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + result, err := runMultilineSQL(context.TODO(), test.sql, nil) + assert.NoError(t, err) + assert.Nil(t, result) + }) + } +}