Describe the bug
A clear and concise description of what the bug is.
Any struct with non-public fields that cannot be encoded will cause an error when the value is converted. This makes the TVP incompatible with protobuf.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message: failed to convert tvp parameter row 0 col {{} [] [] 0}: unsupported type impl.MessageState, a struct
To Reproduce
Include a complete code listing that we can run to reproduce the issue.
type TestItem struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Key int
Value string
}
func main() {
items := make([]TestValue, {
{Key: 0, Value: "a"},
{Key: 1, Value: "b")
}
tvp := mssql.TVP{
TypeName: "ItemsTableType",
Value: items,
}
// Connect to a database and create a transaction
err := tx.ExecContext(context.Background(), "EXEC dbo.usp_InsertItems @TVP", sql.Names("TVP", tvp))
if err != nil {
panic(err)
}
}
Expected behavior
I expect no error to occur.
Further technical details
Operating system: Windows 10
Table schema: Not necessary
Additional context
This appears to be occurring because the encode function is missing a check for whether or not the field is exported. This can be done by checking whether or not field.PkgPath is empty.
Describe the bug A clear and concise description of what the bug is. Any struct with non-public fields that cannot be encoded will cause an error when the value is converted. This makes the TVP incompatible with protobuf.
If you are seeing an exception, include the full exceptions details (message and stack trace).
To Reproduce Include a complete code listing that we can run to reproduce the issue.
}
Expected behavior I expect no error to occur.
Further technical details
Operating system: Windows 10 Table schema: Not necessary
Additional context This appears to be occurring because the
encode
function is missing a check for whether or not the field is exported. This can be done by checking whether or notfield.PkgPath
is empty.