Skip to content

Add support for reading text BLOB to standard types in stdlib. - #56

Open
P1cheneG wants to merge 2 commits into
mainfrom
add_support_for_reading_text_blob_to_standard_types_stdlib
Open

P1cheneG wants to merge 2 commits into
mainfrom
add_support_for_reading_text_blob_to_standard_types_stdlib

Conversation

@P1cheneG

Copy link
Copy Markdown
Contributor

No description provided.

@P1cheneG
P1cheneG requested a review from MrTeeett November 23, 2026 13:08
@P1cheneG P1cheneG self-assigned this Nov 23, 2026
@P1cheneG P1cheneG added the enhancement New feature or request label Nov 23, 2026
@github-code-quality

github-code-quality Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Go

Go / code-coverage/gotest

main 3525ff6 add_support_for_read... 5db82ca +/-
79% 79% 0%
View coverage of the 5 most impacted files.
File main 3525ff6 add_support_for_read... 5db82ca +/-
fbservice/trace_session.go 100% 97% -3%
fbtype/array.go 83% 83% 0%
fbtype/dec16.go 74% 74% 0%
fbtype/timetz.go 76% 77% +1%
stdlib/sql_go1.27.go 80% 81% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 24, 2026 13:44 UTC

Comment thread stdlib/sql_go1.27.go Outdated
if err != nil {
return err
}
switch d := dest.(type) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With var p *string, row.Scan(&p) succeeds for SQL NULL but returns unsupported Scan for a TEXT BLOB containing "ok". This switch matches *string exactly, so **string falls through and ConvertAssign receives a stdlib.Blob. I reproduced the same failure with rows.Scan(&raw) for sql.RawBytes, with sql.Null[[]byte], and with a defined string type.

Comment thread stdlib/sql_go1.27.go Outdated

if fd.IsBlob() {
if src == nil {
if d, ok := dest.(*io.ReadCloser); ok {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scanning a non-NULL BLOB into var r io.Reader succeeds. Scanning the next NULL into the same &r returns unsupported Scan and leaves the previous BLOB in r. This branch only clears *io.ReadCloser.

Comment thread stdlib/sql_go1.27_test.go Outdated
require.NoError(t, err)
defer closeResource(t, &actual)
require.Equal(t, int32(1), actual.SubType)
require.Equal(t, "UTF8", actual.Charset)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Firebird 5.0.4 with encoding=ASCII, this assertion gets "ASCII" in both query execution modes. Firebird reports the result in the connection charset even though the CAST specifies UTF8.

Either open an explicitly UTF8 connection for this test or compare actual.Charset with the result metadata reported on the same connection.

Comment thread stdlib/sql_go1.27.go Outdated
*d = str
return nil
case *[]byte:
bin, err := blobValue.Bytes()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NextRow has already materialized these bytes in r.blobValues[index]. Calling Blob.Bytes() reads the entire buffer again through io.ReadAll. For an 8 MiB value, this path allocated 16.3 MiB across 34 allocations per scan.

The *[]byte case can run before buildBlobValue and return sql.ConvertAssign(scanCtx, dest, r.blobValues[index]). That measured 8.0 MiB across 2 allocations and still gives the caller an independent copy.

Comment thread stdlib/sql_go1.27.go Outdated
}
*d = bin
return nil
case *sql.NullString, *sql.Null[string]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The *string branch above and this branch both call blobValue.Text() and handle the same error. sql.ConvertAssign also handles *string, so all three destinations can share one case: case *string, *sql.NullString, *sql.Null[string]. Decode once and return sql.ConvertAssign(scanCtx, dest, str).

Comment thread stdlib/sql_go1.27_test.go Outdated
})
}

func TestScanBlobIntoNullString(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four nullable-string tests starting here each open a database for every query mode. They could share one testWithAllQueryExecModes call with a subtest for each nullable type. Scan 'blob' and then NULL into the same variable in each subtest. That covers both the successful conversion and the clearing of the previous value.

Comment thread stdlib/sql_go1.27.go Outdated
return err
}
switch d := dest.(type) {
case *string:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case also changes binary BLOB behavior. Scanning CAST(x'FF' AS BLOB SUB_TYPE BINARY) into a string now succeeds and returns a string containing the raw byte 0xff. The base commit returned a conversion error.

Is binary-to-string conversion intended? If so, cover it explicitly. If the change is scoped to TEXT BLOBs, guard the string destinations by BLOB subtype.

@smirnoffjr smirnoffjr added this to the v0.8.0 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants