Skip to content

Commit dca11b0

Browse files
committed
* Fixed error Empty query text using prepared statements and ydb.WithExecuteDataQueryOverQueryClient(true) option
* Prepared statements always send query text on Execute call from now (previous behaviour - send query ID)
1 parent 6464f7d commit dca11b0

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed error `Empty query text` using prepared statements and `ydb.WithExecuteDataQueryOverQueryClient(true)` option
2+
* Prepared statements always send query text on Execute call from now (previous behaviour - send query ID)
13
* Prevented create decoder instance until start read a message from topics
24

35
## v3.99.4

internal/table/data_query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (q preparedQuery) YQL() string {
5454

5555
func (q preparedQuery) toYDB(a *allocator.Allocator) *Ydb_Table.Query {
5656
query := a.TableQuery()
57-
query.Query = a.TableQueryID(q.id)
57+
query.Query = a.TableQueryYqlText(q.sql)
5858

5959
return query
6060
}

tests/integration/table_regression_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/stretchr/testify/require"
1515
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1616

17+
"github.com/ydb-platform/ydb-go-sdk/v3"
1718
"github.com/ydb-platform/ydb-go-sdk/v3/internal/scanner"
1819
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1920
"github.com/ydb-platform/ydb-go-sdk/v3/table"
@@ -514,3 +515,61 @@ func (c *customTestUnmarshalUUIDTyped) UnmarshalYDB(raw scanner.RawValue) error
514515
func (c *customTestUnmarshalUUIDTyped) String() string {
515516
return string(*c)
516517
}
518+
519+
func TestRegressionIssue1636(t *testing.T) {
520+
for _, tt := range []struct {
521+
name string
522+
executeDataQueryOverQueryService bool
523+
}{
524+
{
525+
name: "ydb.WithExecuteDataQueryOverQueryClient(false)",
526+
executeDataQueryOverQueryService: false,
527+
},
528+
{
529+
name: "ydb.WithExecuteDataQueryOverQueryClient(true)",
530+
executeDataQueryOverQueryService: true,
531+
},
532+
} {
533+
t.Run(tt.name, func(t *testing.T) {
534+
var (
535+
scope = newScope(t)
536+
driver = scope.Driver(ydb.WithExecuteDataQueryOverQueryClient(tt.executeDataQueryOverQueryService))
537+
)
538+
err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
539+
stmt, err := s.Prepare(ctx, `
540+
DECLARE $val AS Uint64;
541+
SELECT $val;
542+
`)
543+
if err != nil {
544+
return fmt.Errorf("prepare failed: %w", err)
545+
}
546+
_, r, err := stmt.Execute(ctx, table.DefaultTxControl(),
547+
table.NewQueryParameters(table.ValueParam("$val", types.Uint64Value(123))),
548+
)
549+
if err != nil {
550+
return fmt.Errorf("prepared statement execute failed: %w", err)
551+
}
552+
553+
if !r.NextResultSet(ctx) {
554+
return fmt.Errorf("no result set: %w", r.Err())
555+
}
556+
557+
if !r.NextRow() {
558+
return fmt.Errorf("no row: %w", r.Err())
559+
}
560+
561+
var v uint64
562+
if err := r.Scan(&v); err != nil {
563+
return fmt.Errorf("scan failed: %w", err)
564+
}
565+
566+
if v != 123 {
567+
return fmt.Errorf("unexpected value: %d", v)
568+
}
569+
570+
return r.Err()
571+
})
572+
require.NoError(t, err)
573+
})
574+
}
575+
}

0 commit comments

Comments
 (0)