// AsInterface converts the ValExpr to an interface. It converts // ValTuple to []interface{}, ValArg to string, StrVal to sqltypes.String, // NumVal to sqltypes.Numeric, NullVal to nil. // Otherwise, it returns an error. func AsInterface(node ValExpr) (interface{}, error) { switch node := node.(type) { case ValTuple: vals := make([]interface{}, 0, len(node)) for _, val := range node { v, err := AsInterface(val) if err != nil { return nil, err } vals = append(vals, v) } return vals, nil case ValArg: return hack.String(node), nil case ListArg: return hack.String(node), nil case StrVal: return sqltypes.MakeString(node), nil case NumVal: n, err := sqltypes.BuildNumeric(hack.String(node)) if err != nil { return nil, fmt.Errorf("type mismatch: %s", err) } return n, nil case *NullVal: return nil, nil } return nil, fmt.Errorf("unexpected node %v", node) }
func (node StrVal) Format(buf *TrackedBuffer) { s := sqltypes.MakeString([]byte(node)) s.EncodeSql(buf) }