Hi,
Sometimes the following code let cursor.execute() run in the "Cannot operate on 
a closed cursor" issue (seen with Trac 1.0 and SQLite). I played around with 
several trials for a fix but nothing seems to help. Could you help me and 
correct the following code example so that I can see what the proper use of 
that db API is? Yes, I’ve read 
http://trac.edgewall.org/wiki/TracDev/DatabaseApi but it’s still not clear to 
me how I must fix the closed cursor error. Thanks in advance.

class SmpModel(Component):

    # DB Method
    def __get_cursor(self):
        if VERSION < '0.12':
            self.db = self.env.get_db_cnx()
        else:
            self.db = self.env.get_read_db()
        return self.db.cursor()


    def __start_transacction(self):
        if VERSION < '0.12':
            # deprecated in newer versions
            self.db.commit()
            self.db.close()


    def get_ticket_project(self, id):
        cursor = self.__get_cursor()
        query    = """SELECT
                        value
                      FROM
                        ticket_custom
                      WHERE
                        name = 'project' AND ticket = %s"""
        cursor.execute(query, [id])
        self.__start_transacction()
        return cursor.fetchone()

CU, F@lk

----
R&D Software
Baumer Optronic GmbH
www.baumer.com<http://www.baumer.com/>



Geschäftsführer: Dr. Albert Schmidt · Dr. Oliver Vietze
Sitz der Gesellschaft: Radeberg
Amtsgericht Dresden: HRB 15379
Ust. ID: DE  189714583




-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to