Re: [pysqlite] [APSW] "SQLError: cannot rollback - no transaction is active"

"Eric S. Johansson" <[email protected]> Sat, 29 Nov 2008 10:34:11 -0500
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Roger Binns wrote:

> Please can you post an example of this code, because there is something
> we are missing.

that is a really good idea because if I can do things better, I want to learn how.

select generator:

bfm_select = "select * from %s where %s %s;"

    def generate_select (self, state=None, key=None, tpblue_ID = None,
order_field= None ):
        if state is not None and key is None:
            # retrieve by state
            select_me = "state='%s'"%state
            match_on = state
        elif state is None and key is not None:
            # retrieve by key
            select_me = "trap_id='%s'"%key
            match_on = key
        else:
            raise "bad state and key argument"

        # fill an optional selector limiting search to specific twopenny blue ID
        filler = ''
        if tpblue_ID is not None:
            filler = " and tpblue_id='%s'" %tpblue_ID
        select_me = select_me + filler

        sort_order = ""
        if order_field is not None:
            sort_order =  " ORDER BY %s" % order_field
        log("select command %s  || %s"%(select_me, sort_order),1)
        select_command = bfm_select % (self.table_name,  select_me, sort_order )

        log("select command %s "%(select_command),1)
        return select_command, match_on