Exemple #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())
	}
}
Exemple #2
0
func validateValue(col *schema.TableColumn, value sqltypes.Value) {
	if value.IsNull() {
		return
	}
	switch col.Category {
	case schema.CAT_NUMBER:
		if !value.IsNumeric() {
			panic(NewTabletError(FAIL, "Type mismatch, expecting numeric type for %v", value))
		}
	case schema.CAT_VARBINARY:
		if !value.IsString() {
			panic(NewTabletError(FAIL, "Type mismatch, expecting string type for %v", value))
		}
	}
}