From a9eb3120b614eee4f8d11cc4def8869bbe0b9658 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 28 May 2012 14:02:01 +0200 Subject: [PATCH] Skip attachment if an error is encountered during database insertion --- parse | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/parse b/parse index 4f5b4f2..c364bdb 100755 --- a/parse +++ b/parse @@ -196,10 +196,13 @@ for email_file in file_list: if len(cursor.fetchall()) > 0: print "Skipping attachment %s, already exists in the database." % attachment[2] continue - - new_row = (sha1_hash, attachment[0], attachment[1], attachment[2], attachment[3]) - cursor.execute("INSERT INTO attachments VALUES (?, ?, ?, ?, ?)", new_row) - inserted += 1 + + try: + new_row = (sha1_hash, attachment[0], attachment[1], attachment[2], attachment[3]) + cursor.execute("INSERT INTO attachments VALUES (?, ?, ?, ?, ?)", new_row) + inserted += 1 + except sqlite3.ProgrammingError: + print "Inserting of attachment %s failed." % attachment[2] if inserted > 0: print "Successfully inserted %d attachment(s) for %s." % (inserted, sha1_hash)