@@ -54,6 +54,8 @@ type conn struct {
5454
5555 dataOpts []options.ExecuteDataQueryOption
5656 scanOpts []options.ExecuteScanQueryOption
57+
58+ currentTx * tx
5759}
5860
5961var (
@@ -134,17 +136,22 @@ func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (driver.
134136 if err != nil {
135137 return nil , c .checkClosed (err )
136138 }
137- return & tx {
139+ c . currentTx = & tx {
138140 conn : c ,
139141 transaction : t ,
140- }, nil
142+ }
143+ return c .currentTx , nil
141144}
142145
143146func (c * conn ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Result , error ) {
144147 if c .isClosed () {
145148 return nil , errClosedConn
146149 }
147- switch m := queryModeFromContext (ctx , c .defaultQueryMode ); m {
150+ m := queryModeFromContext (ctx , c .defaultQueryMode )
151+ if c .currentTx != nil && m == DataQueryMode {
152+ return c .currentTx .ExecContext (ctx , query , args )
153+ }
154+ switch m {
148155 case DataQueryMode :
149156 _ , res , err := c .session .Execute (ctx , txControl (ctx , c .defaultTxControl ), query , toQueryParams (args ))
150157 if err != nil {
@@ -175,7 +182,11 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam
175182 if c .isClosed () {
176183 return nil , errClosedConn
177184 }
178- switch m := queryModeFromContext (ctx , c .defaultQueryMode ); m {
185+ m := queryModeFromContext (ctx , c .defaultQueryMode )
186+ if c .currentTx != nil && m == DataQueryMode {
187+ return c .currentTx .QueryContext (ctx , query , args )
188+ }
189+ switch m {
179190 case DataQueryMode :
180191 _ , res , err := c .session .Execute (ctx , txControl (ctx , c .defaultTxControl ), query , toQueryParams (args ))
181192 if err != nil {
0 commit comments