Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed marshal optional parambuilder value to protobuf #1480

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Added write to topics within transactions
* Fixed marshal optional parameter of ydb.ParamBuilder to protobuf

## v3.80.10
* Added `ydb.WithSessionPoolSessionUsageLimit()` option for limitation max count of session usage
Expand Down
2 changes: 1 addition & 1 deletion internal/params/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (b *optionalBuilder) EndOptional() Builder {
b.opt.parent.params = append(b.opt.parent.params, &Parameter{
parent: b.opt.parent,
name: b.opt.name,
value: value.OptionalValue(b.opt.value),
value: b.opt.value,
})

return b.opt.parent
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/table_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package integration
import (
"context"
"fmt"
"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/query"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -113,3 +115,34 @@ func TestRegressionIssue1227RetryBadSession(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, 100, cnt)
}

func TestOptionalWithParamBuilder(t *testing.T) {
t.Run("Nil", func(t *testing.T) {
scope := newScope(t)
row, err := scope.Driver().Query().QueryRow(scope.Ctx, `
DECLARE $val AS Int64?;

SELECT $val
`, query.WithParameters(ydb.ParamsBuilder().Param("$val").BeginOptional().Int64(nil).EndOptional().Build()))
require.NoError(t, err)
var val *int64
err = row.Scan(&val)
require.NoError(t, err)
require.Nil(t, val)
})
t.Run("Val", func(t *testing.T) {
scope := newScope(t)
param := int64(123)
row, err := scope.Driver().Query().QueryRow(scope.Ctx, `
DECLARE $val AS Int64?;

SELECT $val
`, query.WithParameters(ydb.ParamsBuilder().Param("$val").BeginOptional().Int64(&param).EndOptional().Build()))
require.NoError(t, err)
var val *int64
err = row.Scan(&val)
require.NoError(t, err)
require.Equal(t, param, *val)
})

}
Loading