Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #673 from erizocosmico/fix/charset-for-blobs
Browse files Browse the repository at this point in the history
server: correctly set binary charset on blob fields
  • Loading branch information
ajnavarro authored Apr 12, 2019
2 parents 486b78c + 00f8870 commit 217cb4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 2 additions & 4 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,9 @@ func rowToSQL(s sql.Schema, row sql.Row) []sqltypes.Value {
func schemaToFields(s sql.Schema) []*query.Field {
fields := make([]*query.Field, len(s))
for i, c := range s {
var charset uint32
if c.Type.Type() == mysql.TypeBlob {
var charset uint32 = mysql.CharacterSetUtf8
if c.Type == sql.Blob {
charset = mysql.CharacterSetBinary
} else {
charset = mysql.CharacterSetUtf8
}

fields[i] = &query.Field{
Expand Down
20 changes: 20 additions & 0 deletions server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-vitess.v1/mysql"
"gopkg.in/src-d/go-vitess.v1/sqltypes"
"gopkg.in/src-d/go-vitess.v1/vt/proto/query"

opentracing "github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -223,3 +224,22 @@ func assertNoConnProcesses(t *testing.T, e *sqle.Engine, conn uint32) {
}
}
}

func TestSchemaToFields(t *testing.T) {
require := require.New(t)

schema := sql.Schema{
{Name: "foo", Type: sql.Blob},
{Name: "bar", Type: sql.Text},
{Name: "baz", Type: sql.Int64},
}

expected := []*query.Field{
{Name: "foo", Type: query.Type_BLOB, Charset: mysql.CharacterSetBinary},
{Name: "bar", Type: query.Type_TEXT, Charset: mysql.CharacterSetUtf8},
{Name: "baz", Type: query.Type_INT64, Charset: mysql.CharacterSetUtf8},
}

fields := schemaToFields(schema)
require.Equal(expected, fields)
}

0 comments on commit 217cb4d

Please sign in to comment.