Skip to content

Commit

Permalink
fix: handle empty query correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Mar 18, 2023
1 parent dfc7401 commit 5c74314
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/executor/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
var (
errMissingTx = stdErrors.New("no transaction found")
errNoDatabaseSelected = mysqlErrors.NewSQLError(mConstants.ERNoDb, mConstants.SSNoDatabaseSelected, "No database selected")
errEmptyQuery = mysqlErrors.NewSQLError(mConstants.EREmptyQuery, mConstants.SS42000, "Query was empty")
)

var (
Expand Down Expand Up @@ -305,7 +306,12 @@ func (executor *RedirectExecutor) doExecutorComQuery(ctx *proto.Context, act ast
func (executor *RedirectExecutor) ExecutorComQuery(ctx *proto.Context, h func(result proto.Result, warns uint16, failure error) error) error {
p := parser.New()
query := ctx.GetQuery()
log.Debugf("ComQuery: %s", query)

if len(query) < 1 {
return h(nil, 0, errEmptyQuery)
}

log.Debugf("ComQuery: '%s'", query)

charset, collation := getCharsetCollation(ctx.C.CharacterSet())

Expand Down
2 changes: 1 addition & 1 deletion pkg/mysql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
import (
_ "github.com/arana-db/parser/test_driver"

uconfig "github.com/arana-db/arana/pkg/util/config"
perrors "github.com/pkg/errors"

"go.uber.org/atomic"
Expand All @@ -46,6 +45,7 @@ import (
"github.com/arana-db/arana/pkg/mysql/errors"
"github.com/arana-db/arana/pkg/proto"
"github.com/arana-db/arana/pkg/security"
uconfig "github.com/arana-db/arana/pkg/util/config"
"github.com/arana-db/arana/pkg/util/log"
)

Expand Down

0 comments on commit 5c74314

Please sign in to comment.