# Buggy code
def get_time_range(
    self,
    start,
    end,
    account,
    color="",
    readonly=False,
    unicode_symbols=True,
    show_deleted=True,
):
    """returns
    :type start: datetime.datetime
    :type end: datetime.datetime
    :param deleted: include deleted events in returned lsit
    """
    start = time.mktime(start.timetuple())
    end = time.mktime(end.timetuple())
    sql_s = (
        "SELECT href, dtstart, dtend FROM {0} WHERE "
        "dtstart >= ? AND dtstart <= ? OR "
        "dtend >= ? AND dtend <= ? OR "
        "dtstart <= ? AND dtend >= ?"
    ).format(account + "_dt")
    stuple = (start, end, start, end, start, end)
    result = self.sql_ex(sql_s, stuple)
    event_list = list()
    for href, start, end in result:
        start = pytz.UTC.localize(datetime.datetime.utcfromtimestamp(start))
        end = pytz.UTC.localize(datetime.datetime.utcfromtimestamp(end))
        event = self.get_vevent_from_db(
            href,
            account,
            start=start,
            end=end,
            color=color,
            readonly=readonly,
            unicode_symbols=unicode_symbols,
        )
        if show_deleted or event.status not in [DELETED, CALCHANGED, NEWDELETE]:
            event_list.append(event)

    return event_list


# Traceback (sqlite3.OperationalError)
Traceback (most recent call last):
File "/home/catern/src/khal/virt/bin/khal", line 5, in <module>
pkg_resources.run_script('khal==0.1.0.dev', 'khal')
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 540, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 1462, in run_script
exec_(script_code, namespace, namespace)
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/pkg_resources.py", line 41, in exec_
exec("""exec code in globs, locs""")
File "<string>", line 1, in <module>
File "/home/catern/src/khal/virt/lib/python2.7/site-packages/khal-0.1.0.dev-py2.7.egg/EGG-INFO/scripts/khal", line 72, in <module>

File "build/bdist.linux-x86_64/egg/khal/controllers.py", line 178, in __init__
File "build/bdist.linux-x86_64/egg/khal/backend.py", line 440, in get_allday_range
File "build/bdist.linux-x86_64/egg/khal/backend.py", line 164, in sql_ex
sqlite3.OperationalError: no such table: simple_d

# Fixed code
def get_time_range(
    self,
    start,
    end,
    account,
    color="",
    readonly=False,
    unicode_symbols=True,
    show_deleted=True,
):
    """returns
    :type start: datetime.datetime
    :type end: datetime.datetime
    :param deleted: include deleted events in returned lsit
    """
    self._check_account(account)
    start = time.mktime(start.timetuple())
    end = time.mktime(end.timetuple())
    sql_s = (
        "SELECT href, dtstart, dtend FROM {0} WHERE "
        "dtstart >= ? AND dtstart <= ? OR "
        "dtend >= ? AND dtend <= ? OR "
        "dtstart <= ? AND dtend >= ?"
    ).format(account + "_dt")
    stuple = (start, end, start, end, start, end)
    result = self.sql_ex(sql_s, stuple)
    event_list = list()
    for href, start, end in result:
        start = pytz.UTC.localize(datetime.datetime.utcfromtimestamp(start))
        end = pytz.UTC.localize(datetime.datetime.utcfromtimestamp(end))
        event = self.get_vevent_from_db(
            href,
            account,
            start=start,
            end=end,
            color=color,
            readonly=readonly,
            unicode_symbols=unicode_symbols,
        )
        if show_deleted or event.status not in [DELETED, CALCHANGED, NEWDELETE]:
            event_list.append(event)

    return event_list