[Zope] Reporting a bug in the Solid DA
Rob Page
rob.page@digicool.com
Wed, 14 Jul 1999 19:47:30 -0400
Ross:
> The PostgreSQL DA does the same thing, BTW. I know its
> 'contrib', so not
> supported by DC, but if someone gives me 1/2 a clue, I'd dig
> in and fix it.
Below is a code snippet (actually a long code snippet) from the Sybase
DA. Note the:
except self.Database_Error, v:
within which it tries once to restart/reestablish the connection.
--Rob
-------------------------------------------------------------
def query(self,query_string,
max_rows=9999999,
select_m=regex.compile('[\0- ]*select[\0- ]+',
regex.casefold).match,
try_again=1
):
global failures, calls
calls=calls+1
db=self.db
try:
c=self.cursor
self.register()
queries=filter(None, map(strip,split(query_string, '\0')))
if not queries: raise 'Query Error', 'empty query'
if len(queries) > 1:
result=[]
for qs in queries:
if select_m(qs) >= 0: raise 'Query Error', (
'select in multiple sql-statement query'
)
r=db.execute(qs)
#if r is None: raise 'Query Error', (
# 'select in multiple sql-statement query'
# )
result.append([qs, str(`r`), calls])
desc=nonselect_desc
else:
query_string=queries[0]
if select_m(query_string) >= 0:
r=c.execute(query_string)
result=c.fetchmany(max_rows)
desc=c.description[0]
else:
r=db.execute(query_string)
result=[[query_string, str(`r`), calls]]
desc=nonselect_desc
failures=0
c.close()
except self.Database_Error, v:
messages=[]
ertype=v[0]
server=0
for m in v[1:]:
if m[0]=='server':
server=1
messages.append(m[4])
else: messages.append(m[3])
try: self.db.rollback()
except: pass
failures=failures+1
if not server: # Connection is bad
try: c.close()
except: pass
try: self.db.close()
except: pass
# Hm. maybe the db is hosed. Let's try once to restart
it.
if try_again:
failures=0
try:
db=self.db=self.Database_Connection(self.connection)
self.cursor=db.cursor()
return self.query(query_string, max_rows,
try_again=0)
except: pass
raise self.Database_Error, (
"%s\n<ul><li>%s\n</ul>\n" % (ertype,
join(messages,"\n<li>")))