Skip to content

Implement ColumnTypeDatabaseTypeName on Rows #223

@marcfargas

Description

@marcfargas

Summary

database/sql.ColumnType.DatabaseTypeName() always returns "" because the driver's Rows type does not implement the ColumnTypeDatabaseTypeName(index int) string interface.

This makes it impossible for callers to distinguish text columns (VARCHAR, WVARCHAR, etc.) from binary columns (BINARY, VARBINARY) when both arrive as []byte values.

Context

The ODBC SQL type is already available — BaseColumn.SQLType is populated by SQLDescribeCol during column setup in NewColumn(). It just needs to be exposed as a string via the database/sql optional interface.

Suggested implementation

Add to rows.go:

func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
    // requires exposing SQLType from the Column interface
}

The mapping from api.SQL_* constants to names is straightforward (SQL_VARCHAR → "VARCHAR", SQL_WCHAR → "WCHAR", etc.). The Column interface would need a method to expose BaseColumn.SQLType, or the implementation could type-assert through the concrete types.

Use case

I maintain a read-only REST API for Microsoft Access databases. The ACE ODBC driver returns text fields as []byte (via SQL_C_CHAR/SQL_C_WCHAR). Without DatabaseTypeName(), there's no way to distinguish text from binary/OLE columns — both arrive as []byte. Currently working around this with a UTF-8 validity heuristic, but the proper fix is driver-level type metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions