Exemple #1
0
func resolveValue(col *schema.TableColumn, value interface{}, bindVars map[string]interface{}) (result sqltypes.Value, err error) {
	if v, ok := value.(string); ok {
		value, _, err = sqlparser.FetchBindVar(v, bindVars)
		if err != nil {
			return result, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
		}
	}
	result, err = sqltypes.BuildConverted(col.Type, value)
	if err != nil {
		return result, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
	}
	if err = validateValue(col, result); err != nil {
		return result, err
	}
	return result, nil
}
Exemple #2
0
func resolveListArg(col *schema.TableColumn, key string, bindVars map[string]interface{}) ([]sqltypes.Value, error) {
	val, _, err := sqlparser.FetchBindVar(key, bindVars)
	if err != nil {
		return nil, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
	}
	list := val.([]interface{})
	resolved := make([]sqltypes.Value, len(list))
	for i, v := range list {
		sqlval, err := sqltypes.BuildConverted(col.Type, v)
		if err != nil {
			return nil, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
		}
		if err = validateValue(col, sqlval); err != nil {
			return nil, err
		}
		resolved[i] = sqlval
	}
	return resolved, nil
}
Exemple #3
0
func resolveValue(col *schema.TableColumn, value interface{}, bindVars map[string]interface{}) (result sqltypes.Value, err error) {
	switch v := value.(type) {
	case string:
		val, _, err := sqlparser.FetchBindVar(v, bindVars)
		if err != nil {
			return result, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
		}
		sqlval, err := sqltypes.BuildConverted(col.Type, val)
		if err != nil {
			return result, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "%v", err)
		}
		result = sqlval
	case sqltypes.Value:
		result = v
	default:
		return result, NewTabletError(ErrFail, vtrpcpb.ErrorCode_BAD_INPUT, "incompatible value type %v", v)
	}

	if err = validateValue(col, result); err != nil {
		return result, err
	}
	return result, nil
}