Exemplo n.º 1
0
    def compile(self):
        name = quote_identifier(self.name)

        create_decl = 'CREATE DATABASE'
        create_line = '{0} {1}{2}'.format(create_decl, self._if_exists(), name)
        if self.path is not None:
            create_line += "\nLOCATION '{0}'".format(self.path)

        return create_line
Exemplo n.º 2
0
    def compile(self):
        if_exists = '' if self.fail_if_exists else 'IF NOT EXISTS '
        name = quote_identifier(self.name)

        create_decl = 'CREATE DATABASE'
        create_line = '{0} {1}{2}'.format(create_decl, if_exists, name)
        if self.path is not None:
            create_line += "\nLOCATION '{0}'".format(self.path)

        return create_line
Exemplo n.º 3
0
    def compile(self):
        name = quote_identifier(self.name)

        create_decl = 'CREATE DATABASE'
        create_line = '{0} {1}{2}'.format(create_decl, self._if_exists(),
                                          name)
        if self.path is not None:
            create_line += "\nLOCATION '{0}'".format(self.path)

        return create_line
Exemplo n.º 4
0
def _format_table(ctx, expr, indent=2):
    # TODO: This could probably go in a class and be significantly nicer

    ref_expr = expr
    op = ref_op = expr.op()
    if isinstance(op, ops.SelfReference):
        ref_expr = op.table
        ref_op = ref_expr.op()

    if isinstance(ref_op, ops.PhysicalTable):
        name = ref_op.name
        if name is None:
            raise com.RelationError('Table did not have a name: {0!r}'
                                    .format(expr))
        result = quote_identifier(name)
        is_subquery = False
    else:
        # A subquery
        if ctx.is_extracted(ref_expr):
            # Was put elsewhere, e.g. WITH block, we just need to grab its
            # alias
            alias = ctx.get_alias(expr)

            # HACK: self-references have to be treated more carefully here
            if isinstance(op, ops.SelfReference):
                return '{0} {1}'.format(ctx.get_alias(ref_expr), alias)
            else:
                return alias

        subquery = ctx.get_formatted_query(expr)
        result = '(\n{0}\n)'.format(util.indent(subquery, indent))
        is_subquery = True

    if is_subquery or ctx.need_aliases():
        result += ' {0}'.format(ctx.get_alias(expr))

    return result
Exemplo n.º 5
0
def _format_schema_element(name, t):
    return '{0} {1}'.format(quote_identifier(name, force=True),
                            _format_type(t))