Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upColumnType interfaces #667
Conversation
We should probably add sanity-checks for the index, as in #664 |
fieldTypeMediumBLOB: "MEDIUMBLOB", | ||
fieldTypeLongBLOB: "LONGBLOB", | ||
fieldTypeBLOB: "BLOB", | ||
fieldTypeVarString: "VARSTRING", // correct? |
arnehormann
Sep 18, 2017
•
Member
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.
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.
methane
Sep 19, 2017
Member
There are no document about it.
After seeing some response, I decided to handle charsetnr == 63 is bytes, not string.
There are no document about it.
After seeing some response, I decided to handle charsetnr == 63 is bytes, not string.
methane
Sep 19, 2017
Member
Of course, string can contain bytes.
Of course, string can contain bytes.
} | ||
|
||
func (rows *mysqlRows) ColumnTypeNullable(i int) (nullable, ok bool) { | ||
return rows.rs.columns[i].flags&flagNotNULL == 0, true |
arnehormann
Sep 18, 2017
Member
If we add the sanity checks here, it should also check for a negative index for ok
.
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 |
arnehormann
Sep 18, 2017
Member
I'm not convinced this helps taking all the casting happening in packets.go ...
I'm not convinced this helps taking all the casting happening in packets.go ...
Implementation for time.Time not yet complete!
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 |
This comment has been minimized.
This comment has been minimized.
Hello, thanks for the pr. It saved me so long time. |
This comment has been minimized.
This comment has been minimized.
It only removed unused code. |
@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. |
return scanTypeString | ||
} | ||
return scanTypeNullString | ||
return scanTypeRawBytes |
molon
Oct 17, 2017
Do I have to check nullable to decide converting to sql.NullString or string myself?
Do I have to check nullable to decide converting to sql.NullString or string myself?
julienschmidt
Oct 17, 2017
•
Author
Member
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()
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