Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 38763)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 38837)
@@ -914,12 +914,27 @@
 
     '''
+    Returns boolean value for this column in clients table
+    '''
+    def existsClient(self, host, pid):
+
+        sql = "SELECT id FROM clients WHERE host = '" + host + "' AND pid = " + str(pid) + " LIMIT 1"
+
+        try:
+            rs = self.executeQuery(sql)
+            if rs.first() is False: return False
+        except:
+            self.logger.exception("Unable to check if " + host + "-" + str(pid) + " is in clients table")
+
+        return True
+
+    '''
     Update clients, or inserts it for the first time
     '''
     def updateClient(self, type, host, pid):
 
-        try:
+        if self.existsClient(host, pid):
+            self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid))
+        else:
             self.insertClient(type, host, pid)
-        except:
-            self.execute("UPDATE clients SET timestamp = now() WHERE host = '" + host + "' AND pid = " + str(pid))
 
     '''
@@ -1337,15 +1352,11 @@
 
         for id in ids:
-            sql = "INSERT IGNORE INTO pending \
+            # why is there an IGNORE here? we have deleted old versions already above
+            sql = "INSERT INTO pending \
                (box_id, batch_type, stage_id) \
                VALUES \
                (" + str(box_id) + ", '" + batchType + "', " + str(id) + ")"
 
-            print sql
-            try: self.execute(sql)
-            except:
-                print "failed to insert into pending"
-                print "sql: " + sql
-                raise
+            self.execute(sql)
 
     '''
@@ -1656,12 +1667,8 @@
     def storeAllItems(self, rows):
 
-        try:
-            self.execute("DROP TABLE all_pending")
-        except:
-            pass
+        self.dropTable("all_pending")
 
         self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
         for row in rows:
-
             try:
                 sql = "INSERT INTO all_pending (stage_id, ra_bore, dec_bore) \
@@ -1678,9 +1685,4 @@
     '''
     def storeAllItemsInDvodb(self, rows, dvo_db, batchType):
-
-        #try:
-        #    self.execute("DROP TABLE all_pending")
-        #except:
-        #    pass
 
         #self.execute("CREATE TEMPORARY TABLE all_pending (stage_id bigint(20), ra_bore float, dec_bore float)")
@@ -1699,6 +1701,4 @@
         #self.logger.infoPair("Items written to Db", "%d" % count)
 
-
-
     '''
     Gets all items in the all_pending temporary table within the bounds of this box
