From 5bc0ef7ffee28cf573918a12d28f3df8f8d9c1bf Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Fri, 6 Feb 2009 01:34:01 -0700
Subject: [PATCH] backupdb.py: catch OperationalError on duplicate-insert too,
 since pysqlite2 on dapper raises it instead of IntegrityError

---
 src/allmydata/scripts/backupdb.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/allmydata/scripts/backupdb.py b/src/allmydata/scripts/backupdb.py
index 02cf7eb6..51fbda7d 100644
--- a/src/allmydata/scripts/backupdb.py
+++ b/src/allmydata/scripts/backupdb.py
@@ -208,7 +208,9 @@ class BackupDB_v1:
         c = self.cursor
         try:
             c.execute("INSERT INTO caps (filecap) VALUES (?)", (filecap,))
-        except self.sqlite_module.IntegrityError:
+        except (self.sqlite_module.IntegrityError, self.sqlite_module.OperationalError):
+            # sqlite3 on sid gives IntegrityError
+            # pysqlite2 on dapper gives OperationalError
             pass
         c.execute("SELECT fileid FROM caps WHERE filecap=?", (filecap,))
         foundrow = c.fetchone()
@@ -222,7 +224,7 @@ class BackupDB_v1:
         try:
             self.cursor.execute("INSERT INTO last_upload VALUES (?,?,?)",
                                 (fileid, now, now))
-        except self.sqlite_module.IntegrityError:
+        except (self.sqlite_module.IntegrityError, self.sqlite_module.OperationalError):
             self.cursor.execute("UPDATE last_upload"
                                 " SET last_uploaded=?, last_checked=?"
                                 " WHERE fileid=?",
@@ -230,7 +232,7 @@ class BackupDB_v1:
         try:
             self.cursor.execute("INSERT INTO local_files VALUES (?,?,?,?,?)",
                                 (path, size, mtime, ctime, fileid))
-        except self.sqlite_module.IntegrityError:
+        except (self.sqlite_module.IntegrityError, self.sqlite_module.OperationalError):
             self.cursor.execute("UPDATE local_files"
                                 " SET size=?, mtime=?, ctime=?, fileid=?"
                                 " WHERE path=?",
-- 
2.45.2