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
defopencursor(self):importMySQLdbself.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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.