Catch some sqlite exceptions that probably shouldn't be happening, but I

don't have the best of luck with sqlite.
This commit is contained in:
James Vega 2004-06-19 18:03:58 +00:00
parent 21764931ec
commit 18138da1c0

View File

@ -183,7 +183,11 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
if len(url) >= minlen:
db = self.getDb(channel)
cursor = db.cursor()
try:
(tinyurl, updateDb) = self._getTinyUrl(url, channel)
except sqlite.OperationalError:
irc.error('The database just decided to crap itself.')
return
if tinyurl is None:
self.log.warning('tinyurl was None for url %r', url)
return
@ -236,9 +240,12 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
def _getTinyUrl(self, url, channel, cmd=False):
db = self.getDb(channel)
cursor = db.cursor()
try:
cursor.execute("""SELECT tinyurls.tinyurl FROM urls, tinyurls
WHERE urls.url=%s AND
tinyurls.url_id=urls.id""", url)
except sqlite.OperationalError:
raise
if cursor.rowcount == 0:
updateDb = True
try:
@ -299,8 +306,12 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
r = self.registryValue('nonSnarfingRegexp', channel)
if snarf and len(url) >= minlen and not r.search(url):
return
try:
(tinyurl, updateDb) = self._getTinyUrl(url, channel, cmd=True)
if tinyurl:
except sqlite.OperationalError:
irc.error('The database just decided to crap itself.')
return
if tinyurl is not None:
if updateDb:
self._updateTinyDb(url, tinyurl, channel)
irc.reply(tinyurl)