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
1 changed files with 17 additions and 6 deletions

View File

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