Skip to content

Commit 1bcbc91

Browse files
authored
Merge pull request #1512 PublicRevertReorderForIssue1501
PublicRevertReorderForIssue1501
2 parents 5acfc74 + 29f6adb commit 1bcbc91

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tests/integration/database_sql_regression_test.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/google/uuid"
1516
"github.com/stretchr/testify/require"
1617
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1718

@@ -167,3 +168,130 @@ func TestRegressionKikimr17104(t *testing.T) {
167168
})
168169
})
169170
}
171+
172+
func TestUUIDSerializationDatabaseSQLIssue1501(t *testing.T) {
173+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
174+
// test with special uuid - all bytes are different for check any byte swaps
175+
176+
t.Run("old-send", func(t *testing.T) {
177+
// test old behavior - for test way of safe work with data, written with bagged API version
178+
var (
179+
scope = newScope(t)
180+
db = scope.SQLDriver()
181+
)
182+
183+
idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
184+
expectedResultWithBug := "2d9e498b-b746-9cfb-084d-de4e1cb4736e"
185+
id := [16]byte(uuid.MustParse(idString))
186+
row := db.QueryRow(`
187+
DECLARE $val AS UUID;
188+
189+
SELECT CAST($val AS Utf8)`, sql.Named("val", id),
190+
)
191+
192+
require.NoError(t, row.Err())
193+
194+
var res string
195+
196+
err := row.Scan(&res)
197+
require.NoError(t, err)
198+
require.Equal(t, expectedResultWithBug, res)
199+
})
200+
t.Run("old-receive-to-bytes", func(t *testing.T) {
201+
// test old behavior - for test way of safe work with data, written with bagged API version
202+
var (
203+
scope = newScope(t)
204+
db = scope.SQLDriver()
205+
)
206+
207+
idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
208+
expectedResultWithBug := "8b499e2d-46b7-fb9c-4d08-4ede6e73b41c"
209+
row := db.QueryRow(`
210+
DECLARE $val AS Text;
211+
212+
SELECT CAST($val AS UUID)`,
213+
sql.Named("val", idString),
214+
)
215+
216+
require.NoError(t, row.Err())
217+
218+
var res [16]byte
219+
220+
err := row.Scan(&res)
221+
require.NoError(t, err)
222+
223+
resUUID := uuid.UUID(res)
224+
require.Equal(t, expectedResultWithBug, resUUID.String())
225+
})
226+
t.Run("old-receive-to-string", func(t *testing.T) {
227+
// test old behavior - for test way of safe work with data, written with bagged API version
228+
var (
229+
scope = newScope(t)
230+
db = scope.SQLDriver()
231+
)
232+
233+
idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
234+
row := db.QueryRow(`
235+
DECLARE $val AS Text;
236+
237+
SELECT CAST($val AS UUID)`,
238+
sql.Named("val", idString),
239+
)
240+
241+
require.NoError(t, row.Err())
242+
243+
var res string
244+
245+
err := row.Scan(&res)
246+
require.Error(t, err)
247+
})
248+
t.Run("old-receive-to-uuid", func(t *testing.T) {
249+
// test old behavior - for test way of safe work with data, written with bagged API version
250+
var (
251+
scope = newScope(t)
252+
db = scope.SQLDriver()
253+
)
254+
255+
idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
256+
row := db.QueryRow(`
257+
DECLARE $val AS Text;
258+
259+
SELECT CAST($val AS UUID)`,
260+
sql.Named("val", idString),
261+
)
262+
263+
require.NoError(t, row.Err())
264+
265+
var res uuid.UUID
266+
267+
err := row.Scan(&res)
268+
require.Error(t, err)
269+
})
270+
t.Run("old-send-receive", func(t *testing.T) {
271+
// test old behavior - for test way of safe work with data, written with bagged API version
272+
var (
273+
scope = newScope(t)
274+
db = scope.SQLDriver()
275+
)
276+
277+
idString := "6E73B41C-4EDE-4D08-9CFB-B7462D9E498B"
278+
id := uuid.MustParse(idString)
279+
idParam := [16]byte(id)
280+
row := db.QueryRow(`
281+
DECLARE $val AS UUID;
282+
283+
SELECT $val`,
284+
sql.Named("val", idParam),
285+
)
286+
287+
require.NoError(t, row.Err())
288+
289+
var resBytes [16]byte
290+
err := row.Scan(&resBytes)
291+
require.NoError(t, err)
292+
293+
resUUID := uuid.UUID(resBytes)
294+
295+
require.Equal(t, id, resUUID)
296+
})
297+
}

0 commit comments

Comments
 (0)