Untitled

 avatar
unknown
plain_text
a month ago
1.2 kB
4
Indexable
def get_trigger_count(connection, schema_name):
    """Get count of triggers for a schema"""
    try:
        cursor = connection.cursor()
        sql = """
        SELECT COUNT(*) 
        FROM DBA_TRIGGERS 
        WHERE OWNER = :schema 
        AND TRIGGER_NAME NOT LIKE 'AUD%'
        """
        cursor.execute(sql, {'schema': schema_name})
        count = cursor.fetchone()[0]
        cursor.close()
        return count
    except Exception as e:
        printf(f'Error getting trigger count: {e}')
        if 'cursor' in locals():
            cursor.close()
        return None


printf(f'Getting initial trigger counts', True)
initial_trigger_counts = {}
for sch in schemaList:
    count = get_trigger_count(connection, sch)
    initial_trigger_counts[sch] = count
    printf(f'Schema {sch} - Initial trigger count: {count}')




printf(f'Getting final trigger counts', True)
for sch in schemaList:
    final_count = get_trigger_count(connection, sch)
    initial_count = initial_trigger_counts[sch]
    printf(f'Schema {sch}:')
    printf(f'  - Initial trigger count: {initial_count}')
    printf(f'  - Final trigger count: {final_count}')
    printf(f'  - Difference: {final_count - initial_count}')
Leave a Comment