예제 #1
0
파일: expr.py 프로젝트: sthagen/edgedb
def compile_Parameter(expr: irast.Parameter, *,
                      ctx: context.CompilerContextLevel) -> pgast.BaseExpr:

    result: pgast.BaseParamRef
    is_decimal: bool = expr.name.isdecimal()

    if not is_decimal and ctx.env.use_named_params:
        result = pgast.NamedParamRef(
            name=expr.name,
            nullable=not expr.required,
        )
    else:
        try:
            index = ctx.argmap[expr.name].index
        except KeyError:
            if expr.name in ctx.argmap:
                index = ctx.argmap[expr.name].index
            else:
                if expr.name.startswith('__edb_arg_'):
                    index = int(expr.name[10:]) + 1
                elif is_decimal:
                    index = int(expr.name) + 1
                else:
                    index = next(ctx.next_argument)
                ctx.argmap[expr.name] = pgast.Param(
                    index=index,
                    required=expr.required,
                )
        result = pgast.ParamRef(number=index, nullable=not expr.required)

    return pgast.TypeCast(
        arg=result,
        type_name=pgast.TypeName(
            name=pg_types.pg_type_from_ir_typeref(expr.typeref)))
예제 #2
0
파일: expr.py 프로젝트: syyunn/edgedb
def compile_Parameter(
        expr: irast.Parameter, *,
        ctx: context.CompilerContextLevel) -> pgast.BaseExpr:

    result: pgast.BaseParamRef
    if expr.name.isdecimal():
        index = int(expr.name) + 1
        result = pgast.ParamRef(number=index)
    else:
        if ctx.env.use_named_params:
            result = pgast.NamedParamRef(name=expr.name)
        else:
            if expr.name in ctx.argmap:
                index = ctx.argmap[expr.name]
            else:
                index = len(ctx.argmap) + 1
                ctx.argmap[expr.name] = index

            result = pgast.ParamRef(number=index)

    return pgast.TypeCast(
        arg=result,
        type_name=pgast.TypeName(
            name=pg_types.pg_type_from_ir_typeref(expr.typeref)
        )
    )
예제 #3
0
def compile_Parameter(expr: irast.Parameter, *,
                      ctx: context.CompilerContextLevel) -> pgast.BaseExpr:

    result: pgast.BaseParamRef
    is_decimal: bool = expr.name.isdecimal()

    if not is_decimal and ctx.env.use_named_params:
        result = pgast.NamedParamRef(
            name=expr.name,
            nullable=not expr.required,
        )
    else:
        index = ctx.argmap[expr.name].index
        ctx.argmap[expr.name].used = True

        result = pgast.ParamRef(number=index, nullable=not expr.required)

    return pgast.TypeCast(
        arg=result,
        type_name=pgast.TypeName(
            name=pg_types.pg_type_from_ir_typeref(expr.typeref)))