def doQuery(q, *args):
    matchid = 'select * from foo where id ='
    setsql = 'update foo set subject = '
    insertsql = 'insert into foo values'
    if q == 'select * from foo':
        return whole
    elif q.startswith(matchid):
        theId = args[0]
        for dbid, subj in whole:
            if dbid == theId:
                return [(dbid, subj)]
        raise KeyError, theId
    elif q.startswith(setsql):
        newsubj, theId = args
        for index, (dbid, subj) in enumerate(whole):
            if dbid == theId:
                whole[index] = (dbid, newsubj)
    elif q.startswith(insertsql):
        max = whole[-1][0]
        subject, = args
        whole.append((max + 1, subject))
Pretend like we have a database and we are accessing it through this hypothetical interface.
dataset/ETHPy150Open twisted/nevow/examples/db/db.py/doQuery