Skip to content

Commit c18d860

Browse files
committed
fix integration test cases
1 parent c713698 commit c18d860

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

pkg/listener/mysql.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,14 @@ func (l *MysqlListener) ExecuteCommand(ctx context.Context, c *mysql.Conn, data
548548
return nil
549549
}
550550

551-
if showStmt, ok := stmt.(*ast.ShowStmt); ok && showStmt.Tp == ast.ShowTables {
552-
showStmt.DBName = c.Database()
551+
if showStmt, ok := stmt.(*ast.ShowStmt); ok {
552+
switch showStmt.Tp {
553+
case ast.ShowTables, ast.ShowTableStatus, ast.ShowColumns, ast.ShowIndex, ast.ShowTriggers:
554+
if misc.IsBlank(showStmt.DBName) {
555+
showStmt.DBName = c.Database()
556+
}
557+
default:
558+
}
553559
}
554560

555561
if !misc.IsBlank(c.Database()) {

pkg/sql/db.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sql
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223
"time"
2324

2425
"github.com/pkg/errors"
@@ -31,6 +32,7 @@ import (
3132
"github.com/cectc/dbpack/pkg/misc"
3233
"github.com/cectc/dbpack/pkg/proto"
3334
"github.com/cectc/dbpack/pkg/tracing"
35+
"github.com/cectc/dbpack/third_party/parser/format"
3436
"github.com/cectc/dbpack/third_party/pools"
3537
)
3638

@@ -363,7 +365,11 @@ func (db *DB) QueryDirectly(query string) (proto.Result, uint16, error) {
363365
}
364366

365367
func (db *DB) ExecuteStmt(ctx context.Context, stmt *proto.Stmt) (proto.Result, uint16, error) {
366-
query := stmt.StmtNode.Text()
368+
var sb strings.Builder
369+
if err := stmt.StmtNode.Restore(format.NewRestoreCtx(constant.DBPackRestoreFormat, &sb)); err != nil {
370+
return nil, 0, err
371+
}
372+
query := sb.String()
367373
spanCtx, span := tracing.GetTraceSpan(ctx, tracing.DBExecStmt)
368374
span.SetAttributes(attribute.KeyValue{Key: "db", Value: attribute.StringValue(db.name)},
369375
attribute.KeyValue{Key: "sql", Value: attribute.StringValue(query)})

pkg/sql/tx.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sql
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/uber-go/atomic"
2425
"go.opentelemetry.io/otel/attribute"
@@ -29,6 +30,7 @@ import (
2930
"github.com/cectc/dbpack/pkg/proto"
3031
"github.com/cectc/dbpack/pkg/tracing"
3132
"github.com/cectc/dbpack/third_party/parser/ast"
33+
"github.com/cectc/dbpack/third_party/parser/format"
3234
)
3335

3436
type Tx struct {
@@ -69,7 +71,11 @@ func (tx *Tx) QueryDirectly(query string) (proto.Result, uint16, error) {
6971
}
7072

7173
func (tx *Tx) ExecuteStmt(ctx context.Context, stmt *proto.Stmt) (proto.Result, uint16, error) {
72-
query := stmt.StmtNode.Text()
74+
var sb strings.Builder
75+
if err := stmt.StmtNode.Restore(format.NewRestoreCtx(constant.DBPackRestoreFormat, &sb)); err != nil {
76+
return nil, 0, err
77+
}
78+
query := sb.String()
7379
spanCtx, span := tracing.GetTraceSpan(ctx, tracing.TxExecStmt)
7480
span.SetAttributes(attribute.KeyValue{Key: "db", Value: attribute.StringValue(tx.db.name)},
7581
attribute.KeyValue{Key: "sql", Value: attribute.StringValue(query)})

0 commit comments

Comments
 (0)