microsoft / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
283 stars 63 forks source link

rows.ColumnTypes().DatabaseTypeName() returning empty string for common SQL server types #215

Closed rob2244 closed 1 month ago

rob2244 commented 1 month ago

Describe the bug When any sort of query and then trying to introspect the database types on the result set via ColumnTypes()[i].DatabaseTypeName the type name is always an empty string. Additionally there is not error returned from ColumnTypes() which would indicate any errors from parsing type names.

To Reproduce

  1. Using an azure sql instance with adventureworks dw installed, and using version 1.7.2 of the driver run the follwing:
rows, err := db.QueryContext(ctx, "SELECT * FROM FactInternetSales")

cols, err := rows.ColumnTypes()
if err != nil {
  panic(err)
}

for i := range types {
     fmt.Println("%s", types[i].DatabaseTypeName())
}

Expected behavior I expected the correct database type names to be returned and not empty strings

Further technical details

SQL Server version: (e.g. SQL Server 2017): Azure SQL With Server encryption turned on and a server level encryption key

Table schema: Adventure works Fact Internet Sales Table

shueybubbles commented 1 month ago

thx for opening an issue. We have a test for DatabaseTypeName() that passes, here: https://github.com/microsoft/go-mssqldb/blob/9b84d9bacd9bfaca0d33c4a855ad52b1b8b6cb35/queries_test.go#L1641 Does this happen with other databases/servers or just this one?

rob2244 commented 1 month ago

@shueybubbles thanks for the quick response! afaik, only this db/server. I haven't tested any others. Happy to provide any other information that might help in debugging.

I got the adventureworksdw2022 files from here and imported them into the azure sql instance:

https://learn.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver16&tabs=data-studio The .bak approach was a little cumbersome so I just downloaded and ran the scripts near the bottom of the page

rob2244 commented 1 month ago

@shueybubbles figured out the issue: I'm wrapping the sql driver in the otsql driver to add otel support. Looks like otsql is not correctly passing through the data types:

image

Apologies for the false alarm