Example #1
0
    def __init__(self,
                 msg=None,
                 *,
                 hint=None,
                 details=None,
                 token=None,
                 line=None,
                 col=None,
                 expr=None,
                 context=None):
        if msg is None:
            msg = 'syntax error at or near "%s"' % token
        super().__init__(msg, hint=hint, details=details)

        self.token = token
        if line is not None:
            self.line = line
        if col is not None:
            self.col = col
        self.expr = expr
        if context:
            add_context(self, context)
            if line is None and col is None:
                self.line = context.start.line
                self.col = context.start.column
Example #2
0
 def to_source(
         cls, node, indent_with=' ' * 4, add_line_information=False,
         pretty=True):
     try:
         return super().to_source(
             node, indent_with=indent_with,
             add_line_information=add_line_information, pretty=pretty)
     except SQLSourceGeneratorError as e:
         ctx = SQLSourceGeneratorContext(node)
         exceptions.add_context(e, ctx)
         raise
Example #3
0
def _run_codegen(qtree, *, pretty=True):
    codegen = pgcodegen.SQLSourceGenerator(pretty=pretty)
    try:
        codegen.visit(qtree)
    except pgcodegen.SQLSourceGeneratorError as e:  # pragma: no cover
        ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result)
        edgedb_error.add_context(e, ctx)
        raise
    except Exception as e:  # pragma: no cover
        ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result)
        err = pgcodegen.SQLSourceGeneratorError(
            'error while generating SQL source')
        edgedb_error.add_context(err, ctx)
        raise err from e

    return codegen
Example #4
0
def run_codegen(
    qtree: pgast.Base,
    *,
    pretty: bool = True,
    reordered: bool = False,
) -> str:
    codegen = pgcodegen.SQLSourceGenerator(pretty=pretty, reordered=reordered)
    try:
        codegen.visit(qtree)
    except pgcodegen.SQLSourceGeneratorError as e:  # pragma: no cover
        ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result)
        edgedb_error.add_context(e, ctx)
        raise
    except Exception as e:  # pragma: no cover
        ctx = pgcodegen.SQLSourceGeneratorContext(qtree, codegen.result)
        err = pgcodegen.SQLSourceGeneratorError(
            'error while generating SQL source')
        edgedb_error.add_context(err, ctx)
        raise err from e

    return ''.join(codegen.result)
Example #5
0
 def __init__(self, msg, *, node=None, details=None, hint=None):
     super().__init__(msg, details=details, hint=hint)
     if node is not None:
         ctx = SQLSourceGeneratorContext(node)
         exceptions.add_context(self, ctx)