Skip to content

Commit

Permalink
executor: fix format of bit default value on INFORMATION_SCHEMA.COLUM…
Browse files Browse the repository at this point in the history
…NS (#32701)

close #32655
  • Loading branch information
Defined2014 authored Mar 2, 2022
1 parent 42675fd commit 1268bf0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ ForColumnsTag:
var columnDefault interface{}
if columnDesc.DefaultValue != nil {
columnDefault = fmt.Sprintf("%v", columnDesc.DefaultValue)
if col.Tp == mysql.TypeBit {
defaultStr := fmt.Sprintf("%v", columnDesc.DefaultValue)
defaultValBinaryLiteral := types.BinaryLiteral(defaultStr)
columnDefault = defaultValBinaryLiteral.ToBitLiteralString(true)
}
}
record := types.MakeDatums(
infoschema.CatalogVal, // TABLE_CATALOG
Expand Down
12 changes: 12 additions & 0 deletions executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ func TestViews(t *testing.T) {
tk.MustQuery("SELECT table_catalog, table_schema, table_name, table_type, engine, version, row_format, table_rows, avg_row_length, data_length, max_data_length, index_length, data_free, auto_increment, update_time, check_time, table_collation, checksum, create_options, table_comment FROM information_schema.tables WHERE table_schema='test' AND table_name='v1'").Check(testkit.Rows("def test v1 VIEW <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> VIEW"))
}

func TestColumnsTables(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (bit bit(10) DEFAULT b'100')")
tk.MustQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 't'").Check(testkit.Rows(
"def test t bit 1 b'100' YES bit <nil> <nil> 10 0 <nil> <nil> <nil> bit(10) unsigned select,insert,update,references "))
tk.MustExec("drop table if exists t")
}

func TestEngines(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand Down

0 comments on commit 1268bf0

Please sign in to comment.