ydb-platform / ydb-go-sdk

Pure Go native and database/sql driver for YDB
https://ydb.tech
Apache License 2.0
133 stars 69 forks source link

bug: When using `Text` columns, ScanStruct does not work for pointer struct field & and the column is mandatory #1258

Open flymedllva opened 1 month ago

flymedllva commented 1 month ago

Bug Report

YDB GO SDK version:

v3.71.0

Description:

When using Text columns, ScanStruct does not work for pointer struct field](bug: When using Text columns, ScanStruct does not work for pointer struct field & and the column is mandatory)

CREATE TABLE `test`
(
    `id`         Text NOT NULL
);
type T struct {
    ID        *string   `sql:"id"`
}

Not work, error: cannot cast 'TEST' (type 'Utf8') to '**string' destination at github.com/ydb-platform/ydb-go-sdk/v3/internal/value.textValue.castTo(value.go:2046) at `github.com/ydb-platform/ydb-go-sdk/v3/internal/query/scanner.StructScanner.ScanStruct(struct.go:64)

row, err := s.ydbConn.Query().ReadResultSet(ctx, "select id from `test`;")
nextRow, err := row.NextRow(ctx)
var t T
err = nextRow.ScanStruct(&t, query.WithScanStructAllowMissingColumnsFromSelect(), query.WithScanStructAllowMissingFieldsInStruct())