-
Notifications
You must be signed in to change notification settings - Fork 2.3k
ColumnType interfaces #667
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
Conversation
We should probably add sanity-checks for the index, as in #664 |
fields.go
Outdated
fieldTypeMediumBLOB: "MEDIUMBLOB", | ||
fieldTypeLongBLOB: "LONGBLOB", | ||
fieldTypeBLOB: "BLOB", | ||
fieldTypeVarString: "VARSTRING", // correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see these in MySQL anywhere. The docs, e.g. https://dev.mysql.com/doc/refman/5.7/en/string-types.html don't mention them either. I don't think they are correct, should probably be varchar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no document about it.
After seeing some response, I decided to handle charsetnr == 63 is bytes, not string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, string can contain bytes.
rows.go
Outdated
} | ||
|
||
func (rows *mysqlRows) ColumnTypeNullable(i int) (nullable, ok bool) { | ||
return rows.rs.columns[i].flags&flagNotNULL == 0, true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add the sanity checks here, it should also check for a negative index for ok
.
@@ -87,8 +87,10 @@ const ( | |||
) | |||
|
|||
// https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType | |||
type fieldType byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this helps taking all the casting happening in packets.go ...
01e7b59
to
925d497
Compare
Implementation for time.Time not yet complete!
925d497
to
163ddcd
Compare
Removed the ColumnTypeLength implementation for now and added a section to the README |
I think it's the storage length for strings. Number of bytes for the
default utf8 "dialect" with 3 bytes per character. utf8_mb4 probably has a
value 4 times as long. Calling it utf8 at all is not quite accurate.
If you know the encoding, you know the correction factor.
|
That's what I assumed. There is also a We can work on this later, but for now I'd like to get this PR merged without the length before it gets too big. |
Completely agree. |
Code looks OK. But maybe, it can be implemented later. |
How would you distinguish BLOB and TEXT? And regarding usage: Wherever not all required information about the db schema is known at compile-time. Think for example of ORMs or applications like phpMyAdmin (goMyAdmin?). |
|
I mean, how would we treat it differently? |
DatabaseType() returns |
@methane I'd suggest we implement that in another PR. The MySQL server also seems to treat them the same internally. |
I agree with you. LGTM for now. |
fields.go
Outdated
return scanTypeString | ||
} | ||
return scanTypeNullString | ||
return scanTypeRawBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I have to check nullable to decide converting to sql.NullString or string myself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql.RawBytes
can also be nil
, which is distinguishable from an empty string (""
). I.e. if rawBytes == nil
then it was a NULL value.
If you want to known if the column itself may contain NULL values, then you should check ColumnType.Nullable()
* rows: implement driver.RowsColumnTypeScanType Implementation for time.Time not yet complete! * rows: implement driver.RowsColumnTypeNullable * rows: move fields related code to fields.go * fields: use NullTime for nullable datetime fields * fields: make fieldType its own type * rows: implement driver.RowsColumnTypeDatabaseTypeName * fields: fix copyright year * rows: compile time interface implementation checks * rows: move tests to versioned driver test files * rows: cache parseTime in resultSet instead of mysqlConn * fields: fix string and time types * rows: implement ColumnTypeLength * rows: implement ColumnTypePrecisionScale * rows: fix ColumnTypeNullable * rows: ColumnTypes tests part1 * rows: use keyed composite literals in ColumnTypes tests * rows: ColumnTypes tests part2 * rows: always use NullTime as ScanType for datetime * rows: avoid errors through rounding of time values * rows: remove parseTime cache * fields: remove unused scanTypes * rows: fix ColumnTypePrecisionScale implementation * fields: sort types alphabetical * rows: remove ColumnTypeLength implementation for now * README: document ColumnType Support
Latest release for mysql driver, 1.3, does not support ColumnType.DatabaseTypeName. See go-sql-driver/mysql#667 Signed-off-by: Carlos Martín <[email protected]>
Latest release for mysql driver, 1.3, does not support ColumnType.DatabaseTypeName. See go-sql-driver/mysql#667 Signed-off-by: Carlos Martín <[email protected]>
Latest release for mysql driver, 1.3, does not support ColumnType.DatabaseTypeName. See go-sql-driver/mysql#667 Signed-off-by: Carlos Martín <[email protected]>
Latest release for mysql driver, 1.3, does not support ColumnType.DatabaseTypeName. See go-sql-driver/mysql#667 Signed-off-by: Carlos Martín <[email protected]>
Latest release for mysql driver, 1.3, does not support ColumnType.DatabaseTypeName. See go-sql-driver/mysql#667 Signed-off-by: Carlos Martín <[email protected]>
Description
Fixes #495
Checklist