示例#1
0
文件: config.py 项目: syyunn/edgedb
def compile_ConfigSet(
    expr: qlast.ConfigSet, *,
    ctx: context.ContextLevel,
) -> irast.ConfigSet:

    info = _validate_op(expr, ctx=ctx)
    param_val = dispatch.compile(expr.expr, ctx=ctx)

    try:
        ireval.evaluate(param_val, schema=ctx.env.schema)
    except ireval.UnsupportedExpressionError as e:
        level = 'SYSTEM' if expr.system else 'SESSION'
        raise errors.QueryError(
            f'non-constant expression in CONFIGURE {level} SET',
            context=expr.expr.context
        ) from e

    return irast.ConfigSet(
        name=info.param_name,
        cardinality=info.cardinality,
        system=expr.system,
        requires_restart=info.requires_restart,
        backend_setting=info.backend_setting,
        context=expr.context,
        expr=param_val,
    )
示例#2
0
def compile_ConfigSet(
    expr: qlast.ConfigSet, *,
    ctx: context.ContextLevel,
) -> irast.Set:

    info = _validate_op(expr, ctx=ctx)
    param_val = setgen.ensure_set(
        dispatch.compile(expr.expr, ctx=ctx), ctx=ctx)

    try:
        ireval.evaluate(param_val, schema=ctx.env.schema)
    except ireval.UnsupportedExpressionError as e:
        raise errors.QueryError(
            f'non-constant expression in CONFIGURE {expr.scope} SET',
            context=expr.expr.context
        ) from e

    config_set = irast.ConfigSet(
        name=info.param_name,
        cardinality=info.cardinality,
        scope=expr.scope,
        requires_restart=info.requires_restart,
        backend_setting=info.backend_setting,
        context=expr.context,
        expr=param_val,
    )
    return setgen.ensure_set(config_set, ctx=ctx)
示例#3
0
def compile_ConfigSet(
    expr: qlast.ConfigSet,
    *,
    ctx: context.ContextLevel,
) -> irast.Set:

    info = _validate_op(expr, ctx=ctx)
    param_val = dispatch.compile(expr.expr, ctx=ctx)
    param_type = info.param_type
    val_type = inference.infer_type(param_val, ctx.env)
    compatible = s_types.is_type_compatible(val_type,
                                            param_type,
                                            schema=ctx.env.schema)
    if not compatible:
        if not val_type.assignment_castable_to(param_type, ctx.env.schema):
            raise errors.ConfigurationError(
                f'invalid setting value type for {info.param_name}: '
                f'{val_type.get_displayname(ctx.env.schema)!r} '
                f'(expecting {param_type.get_displayname(ctx.env.schema)!r})')
        else:
            param_val = casts.compile_cast(param_val,
                                           param_type,
                                           srcctx=None,
                                           ctx=ctx)

    try:
        if expr.scope != qltypes.ConfigScope.GLOBAL:
            val = ireval.evaluate_to_python_val(param_val,
                                                schema=ctx.env.schema)
        else:
            val = None
    except ireval.UnsupportedExpressionError as e:
        raise errors.QueryError(
            f'non-constant expression in CONFIGURE {expr.scope} SET',
            context=expr.expr.context) from e
    else:
        if isinstance(val, statypes.ScalarType) and info.backend_setting:
            backend_expr = dispatch.compile(
                qlast.StringConstant.from_python(val.to_backend_str()),
                ctx=ctx,
            )
        else:
            backend_expr = None

    config_set = irast.ConfigSet(
        name=info.param_name,
        cardinality=info.cardinality,
        required=info.required,
        scope=expr.scope,
        requires_restart=info.requires_restart,
        backend_setting=info.backend_setting,
        context=expr.context,
        expr=param_val,
        backend_expr=backend_expr,
    )
    return setgen.ensure_set(config_set, ctx=ctx)