@@ -15,6 +15,7 @@ import (
1515 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1616 internalTable "github.com/ydb-platform/ydb-go-sdk/v3/internal/table"
1717 "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
18+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1819 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1920 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xslices"
2021 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn"
3738
3839 cc conn.Conn
3940 currentTx * txWrapper
41+ ctx context.Context //nolint:containedctx
4042
4143 connector * Connector
4244 lastUsage xsync.LastUsage
@@ -60,10 +62,13 @@ func (c *connWrapper) CheckNamedValue(value *driver.NamedValue) error {
6062 return nil
6163}
6264
63- func (c * connWrapper ) BeginTx (ctx context.Context , opts driver.TxOptions ) (driver.Tx , error ) {
64- if c .currentTx != nil {
65- return nil , xerrors .WithStackTrace (xerrors .AlreadyHasTx (c .currentTx .ID ()))
66- }
65+ func BeginTx (ctx context.Context , c * connWrapper , opts driver.TxOptions ) (_ driver.Tx , finalErr error ) {
66+ onDone := trace .DatabaseSQLOnConnBegin (c .connector .trace , & ctx ,
67+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.BeginTx" ),
68+ )
69+ defer func () {
70+ onDone (c .currentTx , finalErr )
71+ }()
6772
6873 tx , err := c .cc .BeginTx (ctx , opts )
6974 if err != nil {
@@ -79,7 +84,22 @@ func (c *connWrapper) BeginTx(ctx context.Context, opts driver.TxOptions) (drive
7984 return c .currentTx , nil
8085}
8186
82- func (c * connWrapper ) Close () error {
87+ func (c * connWrapper ) BeginTx (ctx context.Context , opts driver.TxOptions ) (driver.Tx , error ) {
88+ if c .currentTx != nil {
89+ return nil , xerrors .WithStackTrace (xerrors .AlreadyHasTx (c .currentTx .ID ()))
90+ }
91+
92+ return BeginTx (ctx , c , opts )
93+ }
94+
95+ func Close (c * connWrapper ) (finalErr error ) {
96+ onDone := trace .DatabaseSQLOnConnClose (c .connector .Trace (), & c .ctx ,
97+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.Close" ),
98+ )
99+ defer func () {
100+ onDone (finalErr )
101+ }()
102+
83103 err := c .cc .Close ()
84104 if err != nil {
85105 return xerrors .WithStackTrace (err )
@@ -88,6 +108,10 @@ func (c *connWrapper) Close() error {
88108 return nil
89109}
90110
111+ func (c * connWrapper ) Close () (finalErr error ) {
112+ return Close (c )
113+ }
114+
91115func (c * connWrapper ) Connector () * Connector {
92116 return c .connector
93117}
@@ -139,9 +163,9 @@ func (c *connWrapper) Prepare(string) (driver.Stmt, error) {
139163 return nil , errDeprecated
140164}
141165
142- func ( c * connWrapper ) PrepareContext (ctx context.Context , sql string ) (_ driver.Stmt , finalErr error ) {
166+ func PrepareContext (ctx context.Context , c * connWrapper , sql string ) (_ driver.Stmt , finalErr error ) {
143167 onDone := trace .DatabaseSQLOnConnPrepare (c .connector .Trace (), & ctx ,
144- stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.(*connWrapper). PrepareContext" ),
168+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.PrepareContext" ),
145169 sql ,
146170 )
147171 defer func () {
@@ -160,6 +184,10 @@ func (c *connWrapper) PrepareContext(ctx context.Context, sql string) (_ driver.
160184 }, nil
161185}
162186
187+ func (c * connWrapper ) PrepareContext (ctx context.Context , sql string ) (_ driver.Stmt , finalErr error ) {
188+ return PrepareContext (ctx , c , sql )
189+ }
190+
163191func (c * connWrapper ) LastUsage () time.Time {
164192 return c .lastUsage .Get ()
165193}
@@ -178,7 +206,17 @@ func (c *connWrapper) toYdb(sql string, args ...driver.NamedValue) (yql string,
178206 return yql , & params , nil
179207}
180208
181- func (c * connWrapper ) QueryContext (ctx context.Context , sql string , args []driver.NamedValue ) (driver.Rows , error ) {
209+ func QueryContext (ctx context.Context , c * connWrapper , sql string , args []driver.NamedValue ) (
210+ _ driver.Rows , finalErr error ,
211+ ) {
212+ onDone := trace .DatabaseSQLOnConnQuery (c .connector .Trace (), & ctx ,
213+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.QueryContext" ),
214+ sql , c .connector .processor .String (), xcontext .IsIdempotent (ctx ), c .connector .clock .Since (c .lastUsage .Get ()),
215+ )
216+ defer func () {
217+ onDone (finalErr )
218+ }()
219+
182220 done := c .lastUsage .Start ()
183221 defer done ()
184222
@@ -203,7 +241,21 @@ func (c *connWrapper) QueryContext(ctx context.Context, sql string, args []drive
203241 return c .cc .Query (ctx , sql , params )
204242}
205243
206- func (c * connWrapper ) ExecContext (ctx context.Context , sql string , args []driver.NamedValue ) (driver.Result , error ) {
244+ func (c * connWrapper ) QueryContext (ctx context.Context , sql string , args []driver.NamedValue ) (driver.Rows , error ) {
245+ return QueryContext (ctx , c , sql , args )
246+ }
247+
248+ func ExecContext (ctx context.Context , c * connWrapper , sql string , args []driver.NamedValue ) (
249+ _ driver.Result , finalErr error ,
250+ ) {
251+ onDone := trace .DatabaseSQLOnConnExec (c .connector .Trace (), & ctx ,
252+ stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.ExecContext" ),
253+ sql , c .connector .processor .String (), xcontext .IsIdempotent (ctx ), c .connector .clock .Since (c .lastUsage .Get ()),
254+ )
255+ defer func () {
256+ onDone (finalErr )
257+ }()
258+
207259 done := c .lastUsage .Start ()
208260 defer done ()
209261
@@ -219,6 +271,10 @@ func (c *connWrapper) ExecContext(ctx context.Context, sql string, args []driver
219271 return c .cc .Exec (ctx , sql , params )
220272}
221273
274+ func (c * connWrapper ) ExecContext (ctx context.Context , sql string , args []driver.NamedValue ) (driver.Result , error ) {
275+ return ExecContext (ctx , c , sql , args )
276+ }
277+
222278func (c * connWrapper ) GetDatabaseName () string {
223279 return c .connector .Name ()
224280}
0 commit comments