Skip to content

ColumnType.Length() Support #1132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hundredwatt opened this issue Jun 20, 2020 · 4 comments
Closed

ColumnType.Length() Support #1132

hundredwatt opened this issue Jun 20, 2020 · 4 comments
Labels

Comments

@hundredwatt
Copy link

hundredwatt commented Jun 20, 2020

The README states "This driver supports the ColumnType interface introduced in Go 1.8, with the exception of ColumnType.Length(), which is currently not supported."

I found the ColumnTypeLength function commented out here:

mysql/rows.go

Lines 66 to 68 in 578c4c8

// func (rows *mysqlRows) ColumnTypeLength(i int) (length int64, ok bool) {
// return int64(rows.rs.columns[i].length), true
// }

Based on the discussion in #667, it appears there were no limiting factors preventing this from being implemented: #667 (comment).

@julienschmidt can you confirm? Is this something that no one has gotten to yet? Or did you find some sort of limitation trying to implement this?

@julienschmidt
Copy link
Member

As written in the discussion at #667, the length MySQL reports is not the same as a string in Go with the same content would have. It seems to be the internal space requirement for storing it within MySQL, which is rather useless IMO.
If you think you can implement in a way, which produces reliable and useful lengths: go for it!

@methane methane added the wontfix label May 2, 2023
@methane methane closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2023
@kirs
Copy link

kirs commented Mar 14, 2025

In my use case with this driver, I'm looking at columns that are received with resultset, and when the column/field is TINYINT(1) I want to treat it in a certain way that's different from when the field is TINYINT(2) or TINYINT(3).

Unless the client exposes ColumnType.Length(), there's no way for me to look that up.

I get that Length() can be misleading value for string types, but I'm wondering if we could make it work so that at least the length of other types could be looked up.

@kirs
Copy link

kirs commented Mar 14, 2025

Could we expose a RawLength() where the func name would signal that it's not part of the Length() interface?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants