Menu

Direct access to execute() in ZMySQLDA

2005-04-12
2012-09-19
  • Dave Cinege

    Dave Cinege - 2005-04-12

    Andy,

    Can you give me some advise on the best way to access mysql from within Zope,
    when only using external methods? I'm not concerned with Zope transactioning.
    I only need a reliable connection.

    I'm not using ZMySQLDA because my own custom SQL wrapper (kisSQL) depends
    on calling MySQLdb's execute() and also depends on DictCursor.

    In my Zope external methods I'm calling GetDBC() (below) to create a new
    conneciton at the begining of every function that does SQL.

    It is ugly, but generally works well. (It's a low traffic intranet application, not a website)
    However I've been seeing some lost connection type of errors that turn up
    once in awhile. I reload the page that errored and everything is fine.

    Is there a quick fix for what I have, or a butt way for me to backend into ZMySQLDA?

    def GetDBC ():
    import kisSQL
    global sql
    if 'sql' not in globals():
    sql = kisSQL.kisSQL(db=dbname,user=dbuser,passwd=dbpass)

    Inside my kisSQL class

    def opencursor(self):
        import MySQLdb
        self.dbcTuple = self.dbconn.cursor()
        self.dbcDict = self.dbconn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
        self.dbc = self.dbcDict
        #self.dbc get thereafter assigned to dbcTuple or dbcDict as needed.
    
     
    • Andy Dustman

      Andy Dustman - 2005-04-12

      Try this: Before calling .cursor(), call self.dbconn.ping()

      See if that cures your problem. I am assuming that your cursors are relatively short-lived. The main point is to call connection.ping() at the start of a transaction. This will restart the connection if it is no longer open.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.