Skip to content

Commit c31542c

Browse files
committed
Fixing field metadata to report a binary collation for JSON and geometry types
1 parent 942e176 commit c31542c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

server/handler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ func schemaToFields(ctx *sql.Context, s sql.Schema) []*query.Field {
612612
charset = uint32(collatedType.Collation().CharacterSet())
613613
}
614614

615-
// If a result character set has been set for this session, make sure we use
616-
// it for any non-binary types
617-
if !types.IsBinaryType(c.Type) && charSetResults != sql.CharacterSet_Unspecified {
615+
// Binary types always use a binary collation, but non-binary types must
616+
// respect character_set_results if it is set.
617+
if types.IsBinaryType(c.Type) {
618+
charset = uint32(sql.Collation_binary)
619+
} else if charSetResults != sql.CharacterSet_Unspecified {
618620
charset = uint32(charSetResults)
619621
}
620622

server/handler_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,13 @@ func TestSchemaToFields(t *testing.T) {
671671
{Name: "text", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 262_140},
672672
{Name: "mediumtext", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 67_108_860},
673673
{Name: "longtext", Type: query.Type_TEXT, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
674-
{Name: "json", Type: query.Type_JSON, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
674+
{Name: "json", Type: query.Type_JSON, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295},
675675

676676
// Geometry Types
677-
{Name: "geometry", Type: query.Type_GEOMETRY, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
678-
{Name: "point", Type: query.Type_GEOMETRY, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
679-
{Name: "polygon", Type: query.Type_GEOMETRY, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
680-
{Name: "linestring", Type: query.Type_GEOMETRY, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 4_294_967_295},
677+
{Name: "geometry", Type: query.Type_GEOMETRY, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295},
678+
{Name: "point", Type: query.Type_GEOMETRY, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295},
679+
{Name: "polygon", Type: query.Type_GEOMETRY, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295},
680+
{Name: "linestring", Type: query.Type_GEOMETRY, Charset: mysql.CharacterSetBinary, ColumnLength: 4_294_967_295},
681681

682682
// Integer Types
683683
{Name: "uint8", Type: query.Type_UINT8, Charset: uint32(sql.CharacterSet_utf8mb4), ColumnLength: 3},

sql/types/typecheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func IsBinaryType(t sql.Type) bool {
3636
return false
3737
}
3838
switch t.Type() {
39-
case sqltypes.Binary, sqltypes.VarBinary, sqltypes.Blob:
39+
case sqltypes.Binary, sqltypes.VarBinary, sqltypes.Blob, sqltypes.TypeJSON, sqltypes.Geometry:
4040
return true
4141
default:
4242
return false

0 commit comments

Comments
 (0)