[Zope-DB] SQL Relay and _v_ variables
Dieter Maurer
dieter at handshake.de
Wed Oct 29 13:37:30 EST 2003
Chris Withers wrote at 2003-10-29 11:11 +0000:
> Dieter Maurer wrote:
> > However, the DA must be very careful to not open a second connection
> > to the same database within the same request. Otherwise, what
> > should be one transaction may become several independent ones.
> > This can lead to various obscure failures (e.g. database inconsistencies).
>
> Indeed, this is why you suggested that if the connection goes away, a
> ConflictError of some sort should be raised, so that Zope retries the request,
> right?
Right.
> Where is the code which actually does this?
Usually, it is in "query".
For "ZPsycopgDA", it (e.g.) looks like:
"Products/ZPsycopgDA/db.py":
def query(self, query_string, max_rows=None):
...
try:
for qs in filter(None, map(strip, split(query_string, sql_delimiter
....
except (psycopg.OperationalError,psycopg.InterfaceError), err:
# maybe an intermittent failure
# close, reopen and retry
# Python will stop us, when we try too often ("Maximal recursion"),
# but be aware that on some systems the C runtime stack
# may overflow before (in which case, the process is killed
# by SIGSEGV)
del c ; del self.db
self.db = self.connect(self.connection)
LOG('Postgres',INFO,'Retry',query_string)
return self.query(query_string, max_rows)
This code does not yet follow my advice to raise "ConflictError".
The comment is from me and not from the original authors of
"ZPsycopgDA". The code is theirs.
--
Dieter
More information about the Zope-DB
mailing list