Skip to content

Commit a841e81

Browse files
authored
Fix ColumnType.DatabaseTypeName for mediumint unsigned (#1428)
1 parent 081308f commit a841e81

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

Diff for: AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Dave Protasowski <dprotaso at gmail.com>
3333
DisposaBoy <disposaboy at dby.me>
3434
Egor Smolyakov <egorsmkv at gmail.com>
3535
Erwan Martin <hello at erwan.io>
36+
Evan Elias <evan at skeema.net>
3637
Evan Shaw <evan at vendhq.com>
3738
Frederick Mayle <frederickmayle at gmail.com>
3839
Gustavo Kristic <gkristic at gmail.com>

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ user:password@/
465465
The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.
466466

467467
## `ColumnType` Support
468-
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `BIGINT`.
468+
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `MEDIUMINT`, `BIGINT`.
469469

470470
## `context.Context` Support
471471
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.

Diff for: driver_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,7 @@ func TestRowsColumnTypes(t *testing.T) {
28162816
{"tinyuint", "TINYINT UNSIGNED NOT NULL", "UNSIGNED TINYINT", scanTypeUint8, false, 0, 0, [3]string{"0", "255", "42"}, [3]interface{}{uint8(0), uint8(255), uint8(42)}},
28172817
{"smalluint", "SMALLINT UNSIGNED NOT NULL", "UNSIGNED SMALLINT", scanTypeUint16, false, 0, 0, [3]string{"0", "65535", "42"}, [3]interface{}{uint16(0), uint16(65535), uint16(42)}},
28182818
{"biguint", "BIGINT UNSIGNED NOT NULL", "UNSIGNED BIGINT", scanTypeUint64, false, 0, 0, [3]string{"0", "65535", "42"}, [3]interface{}{uint64(0), uint64(65535), uint64(42)}},
2819+
{"mediumuint", "MEDIUMINT UNSIGNED NOT NULL", "UNSIGNED MEDIUMINT", scanTypeUint32, false, 0, 0, [3]string{"0", "16777215", "42"}, [3]interface{}{uint32(0), uint32(16777215), uint32(42)}},
28192820
{"uint13", "INT(13) UNSIGNED NOT NULL", "UNSIGNED INT", scanTypeUint32, false, 0, 0, [3]string{"0", "1337", "42"}, [3]interface{}{uint32(0), uint32(1337), uint32(42)}},
28202821
{"float", "FLOAT NOT NULL", "FLOAT", scanTypeFloat32, false, math.MaxInt64, math.MaxInt64, [3]string{"0", "42", "13.37"}, [3]interface{}{float32(0), float32(42), float32(13.37)}},
28212822
{"floatnull", "FLOAT", "FLOAT", scanTypeNullFloat, true, math.MaxInt64, math.MaxInt64, [3]string{"0", "NULL", "13.37"}, [3]interface{}{nf0, nfNULL, nf1337}},

Diff for: fields.go

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func (mf *mysqlField) typeDatabaseName() string {
3737
case fieldTypeGeometry:
3838
return "GEOMETRY"
3939
case fieldTypeInt24:
40+
if mf.flags&flagUnsigned != 0 {
41+
return "UNSIGNED MEDIUMINT"
42+
}
4043
return "MEDIUMINT"
4144
case fieldTypeJSON:
4245
return "JSON"

0 commit comments

Comments
 (0)