# Buggy code
def get_allday_range(
    self,
    start,
    end=None,
    account=None,
    color="",
    readonly=False,
    unicode_symbols=True,
    show_deleted=True,
):
    if account is None:
        raise Exception("need to specify an account")
    strstart = start.strftime("%Y%m%d")
    if end is None:
        end = start + datetime.timedelta(days=1)
    strend = end.strftime("%Y%m%d")
    sql_s = (
        "SELECT href, dtstart, dtend FROM {0} WHERE "
        "dtstart >= ? AND dtstart < ? OR "
        "dtend > ? AND dtend <= ? OR "
        "dtstart <= ? AND dtend > ? "
    ).format(account + "_d")
    stuple = (strstart, strend, strstart, strend, strstart, strend)
    result = self.sql_ex(sql_s, stuple)
    event_list = list()
    for href, start, end in result:
        start = time.strptime(str(start), "%Y%m%d")
        end = time.strptime(str(end), "%Y%m%d")
        start = datetime.date(start.tm_year, start.tm_mon, start.tm_mday)
        end = datetime.date(end.tm_year, end.tm_mon, end.tm_mday)
        vevent = self.get_vevent_from_db(
            href,
            account,
            start=start,
            end=end,
            color=color,
            readonly=readonly,
            unicode_symbols=unicode_symbols,
        )
        if show_deleted or vevent.status not in [DELETED, CALCHANGED, NEWDELETE]:
            event_list.append(vevent)
    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_allday_range(
    self,
    start,
    end=None,
    account=None,
    color="",
    readonly=False,
    unicode_symbols=True,
    show_deleted=True,
):
    self._check_account(account)
    if account is None:
        raise Exception("need to specify an account")
    strstart = start.strftime("%Y%m%d")
    if end is None:
        end = start + datetime.timedelta(days=1)
    strend = end.strftime("%Y%m%d")
    sql_s = (
        "SELECT href, dtstart, dtend FROM {0} WHERE "
        "dtstart >= ? AND dtstart < ? OR "
        "dtend > ? AND dtend <= ? OR "
        "dtstart <= ? AND dtend > ? "
    ).format(account + "_d")
    stuple = (strstart, strend, strstart, strend, strstart, strend)
    result = self.sql_ex(sql_s, stuple)
    event_list = list()
    for href, start, end in result:
        start = time.strptime(str(start), "%Y%m%d")
        end = time.strptime(str(end), "%Y%m%d")
        start = datetime.date(start.tm_year, start.tm_mon, start.tm_mday)
        end = datetime.date(end.tm_year, end.tm_mon, end.tm_mday)
        vevent = self.get_vevent_from_db(
            href,
            account,
            start=start,
            end=end,
            color=color,
            readonly=readonly,
            unicode_symbols=unicode_symbols,
        )
        if show_deleted or vevent.status not in [DELETED, CALCHANGED, NEWDELETE]:
            event_list.append(vevent)
    return event_list