import re


def table_cols(con, tbl):
    """ Return set containing the table's columns. """

    cur = con.cursor()
    sql = """SELECT sql FROM sqlite_master WHERE tbl_name = ?"""
    cur.execute(sql, (tbl,))
    row = cur.fetchone()

    if row == None:
        return []
    createtbl_sql = row[0]

    # Get field definition
    # the contents of '...' in CREATE TABLE tblname (...)
    m = re.search(r'(?s)\(\s*(.*)\s*\)', createtbl_sql)
    if m == None:
        return []
    fields_sql = m.group(1).strip()

    # Separate each field definition.
    # _id TEXT PRIMARY KEY,
    # _body TEXT
    # field1 TEXT
    # field2 TEXT
    field_defns = re.split(r',\s*', fields_sql)

    # First word of each field definition is the field name.
    # _id
    # _body
    # field1
    # field2
    cols = set()
    for field_defn in field_defns:
        field = re.split(r'\s+', field_defn)
        cols.add(field[0])
    return cols