Example #1
0
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, " ")
}
Example #2
0
// String joins the information of FieldType and
// returns a string.
func (ft *FieldType) String() string {
	ts := FieldTypeToStr(ft.Tp, ft.Charset)
	ans := []string{ts}
	if ft.Flen != UnspecifiedLength {
		if ft.Decimal == UnspecifiedLength {
			ans = append(ans, fmt.Sprintf("(%d)", ft.Flen))
		} else {
			ans = append(ans, fmt.Sprintf("(%d, %d)", ft.Flen, ft.Decimal))
		}
	} else if ft.Decimal != UnspecifiedLength {
		ans = append(ans, fmt.Sprintf("(%d)", ft.Decimal))
	}
	if mysql.HasUnsignedFlag(ft.Flag) {
		ans = append(ans, "UNSIGNED")
	}
	if mysql.HasZerofillFlag(ft.Flag) {
		ans = append(ans, "ZEROFILL")
	}
	if mysql.HasBinaryFlag(ft.Flag) {
		ans = append(ans, "BINARY")
	}
	if ft.Charset != "" && ft.Charset != charset.CharsetBin &&
		(IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp)) {
		ans = append(ans, fmt.Sprintf("CHARACTER SET %s", ft.Charset))
	}
	if ft.Collate != "" && ft.Collate != charset.CharsetBin &&
		(IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp)) {
		ans = append(ans, fmt.Sprintf("COLLATE %s", ft.Collate))
	}
	return strings.Join(ans, " ")
}
Example #3
0
// String joins the information of FieldType and
// returns a string.
func (ft *FieldType) String() string {
	ts := FieldTypeToStr(ft.Tp, ft.Charset)
	ans := []string{ts}
	switch ft.Tp {
	case mysql.TypeEnum, mysql.TypeSet:
		// Format is ENUM ('e1', 'e2') or SET ('e1', 'e2')
		ans = append(ans, fmt.Sprintf("('%s')", strings.Join(ft.Elems, "','")))
	default:
		if ft.Flen != UnspecifiedLength {
			if ft.Decimal == UnspecifiedLength {
				ans = append(ans, fmt.Sprintf("(%d)", ft.Flen))
			} else {
				ans = append(ans, fmt.Sprintf("(%d, %d)", ft.Flen, ft.Decimal))
			}
		} else if ft.Decimal != UnspecifiedLength {
			ans = append(ans, fmt.Sprintf("(%d)", ft.Decimal))
		}
	}

	if mysql.HasUnsignedFlag(ft.Flag) {
		ans = append(ans, "UNSIGNED")
	}
	if mysql.HasZerofillFlag(ft.Flag) {
		ans = append(ans, "ZEROFILL")
	}
	if mysql.HasBinaryFlag(ft.Flag) {
		ans = append(ans, "BINARY")
	}
	if ft.Charset != "" && ft.Charset != charset.CharsetBin &&
		(IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp)) {
		ans = append(ans, fmt.Sprintf("CHARACTER SET %s", ft.Charset))
	}
	if ft.Collate != "" && ft.Collate != charset.CharsetBin &&
		(IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp)) {
		ans = append(ans, fmt.Sprintf("COLLATE %s", ft.Collate))
	}
	return strings.Join(ans, " ")
}
Example #4
0
// String joins the information of FieldType and
// returns a string.
func (ft *FieldType) String() string {
	strs := []string{ft.CompactStr()}
	if mysql.HasUnsignedFlag(ft.Flag) {
		strs = append(strs, "UNSIGNED")
	}
	if mysql.HasZerofillFlag(ft.Flag) {
		strs = append(strs, "ZEROFILL")
	}
	if mysql.HasBinaryFlag(ft.Flag) {
		strs = append(strs, "BINARY")
	}

	if IsTypeChar(ft.Tp) || IsTypeBlob(ft.Tp) {
		if ft.Charset != "" && ft.Charset != charset.CharsetBin {
			strs = append(strs, fmt.Sprintf("CHARACTER SET %s", ft.Charset))
		}
		if ft.Collate != "" && ft.Collate != charset.CharsetBin {
			strs = append(strs, fmt.Sprintf("COLLATE %s", ft.Collate))
		}
	}

	return strings.Join(strs, " ")
}