Format returns a canonical string representation of the type and all relevant options
(buf *nodeBuffer)
| 970 | |
| 971 | // Format returns a canonical string representation of the type and all relevant options |
| 972 | func (ct *ColumnType) Format(buf *nodeBuffer) { |
| 973 | buf.Printf("%s", ct.Type) |
| 974 | |
| 975 | if ct.Length != nil && ct.Scale != nil { |
| 976 | buf.Printf("(%v,%v)", ct.Length, ct.Scale) |
| 977 | |
| 978 | } else if ct.Length != nil { |
| 979 | buf.Printf("(%v)", ct.Length) |
| 980 | } |
| 981 | |
| 982 | if ct.EnumValues != nil { |
| 983 | quotedValues := make([]string, len(ct.EnumValues)) |
| 984 | for i, v := range ct.EnumValues { |
| 985 | quotedValues[i] = "'" + v + "'" |
| 986 | } |
| 987 | buf.Printf("(%s)", strings.Join(quotedValues, ", ")) |
| 988 | } |
| 989 | |
| 990 | if ct.Unsigned { |
| 991 | buf.Printf(" %s", keywordStrings[UNSIGNED]) |
| 992 | } |
| 993 | if ct.Zerofill { |
| 994 | buf.Printf(" %s", keywordStrings[ZEROFILL]) |
| 995 | } |
| 996 | if ct.Charset != "" { |
| 997 | buf.Printf(" %s %s %s", keywordStrings[CHARACTER], keywordStrings[SET], ct.Charset) |
| 998 | } |
| 999 | if ct.Collate != "" { |
| 1000 | buf.Printf(" %s %s", keywordStrings[COLLATE], ct.Collate) |
| 1001 | } |
| 1002 | if ct.Timezone { |
| 1003 | buf.Printf(" %s %s %s", keywordStrings[WITH], keywordStrings[TIME], keywordStrings[ZONE]) |
| 1004 | } |
| 1005 | if ct.NotNull != nil && *ct.NotNull { |
| 1006 | buf.Printf(" %s %s", keywordStrings[NOT], keywordStrings[NULL]) |
| 1007 | } |
| 1008 | if ct.Default != nil { |
| 1009 | buf.Printf(" %s", keywordStrings[DEFAULT]) |
| 1010 | if _, ok := ct.Default.Expression.Expr.(*SQLVal); ok { |
| 1011 | buf.Printf(" %s", String(ct.Default.Expression.Expr)) |
| 1012 | } else { |
| 1013 | buf.Printf("(%v)", ct.Default.Expression.Expr) |
| 1014 | } |
| 1015 | } |
| 1016 | if ct.OnUpdate != nil { |
| 1017 | buf.Printf(" %s %s %s", keywordStrings[ON], keywordStrings[UPDATE], String(ct.OnUpdate)) |
| 1018 | } |
| 1019 | if ct.Autoincrement { |
| 1020 | buf.Printf(" %s", keywordStrings[AUTO_INCREMENT]) |
| 1021 | } |
| 1022 | if ct.Comment != nil { |
| 1023 | buf.Printf(" %s %s", keywordStrings[COMMENT_KEYWORD], String(ct.Comment)) |
| 1024 | } |
| 1025 | if ct.Check != nil { |
| 1026 | buf.Printf(" %s %s", keywordStrings[CHECK], String(&ct.Check.Where)) |
| 1027 | } |
| 1028 | if !ct.References.Name.IsEmpty() { |
| 1029 | buf.Printf(" references %v", ct.References) |
nothing calls this directly
no test coverage detected