MCPcopy Create free account
hub / github.com/bytebase/bytebase / checkDefault

Function checkDefault

backend/plugin/schema/tidb/walk_through.go:1130–1160  ·  view source on GitHub ↗
(columnName string, columnType *types.FieldType, value tidbast.ExprNode)

Source from the content-addressed store, hash-verified

1128}
1129
1130func checkDefault(columnName string, columnType *types.FieldType, value tidbast.ExprNode) *storepb.Advice {
1131 if value.GetType().GetType() != mysql.TypeNull {
1132 switch columnType.GetType() {
1133 case mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeJSON, mysql.TypeGeometry:
1134 content := fmt.Sprintf("BLOB, TEXT, GEOMETRY or JSON column `%s` can't have a default value", columnName)
1135 return &storepb.Advice{
1136 Status: storepb.Advice_ERROR,
1137 Code: code.InvalidColumnDefault.Int32(),
1138 Title: content,
1139 Content: content,
1140 StartPosition: &storepb.Position{Line: 0},
1141 }
1142 default:
1143 // Other column types allow default values
1144 }
1145 }
1146
1147 if valueExpr, yes := value.(tidbast.ValueExpr); yes {
1148 datum := types.NewDatum(valueExpr.GetValue())
1149 if _, err := datum.ConvertTo(types.Context{}, columnType); err != nil {
1150 return &storepb.Advice{
1151 Status: storepb.Advice_ERROR,
1152 Code: code.InvalidColumnDefault.Int32(),
1153 Title: err.Error(),
1154 Content: err.Error(),
1155 StartPosition: &storepb.Position{Line: 0},
1156 }
1157 }
1158 }
1159 return nil
1160}
1161
1162func tidbCreateColumnHelper(t *model.TableMetadata, column *tidbast.ColumnDef, position *tidbast.ColumnPosition) *storepb.Advice {
1163 if t.GetColumn(column.Name.Name.L) != nil {

Callers 1

tidbCreateColumnHelperFunction · 0.85

Calls 4

GetTypeMethod · 0.45
Int32Method · 0.45
GetValueMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected