本文整理汇总了Golang中github.com/pingcap/tidb/util/types.FieldTypeToStr函数的典型用法代码示例。如果您正苦于以下问题:Golang FieldTypeToStr函数的具体用法?Golang FieldTypeToStr怎么用?Golang FieldTypeToStr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FieldTypeToStr函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getTypeStr
func (c *Col) getTypeStr() string {
ans := []string{types.FieldTypeToStr(c.Tp, c.Charset)}
if c.Flen != -1 {
if c.Decimal == -1 {
ans = append(ans, fmt.Sprintf("(%d)", c.Flen))
} else {
ans = append(ans, fmt.Sprintf("(%d, %d)", c.Flen, c.Decimal))
}
}
if mysql.HasUnsignedFlag(c.Flag) {
ans = append(ans, "UNSIGNED")
}
if mysql.HasZerofillFlag(c.Flag) {
ans = append(ans, "ZEROFILL")
}
if mysql.HasBinaryFlag(c.Flag) {
ans = append(ans, "BINARY")
}
if c.Charset != "" && c.Charset != charset.CharsetBin {
ans = append(ans, fmt.Sprintf("CHARACTER SET %s", c.Charset))
}
if c.Collate != "" {
ans = append(ans, fmt.Sprintf("COLLATE %s", c.Collate))
}
return strings.Join(ans, " ")
}
示例2: GetTypeDesc
// GetTypeDesc gets the description for column type.
func (c *Col) GetTypeDesc() string {
var buf bytes.Buffer
buf.WriteString(types.FieldTypeToStr(c.Tp, c.Charset))
switch c.Tp {
case mysql.TypeSet, mysql.TypeEnum:
// Format is ENUM ('e1', 'e2') or SET ('e1', 'e2')
// If elem contain ', we will convert ' -> ''
elems := make([]string, len(c.Elems))
for i := range elems {
elems[i] = strings.Replace(c.Elems[i], "'", "''", -1)
}
buf.WriteString(fmt.Sprintf("('%s')", strings.Join(elems, "','")))
default:
if c.Flen != -1 {
if c.Decimal == -1 {
buf.WriteString(fmt.Sprintf("(%d)", c.Flen))
} else {
buf.WriteString(fmt.Sprintf("(%d,%d)", c.Flen, c.Decimal))
}
}
}
if mysql.HasUnsignedFlag(c.Flag) {
buf.WriteString(" UNSIGNED")
}
return buf.String()
}
示例3: String
// String implements fmt.Stringer interface.
func (c *Col) String() string {
ans := []string{c.Name.O, types.FieldTypeToStr(c.Tp, c.Charset)}
if mysql.HasAutoIncrementFlag(c.Flag) {
ans = append(ans, "AUTO_INCREMENT")
}
if mysql.HasNotNullFlag(c.Flag) {
ans = append(ans, "NOT NULL")
}
return strings.Join(ans, " ")
}
示例4: getTypeDesc
func (c *Col) getTypeDesc() string {
ans := []string{types.FieldTypeToStr(c.Tp, c.Charset)}
if c.Flen != -1 {
if c.Decimal == -1 {
ans = append(ans, fmt.Sprintf("(%d)", c.Flen))
} else {
ans = append(ans, fmt.Sprintf("(%d, %d)", c.Flen, c.Decimal))
}
}
if mysql.HasUnsignedFlag(c.Flag) {
ans = append(ans, "UNSIGNED")
}
return strings.Join(ans, " ")
}
示例5: getTypeDesc
func (c *Col) getTypeDesc() string {
ans := []string{types.FieldTypeToStr(c.Tp, c.Charset)}
switch c.Tp {
case mysql.TypeSet, mysql.TypeEnum:
// Format is ENUM ('e1', 'e2') or SET ('e1', 'e2')
ans = append(ans, fmt.Sprintf("('%s')", strings.Join(c.Elems, "','")))
default:
if c.Flen != -1 {
if c.Decimal == -1 {
ans = append(ans, fmt.Sprintf("(%d)", c.Flen))
} else {
ans = append(ans, fmt.Sprintf("(%d, %d)", c.Flen, c.Decimal))
}
}
}
if mysql.HasUnsignedFlag(c.Flag) {
ans = append(ans, "UNSIGNED")
}
return strings.Join(ans, " ")
}
示例6: TypeError
// TypeError returns error for invalid value type.
func (c *Col) TypeError(v interface{}) error {
return errors.Errorf("cannot use %v (type %T) in assignment to, or comparison with, column %s (type %s)",
v, v, c.Name, types.FieldTypeToStr(c.Tp, c.Charset))
}
示例7: newParseColError
func newParseColError(err error, c *Col) error {
return errors.Errorf("parse err %v at column %s (type %s)", err, c.Name, types.FieldTypeToStr(c.Tp, c.Charset))
}