示例#1
0
func (self *Table) AddColumn(name string, columnType string, defval sqltypes.Value, extra string, isPk, nullable bool) {
	index := len(self.Columns)
	self.Columns = append(self.Columns, TableColumn{Name: name})
	self.Columns[index].IsPk = isPk
	self.Columns[index].Nullable = nullable
	if strings.Contains(columnType, "int") {
		self.Columns[index].Category = CAT_NUMBER
	} else if strings.HasPrefix(columnType, "varbinary") {
		self.Columns[index].Category = CAT_VARBINARY
	} else if strings.HasPrefix(columnType, "fractional") {
		self.Columns[index].Category = CAT_FRACTIONAL
	} else {
		self.Columns[index].Category = CAT_OTHER
	}

	if extra == "auto_increment" {
		self.Columns[index].IsAuto = true
		self.Columns[index].NextId = 0
		// Ignore default value, if any
		return
	} else if extra == "uuid" {
		self.Columns[index].IsUUID = true
	}

	if defval.IsNull() {
		return
	}
	if self.Columns[index].Category == CAT_NUMBER {
		self.Columns[index].Default = sqltypes.MakeNumeric(defval.Raw())
	} else {
		self.Columns[index].Default = sqltypes.MakeString(defval.Raw())
	}
}
示例#2
0
文件: codex.go 项目: ngaut/RationalDb
func buildValue(bytes []byte, fieldType uint32) sqltypes.Value {
	switch fieldType {
	case schema.TYPE_FRACTIONAL:
		return sqltypes.MakeFractional(bytes)
	case schema.TYPE_NUMERIC:
		return sqltypes.MakeNumeric(bytes)
	}
	return sqltypes.MakeString(bytes)
}
示例#3
0
func buildValue(bytes []byte, fieldType int64) sqltypes.Value {
	switch fieldType {
	case schema.CAT_FRACTIONAL:
		return sqltypes.MakeFractional(bytes)
	case schema.CAT_NUMBER:
		return sqltypes.MakeNumeric(bytes)
	}
	return sqltypes.MakeString(bytes)
}