예제 #1
0
func asValue(node *Node) sqltypes.Value {
	switch node.Type {
	case STRING:
		return sqltypes.MakeString(node.Value)
	case NUMBER:
		n, err := sqltypes.BuildNumeric(string(node.Value))
		if err != nil {
			panic(NewParserError("Type mismatch: %s", err))
		}
		return n
	}
	panic(NewParserError("Unexpected node %v", node))
}
예제 #2
0
파일: codex.go 프로젝트: ngaut/RationalDb
func validateKey(tableInfo *schema.Table, key string) (newKey string) {
	if key == "" {
		// TODO: Verify auto-increment table
		return
	}
	pieces := strings.Split(key, ".")
	if len(pieces) != len(tableInfo.PKColumns) {
		// TODO: Verify auto-increment table
		return ""
	}
	pkValues := make([]sqltypes.Value, len(tableInfo.PKColumns))
	for i, piece := range pieces {
		if piece[0] == '\'' {
			s, err := base64.StdEncoding.DecodeString(piece[1 : len(piece)-1])
			if err != nil {
				log.Warn("Error decoding key %s for table %s: %v", key, tableInfo.Name, err)
				errorStats.Add("Mismatch", 1)
				return
			}
			pkValues[i] = sqltypes.MakeString(s)
		} else if piece == "null" {
			// TODO: Verify auto-increment table
			return ""
		} else {
			n, err := sqltypes.BuildNumeric(piece)
			if err != nil {
				log.Warn("Error decoding key %s for table %s: %v", key, tableInfo.Name, err)
				errorStats.Add("Mismatch", 1)
				return
			}
			pkValues[i] = n
		}
	}
	if newKey = buildKey(pkValues); newKey != key {
		log.Warn("Error: Key mismatch, received: %s, computed: %s", key, newKey)
		errorStats.Add("Mismatch", 1)
	}
	return newKey
}