def parse_sql(filename):
    """
    Separates statements in .sql file for sequential execution.
    Slightly modified from adamlamers at http://adamlamers.com/post/GRBJUKCDMPOA
    :param filename: Path to .sql file
    :return: List of sql commands
    """
    data = open(filename, 'r').readlines()
    stmts = []
    DELIMITER = ';'
    stmt = ''

    for lineno, line in enumerate(data):
        if not line.strip():
            continue

        if line.startswith('--'):
            continue

        if 'DELIMITER' in line:
            DELIMITER = line.split()[1]
            continue

        if DELIMITER not in line:
            stmt += line.replace(DELIMITER, ';')
            continue

        if stmt:
            stmt += line
            stmts.append(stmt.strip())
            stmt = ''
        else:
            stmts.append(line.strip())

        stmts = [stmt.replace('\n', '') for stmt in stmts]

    return stmts