Skip to content

Commit 4766b17

Browse files
authored
Fix int (#1853)
* fixed bug with literal YQL value for signed integer YDB types * * Fixed bug with wrong literal YQL representation for signed integer YDB types
1 parent 3e8e535 commit 4766b17

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed bug with wrong literal YQL representation for signed integer YDB types
2+
13
## v3.115.1
24
* Added `ydb.Param.Range()` range iterator
35

internal/value/value.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ func (v int8Value) castTo(dst any) error {
982982
}
983983

984984
func (v int8Value) Yql() string {
985-
return strconv.FormatUint(uint64(v), 10) + "t"
985+
return strconv.FormatInt(int64(v), 10) + "t"
986986
}
987987

988988
func (int8Value) Type() types.Type {
@@ -1046,7 +1046,7 @@ func (v int16Value) castTo(dst any) error {
10461046
}
10471047

10481048
func (v int16Value) Yql() string {
1049-
return strconv.FormatUint(uint64(v), 10) + "s"
1049+
return strconv.FormatInt(int64(v), 10) + "s"
10501050
}
10511051

10521052
func (int16Value) Type() types.Type {
@@ -1166,7 +1166,7 @@ func (v int64Value) castTo(dst any) error {
11661166
}
11671167

11681168
func (v int64Value) Yql() string {
1169-
return strconv.FormatUint(uint64(v), 10) + "l"
1169+
return strconv.FormatInt(int64(v), 10) + "l"
11701170
}
11711171

11721172
func (int64Value) Type() types.Type {
@@ -2230,11 +2230,11 @@ func (v uint8Value) castTo(dst any) error {
22302230

22312231
return nil
22322232
case *string:
2233-
*vv = strconv.FormatUint(uint64(v), 10)
2233+
*vv = strconv.FormatInt(int64(v), 10)
22342234

22352235
return nil
22362236
case *[]byte:
2237-
*vv = xstring.ToBytes(strconv.FormatUint(uint64(v), 10))
2237+
*vv = xstring.ToBytes(strconv.FormatInt(int64(v), 10))
22382238

22392239
return nil
22402240
case *uint64:

internal/value/value_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ func TestValueYql(t *testing.T) {
225225
value: Int8Value(42),
226226
literal: `42t`,
227227
},
228+
{
229+
value: Int8Value(-42),
230+
literal: `-42t`,
231+
},
228232
{
229233
value: Uint8Value(42),
230234
literal: `42ut`,
@@ -233,6 +237,10 @@ func TestValueYql(t *testing.T) {
233237
value: Int16Value(42),
234238
literal: `42s`,
235239
},
240+
{
241+
value: Int16Value(-42),
242+
literal: `-42s`,
243+
},
236244
{
237245
value: Uint16Value(42),
238246
literal: `42us`,
@@ -241,6 +249,10 @@ func TestValueYql(t *testing.T) {
241249
value: Int32Value(42),
242250
literal: `42`,
243251
},
252+
{
253+
value: Int32Value(-42),
254+
literal: `-42`,
255+
},
244256
{
245257
value: Uint32Value(42),
246258
literal: `42u`,
@@ -249,6 +261,10 @@ func TestValueYql(t *testing.T) {
249261
value: Int64Value(42),
250262
literal: `42l`,
251263
},
264+
{
265+
value: Int64Value(-42),
266+
literal: `-42l`,
267+
},
252268
{
253269
value: Uint64Value(42),
254270
literal: `42ul`,

0 commit comments

Comments
 (0)