@@ -7,14 +7,15 @@ import (
77
88 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
99
10- "github.com/ydb-platform/ydb-go-sdk/v3/table/options "
10+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors "
1111)
1212
1313type stmt struct {
1414 nopResult
1515 namedValueChecker
1616
1717 conn * conn
18+ tx * tx
1819 params map [string ]* Ydb.Type
1920 query string
2021}
@@ -31,19 +32,22 @@ func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driv
3132 if s .conn .isClosed () {
3233 return nil , errClosedConn
3334 }
34- switch m := queryModeFromContext (ctx , s .conn .defaultQueryMode ); m {
35+ m := queryModeFromContext (ctx , s .conn .defaultQueryMode )
36+ if s .tx != nil {
37+ if m != DataQueryMode {
38+ return nil , xerrors .WithStackTrace (
39+ fmt .Errorf ("query mode `%s` not supported with prepared statement" , m .String ()),
40+ )
41+ }
42+ return s .tx .QueryContext (withKeepInCache (ctx ), s .query , args )
43+ }
44+ switch m {
3545 case DataQueryMode :
3646 _ , res , err := s .conn .session .Execute (ctx ,
3747 txControl (ctx , s .conn .defaultTxControl ),
3848 s .query ,
3949 toQueryParams (args ),
40- append (
41- append (
42- []options.ExecuteDataQueryOption {},
43- dataQueryOptions (ctx )... ,
44- ),
45- options .WithKeepInCache (true ),
46- )... ,
50+ dataQueryOptions (withKeepInCache (ctx ))... ,
4751 )
4852 if err != nil {
4953 return nil , s .conn .checkClosed (err )
@@ -63,19 +67,22 @@ func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive
6367 if s .conn .isClosed () {
6468 return nil , errClosedConn
6569 }
66- switch m := queryModeFromContext (ctx , s .conn .defaultQueryMode ); m {
70+ m := queryModeFromContext (ctx , s .conn .defaultQueryMode )
71+ if s .tx != nil {
72+ if m != DataQueryMode {
73+ return nil , xerrors .WithStackTrace (
74+ fmt .Errorf ("query mode `%s` not supported with prepared statement" , m .String ()),
75+ )
76+ }
77+ return s .tx .ExecContext (withKeepInCache (ctx ), s .query , args )
78+ }
79+ switch m {
6780 case DataQueryMode :
6881 _ , res , err := s .conn .session .Execute (ctx ,
6982 txControl (ctx , s .conn .defaultTxControl ),
7083 s .query ,
7184 toQueryParams (args ),
72- append (
73- append (
74- []options.ExecuteDataQueryOption {},
75- dataQueryOptions (ctx )... ,
76- ),
77- options .WithKeepInCache (true ),
78- )... ,
85+ dataQueryOptions (withKeepInCache (ctx ))... ,
7986 )
8087 if err != nil {
8188 return nil , s .conn .checkClosed (err )
0 commit comments