Beispiel #1
0
class OracleDatabase(Database):
    __adapter__ = 'oracle'
    __xmlns__ = 'http://www.daversy.org/schemas/state/oracle'
    __xsd__ = state_xsd.schema
    __conn__ = connection.OracleConnection
    __state__ = OracleState
    __builders__ = [
        OracleStateBuilder(),
        OracleObjectTypeBuilder(),
        TableBuilder(),
        TableColumnBuilder(),
        PrimaryKeyBuilder(),
        PrimaryKeyColumnBuilder(),
        UniqueKeyBuilder(),
        UniqueKeyColumnBuilder(),
        CheckConstraintBuilder(),
        SequenceBuilder(),
        IndexBuilder(),
        IndexColumnBuilder(),
        ForeignKeyBuilder(),
        ForeignKeyColumnBuilder(),
        OracleMaterializedViewBuilder(),
        ViewBuilder(),
        ViewColumnBuilder(),
        StoredProcedureBuilder(),
        FunctionBuilder(),
        OraclePackageBuilder(),
        TriggerBuilder()
    ]
Beispiel #2
0
    def commentSQL(table):
        template = "COMMENT ON TABLE %(name)s IS '%(comment)s';"
        result = []
        if table.comment:
            result.append(render(template, table, 
                                 comment = sql_escape(table.comment)))
        
        for column in table.columns.values():
            col_comment = TableColumnBuilder.commentSQL(table, column)
            if col_comment:
                result.append(col_comment)

        return result
Beispiel #3
0
    def commentSQL(table):
        template = "COMMENT ON TABLE %(name)s IS '%(comment)s';"
        result = []
        if table.comment:
            result.append(
                render(template, table, comment=sql_escape(table.comment)))

        for column in table.columns.values():
            col_comment = TableColumnBuilder.commentSQL(table, column)
            if col_comment:
                result.append(col_comment)

        return result
Beispiel #4
0
    def createSQL(table):
        sql = "CREATE %(temp1)sTABLE %(name)s (\n  %(table_sql)s\n)\n%(temp2)s/\n"

        definition = []
        for col in table.columns.values():
            definition.append(TableColumnBuilder.sql(col))
        for key in table.primary_keys.values():
            definition.append(PrimaryKeyBuilder.sql(key))
        for key in table.unique_keys.values():
            definition.append(UniqueKeyBuilder.sql(key))
        for constraint in table.constraints.values():
            definition.append(CheckConstraintBuilder.sql(constraint))

        table_sql = ",\n  ".join(definition)
        t1, t2 = '', ''
        if table.temporary == 'true':
            t1 = 'GLOBAL TEMPORARY '
            if table.get('on-commit-preserve-rows') == 'true':
                t2 = 'ON COMMIT PRESERVE ROWS\n'
            else:
                t2 = 'ON COMMIT DELETE ROWS\n'
        elif table.iot == 'true':
            t2 = 'ORGANIZATION INDEX'
            pk = table.primary_keys.values()[0]
            if pk.compress:
                t2 += ' COMPRESS '+pk.compress
            t2 += '\n'
        else:
            for key in table.primary_keys.values():
                if key.compress:
                    t2 += '/\nALTER INDEX %(name)s REBUILD COMPRESS %(compress)s\n' % key
            for key in table.unique_keys.values():
                if key.compress:
                    t2 += '/\nALTER INDEX %(name)s REBUILD COMPRESS %(compress)s\n' % key

        return render(sql, table, temp1=t1, temp2=t2, table_sql=table_sql)
Beispiel #5
0
    def createSQL(table):
        sql = "CREATE %(temp1)sTABLE %(name)s (\n  %(table_sql)s\n)\n%(temp2)s/\n"

        definition = []
        for col in table.columns.values():
            definition.append(TableColumnBuilder.sql(col))
        for key in table.primary_keys.values():
            definition.append(PrimaryKeyBuilder.sql(key))
        for key in table.unique_keys.values():
            definition.append(UniqueKeyBuilder.sql(key))
        for constraint in table.constraints.values():
            definition.append(CheckConstraintBuilder.sql(constraint))

        table_sql = ",\n  ".join(definition)
        t1, t2 = '', ''
        if table.temporary == 'true':
            t1 = 'GLOBAL TEMPORARY '
            if table.get('on-commit-preserve-rows') == 'true':
                t2 = 'ON COMMIT PRESERVE ROWS\n'
            else:
                t2 = 'ON COMMIT DELETE ROWS\n'
        elif table.iot == 'true':
            t2 = 'ORGANIZATION INDEX'
            pk = table.primary_keys.values()[0]
            if pk.compress:
                t2 += ' COMPRESS ' + pk.compress
            t2 += '\n'
        else:
            for key in table.primary_keys.values():
                if key.compress:
                    t2 += '/\nALTER INDEX %(name)s REBUILD COMPRESS %(compress)s\n' % key
            for key in table.unique_keys.values():
                if key.compress:
                    t2 += '/\nALTER INDEX %(name)s REBUILD COMPRESS %(compress)s\n' % key

        return render(sql, table, temp1=t1, temp2=t2, table_sql=table_sql)