From 46cbfb10ea32fbcecae65441d9692c59cafc5ebc Mon Sep 17 00:00:00 2001 From: siddontang Date: Mon, 9 Nov 2015 10:11:46 +0800 Subject: [PATCH] *: check state when creating table. --- infoschema/infoschema_test.go | 4 ++++ table/tables/tables.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/infoschema/infoschema_test.go b/infoschema/infoschema_test.go index f10910ead9..2957a49f06 100644 --- a/infoschema/infoschema_test.go +++ b/infoschema/infoschema_test.go @@ -52,6 +52,7 @@ func (*testSuite) TestT(c *C) { Name: colName, Offset: 0, FieldType: *types.NewFieldType(mysql.TypeLonglong), + State: model.StatePublic, } idxInfo := &model.IndexInfo{ @@ -66,6 +67,7 @@ func (*testSuite) TestT(c *C) { }, Unique: true, Primary: true, + State: model.StatePublic, } tblInfo := &model.TableInfo{ @@ -73,12 +75,14 @@ func (*testSuite) TestT(c *C) { Name: tbName, Columns: []*model.ColumnInfo{colInfo}, Indices: []*model.IndexInfo{idxInfo}, + State: model.StatePublic, } dbInfo := &model.DBInfo{ ID: 1, Name: dbName, Tables: []*model.TableInfo{tblInfo}, + State: model.StatePublic, } dbInfos := []*model.DBInfo{dbInfo} diff --git a/table/tables/tables.go b/table/tables/tables.go index 43982d039d..207baeffb7 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -55,14 +55,26 @@ type Table struct { // TableFromMeta creates a Table instance from model.TableInfo. func TableFromMeta(alloc autoid.Allocator, tblInfo *model.TableInfo) table.Table { + if tblInfo.State == model.StateNone { + log.Fatalf("table %s can't be in none state", tblInfo.Name) + } + t := NewTable(tblInfo.ID, tblInfo.Name.O, nil, alloc) for _, colInfo := range tblInfo.Columns { + if colInfo.State == model.StateNone { + log.Fatalf("column %s can't be in none state", colInfo.Name) + } + col := &column.Col{ColumnInfo: *colInfo} t.Columns = append(t.Columns, col) } for _, idxInfo := range tblInfo.Indices { + if idxInfo.State == model.StateNone { + log.Fatalf("index %s can't be in none state", idxInfo.Name) + } + idx := &column.IndexedCol{ IndexInfo: *idxInfo, X: kv.NewKVIndex(t.indexPrefix, idxInfo.Name.L, idxInfo.Unique),