Skip to content

Commit

Permalink
Merge pull request #9020 from planetscale/fix-string-comparison
Browse files Browse the repository at this point in the history
Fix sqltypes comparison
  • Loading branch information
systay authored Oct 20, 2021
2 parents 60b84f1 + b69ca98 commit 787b3ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions go/test/endtoend/vtgate/mysql80/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ func TestCheckConstraint(t *testing.T) {
exec(t, conn, cleanup)
}

func TestValueDefault(t *testing.T) {
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()

exec(t, conn, `create table test_float_default (pos_f float default 2.1, neg_f float default -2.1,b blob default ('abc'));`)
defer exec(t, conn, `drop table test_float_default`)
assertMatches(t, conn, "select table_name, column_name, column_default from information_schema.columns where table_name = 'test_float_default' order by column_name", `[[VARBINARY("test_float_default") VARCHAR("b") BLOB("_utf8mb3\\'abc\\'")] [VARBINARY("test_float_default") VARCHAR("neg_f") BLOB("-2.1")] [VARBINARY("test_float_default") VARCHAR("pos_f") BLOB("2.1")]]`)
}

func TestVersionCommentWorks(t *testing.T) {
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
Expand Down
8 changes: 5 additions & 3 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,10 +1520,12 @@ func (es *ExtractedSubquery) updateAlternative() {
}

func defaultRequiresParens(ct *ColumnType) bool {
switch ct.Type {
case "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB", "JSON", "GEOMETRY", "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION":
switch strings.ToUpper(ct.Type) {
case "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "TINYBLOB", "BLOB", "MEDIUMBLOB",
"LONGBLOB", "JSON", "GEOMETRY", "POINT",
"LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
"MULTIPOLYGON", "GEOMETRYCOLLECTION":
return true

}

_, isLiteral := ct.Options.Default.(*Literal)
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ var (
input: "select 1",
output: "select 1 from dual",
}, {
input: "CREATE TABLE t2 (b BLOB DEFAULT 'abc')",
output: "create table t2 (\n\tb BLOB default ('abc')\n)",
input: "CREATE TABLE t2 (b blob DEFAULT 'abc')",
output: "create table t2 (\n\tb blob default ('abc')\n)",
}, {
input: "CREATE TABLE t2 (b BLOB DEFAULT ('abc'))",
output: "create table t2 (\n\tb BLOB default ('abc')\n)",
Expand Down

0 comments on commit 787b3ea

Please sign in to comment.