|
From: CLIFFORD I. <cli...@di...> - 2004-06-24 21:30:05
|
Hi,
I am trying to trap a SQL error caused by attempting to INSERT a duplicate
unique key. Here is what I have tried.
#############
def writeContent(self):
pr = self.writeln
newForm = self.form
if newForm.isSuccessful():
theTelnumType =
TelnumType.byDescription(newForm.numType.value())
if theTelnumType:
pr('''<p>There is already a Telnum Type =
'%s'</p>''' % newForm.numType.value())
else: # not a duplicate so save
newTelnumType = TelnumType (
description = newForm.numType.value(),
modUserId = 'cilkay'
)
pr('''<p>Successfully saved Telnum Type =
'%s'</p>''' % newForm.numType.value())
else:
#############
So, if I already have a row in telnum_type where description = 'Home', no
problem, the code above will print out: "There is already a Telnum Type =
'Home'". However, if there is no Telnum Type = 'Home', I now get a
SQLObjectNotFound error raised by SQLObject. If I just try to insert
without doing a test for a duplicate value, I of course get the usual SQL
error about violating a unique key constraint. How can I trap SQL errors,
not just unique key constraint violations, so that I can provide meaningful
messages to end users?
Regards,
Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, Ontario
Canada M4N 3P6
Tel: 416-410-3326
|