nakagami / firebirdsql

Firebird RDBMS sql driver for Go (golang)
MIT License
227 stars 60 forks source link

Error when selecting "RDB$CONSTRAINT_TYPE" from the "RDB$RELATION_CONSTRAINTS" system table #172

Closed ninoDeme closed 4 months ago

ninoDeme commented 4 months ago

while trying to retrieve the field "RDB$CONSTRAINT_TYPE" from the "RDB$RELATION_CONSTRAINTS" table the library panics with the following message:

panic: interface conversion: interface {} is string, not []uint8
goroutine 1 [running]:
github.com/nakagami/firebirdsql.(*xSQLVAR).value(0xc00002fc78?, {0xc000104020, 0xc00002fc98?, 0x0?}, {0x0?, 0xc000180020?}, {0x57
509f?, 0x0?})
        /home/ricardo/go/pkg/mod/github.com/nakagami/firebirdsql@v0.9.9-0.20240518062043-f13292bc481a/xsqlvar.go:438 +0xc05
github.com/nakagami/firebirdsql.(*wireProtocol).opFetchResponse(0xc0000b6240, 0x74e760?, 0x0?, {0xc0000fc070, 0x1, 0x10?})
        /home/ricardo/go/pkg/mod/github.com/nakagami/firebirdsql@v0.9.9-0.20240518062043-f13292bc481a/wireprotocol.go:1129 +0x713
github.com/nakagami/firebirdsql.(*firebirdsqlRows).Next(0xc000082100, {0xc0000162d0, 0x1, 0x7c88f3d1d1a8?})
        /home/ricardo/go/pkg/mod/github.com/nakagami/firebirdsql@v0.9.9-0.20240518062043-f13292bc481a/rows.go:102 +0x125
database/sql.(*Rows).nextLocked(0xc0000b8120)
        /usr/lib/go-1.22/src/database/sql/sql.go:3047 +0x107
database/sql.(*Rows).Next.func1()
        /usr/lib/go-1.22/src/database/sql/sql.go:3022 +0x29
database/sql.withLock({0x5c0410, 0xc0000b8158}, 0xc00002fe18)
        /usr/lib/go-1.22/src/database/sql/sql.go:3530 +0x82
database/sql.(*Rows).Next(0xc0000b8120)
        /usr/lib/go-1.22/src/database/sql/sql.go:3021 +0x85
database/sql.(*Row).Scan(0xc0000120f0, {0xc00002ff20?, 0x5819e8?, 0x1})
        /usr/lib/go-1.22/src/database/sql/sql.go:3467 +0x10a
main.main()

The error seems very similar to the issue #170, and i tried the branch issue170 from #171 which is supposed to fix it but it didn't seem to fix this issue

Test code to replicate the error:

func TestGoConstraintType(t *testing.T) {
    testDsn := GetTestDSN("test_constraint_type_")
    conn, err := sql.Open("firebirdsql_createdb", testDsn)
    require.NoError(t, err)

    rows, err := conn.Query("select RDB$CONSTRAINT_TYPE from RDB$RELATION_CONSTRAINTS")
    require.NoError(t, err)

    var text string
    require.True(t, rows.Next())
    require.NoError(t, rows.Scan(&text))
    require.NoError(t, rows.Close())
}
nakagami commented 4 months ago

Thank you.

This was related to issue #170. I have merged pull request #171 with the fixes related to this issue into master.