Restore implements Node interface.
(ctx *format.RestoreCtx)
| 196 | |
| 197 | // Restore implements Node interface. |
| 198 | func (ft *FieldType) Restore(ctx *format.RestoreCtx) error { |
| 199 | ctx.WriteKeyWord(TypeToStr(ft.Tp, ft.Charset)) |
| 200 | |
| 201 | switch ft.Tp { |
| 202 | case mysql.TypeEnum, mysql.TypeSet: |
| 203 | ctx.WritePlain("(") |
| 204 | for i, e := range ft.Elems { |
| 205 | if i != 0 { |
| 206 | ctx.WritePlain(",") |
| 207 | } |
| 208 | ctx.WriteString(e) |
| 209 | } |
| 210 | ctx.WritePlain(")") |
| 211 | case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDuration: |
| 212 | if ft.Flen > 0 && ft.Decimal > 0 { |
| 213 | ctx.WritePlainf("(%d)", ft.Decimal) |
| 214 | } |
| 215 | case mysql.TypeDouble, mysql.TypeFloat: |
| 216 | if ft.Flen > 0 && ft.Decimal > 0 { |
| 217 | ctx.WritePlainf("(%d,%d)", ft.Flen, ft.Decimal) |
| 218 | } |
| 219 | case mysql.TypeNewDecimal: |
| 220 | if ft.Flen > 0 && ft.Decimal > 0 { |
| 221 | ctx.WritePlainf("(%d,%d)", ft.Flen, ft.Decimal) |
| 222 | } |
| 223 | case mysql.TypeBit, mysql.TypeShort, mysql.TypeTiny, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeString, mysql.TypeVarString, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob, mysql.TypeYear: |
| 224 | if ft.Flen > 0 { |
| 225 | ctx.WritePlainf("(%d)", ft.Flen) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if mysql.HasUnsignedFlag(ft.Flag) { |
| 230 | ctx.WriteKeyWord(" UNSIGNED") |
| 231 | } |
| 232 | if mysql.HasZerofillFlag(ft.Flag) { |
| 233 | ctx.WriteKeyWord(" ZEROFILL") |
| 234 | } |
| 235 | if mysql.HasBinaryFlag(ft.Flag) && ft.Charset != mysql.CharsetBin { |
| 236 | ctx.WriteKeyWord(" BINARY") |
| 237 | } |
| 238 | |
| 239 | if IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp) { |
| 240 | if ft.Charset != "" && ft.Charset != mysql.CharsetBin { |
| 241 | ctx.WriteKeyWord(" CHARACTER SET " + ft.Charset) |
| 242 | } |
| 243 | if ft.Collate != "" && ft.Collate != mysql.CharsetBin { |
| 244 | ctx.WriteKeyWord(" COLLATE ") |
| 245 | ctx.WritePlain(ft.Collate) |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | // FormatAsCastType is used for write AST back to string. |
| 253 | func (ft *FieldType) FormatAsCastType(w io.Writer) { |
nothing calls this directly
no test coverage detected