Index: branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py
===================================================================
--- branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py	(revision 35043)
+++ branches/eam_branches/ipp-20121219/ippToPsps/jython/detectionbatch.py	(revision 35044)
@@ -231,9 +231,12 @@
         tableName = "ImageMeta_" + ota
         
+        # XXX we drop the table above so it is not left behind on failure
         # drop then re-create table
-        self.scratchDb.dropTable(tableName)
+        # self.scratchDb.dropTable(tableName)
         sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
         try: self.scratchDb.execute(sql)
         except: pass
+        if (ota[0:2] == "XY"): ccdID = ota[2:4]
+        else: ccdID = 0
 
         # insert image metadata into table
@@ -302,5 +305,5 @@
                ) VALUES ( \
                " + str(self.expID) + " \
-               ," + ota[2:4] + " \
+               ," + str(ccdID) + " \
                ," + str(self.bias) + " \
                ," + str(self.biasScat) + " \
@@ -602,4 +605,10 @@
     def alterPspsTablesChip(self, chipname, extname, x, y):
 
+        # drop the ImageMeta_ table first, or we can leave an invalid table behind
+        tableName = "ImageMeta_" + chipname
+        
+        # drop then re-create table
+        self.scratchDb.dropTable(tableName)
+
         # load corresponding header into memory
         header = self.fits.findAndReadHeader(extname)
@@ -714,4 +723,8 @@
     '''
     def populatePspsTablesChip(self, chipname, x, y, results, tables):
+        # XXX EAM NOTE: drop tables (Detection_, SkinnyObject_, DetectionCalib_, Detection_) here so
+        # they do not polute the db?
+        # XXX or put an explicit drop at the end of the loop?
+
         #self.logger.infoTitle("Processing " + chipname)
         # this is a bit crude: if the chip is not present, this test will fail and the chip 
