Skip to content

Commit 506b8f8

Browse files
committed
fix of infinite recursive loop
1 parent 244f96f commit 506b8f8

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

internal/xsql/conn.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,12 @@ func (c *conn) PrepareContext(ctx context.Context, query string) (_ driver.Stmt,
135135
}, nil
136136
}
137137

138-
func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Result, err error) {
138+
func (c *conn) execContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Result, err error) {
139139
m := queryModeFromContext(ctx, c.defaultQueryMode)
140140
onDone := trace.DatabaseSQLOnConnExec(c.trace, &ctx, query, m.String(), retry.IsIdempotent(ctx))
141141
defer func() {
142142
onDone(err)
143143
}()
144-
if c.isClosed() {
145-
return nil, errClosedConn
146-
}
147-
if c.currentTx != nil {
148-
if m != DataQueryMode {
149-
return nil, xerrors.WithStackTrace(
150-
fmt.Errorf("query mode `%s` not supported with currentTx", m.String()),
151-
)
152-
}
153-
return c.currentTx.ExecContext(ctx, query, args)
154-
}
155144
switch m {
156145
case DataQueryMode:
157146
var res result.Result
@@ -185,23 +174,32 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
185174
}
186175
}
187176

177+
func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Result, err error) {
178+
if c.isClosed() {
179+
return nil, errClosedConn
180+
}
181+
if c.currentTx != nil {
182+
return c.currentTx.ExecContext(ctx, query, args)
183+
}
184+
return c.execContext(ctx, query, args)
185+
}
186+
188187
func (c *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Rows, err error) {
189-
m := queryModeFromContext(ctx, c.defaultQueryMode)
190-
onDone := trace.DatabaseSQLOnConnExec(c.trace, &ctx, query, m.String(), retry.IsIdempotent(ctx))
191-
defer func() {
192-
onDone(err)
193-
}()
194188
if c.isClosed() {
195189
return nil, errClosedConn
196190
}
197191
if c.currentTx != nil {
198-
if m != DataQueryMode {
199-
return nil, xerrors.WithStackTrace(
200-
fmt.Errorf("query mode `%s` not supported with currentTx", m.String()),
201-
)
202-
}
203192
return c.currentTx.QueryContext(ctx, query, args)
204193
}
194+
return c.queryContext(ctx, query, args)
195+
}
196+
197+
func (c *conn) queryContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Rows, err error) {
198+
m := queryModeFromContext(ctx, c.defaultQueryMode)
199+
onDone := trace.DatabaseSQLOnConnExec(c.trace, &ctx, query, m.String(), retry.IsIdempotent(ctx))
200+
defer func() {
201+
onDone(err)
202+
}()
205203
switch m {
206204
case DataQueryMode:
207205
var res result.Result

internal/xsql/fake_tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ func (tx *fakeTx) QueryContext(ctx context.Context, q string, args []driver.Name
5555
defer func() {
5656
onDone(err)
5757
}()
58-
return tx.conn.QueryContext(WithTxControl(ctx, tx.txControl), q, args)
58+
return tx.conn.queryContext(WithTxControl(ctx, tx.txControl), q, args)
5959
}
6060

6161
func (tx *fakeTx) ExecContext(ctx context.Context, q string, args []driver.NamedValue) (_ driver.Result, err error) {
6262
onDone := trace.DatabaseSQLOnTxExec(tx.conn.trace, &ctx, tx.ctx, tx, q, retry.IsIdempotent(ctx))
6363
defer func() {
6464
onDone(err)
6565
}()
66-
return tx.conn.ExecContext(WithTxControl(ctx, tx.txControl), q, args)
66+
return tx.conn.execContext(WithTxControl(ctx, tx.txControl), q, args)
6767
}

0 commit comments

Comments
 (0)