Index: /trunk/ippToPsps/jython/dvoToMySQL.py
===================================================================
--- /trunk/ippToPsps/jython/dvoToMySQL.py	(revision 31971)
+++ /trunk/ippToPsps/jython/dvoToMySQL.py	(revision 31972)
@@ -27,5 +27,5 @@
 
     '''
-    def __init__(self, logger):
+    def __init__(self, logger, RESETTABLES):
 
         # set up logging
@@ -49,5 +49,5 @@
 
         # create DVO tables
-        #self.scratchDb.createDvoTables()
+        if RESETTABLES: self.scratchDb.resetDvoToMysqlTables()
 
         # import Images.dat table
@@ -102,4 +102,5 @@
                         file + ".cpm", 
                         "IMAGE_ID DET_ID OBJ_ID CAT_ID EXT_ID DB_FLAGS")
+                self.scratchDb.createIndex(cpmTableName, "IMAGE_ID")
                 self.scratchDb.createIndex(cpmTableName, "CAT_ID")
                 self.scratchDb.createIndex(cpmTableName, "OBJ_ID")
@@ -110,4 +111,5 @@
                         file + ".cpt", 
                         "OBJ_ID CAT_ID EXT_ID")
+                self.scratchDb.createIndex(cptTableName, "IMAGE_ID")
                 self.scratchDb.createIndex(cptTableName, "CAT_ID")
                 self.scratchDb.createIndex(cptTableName, "OBJ_ID")
@@ -132,4 +134,8 @@
                 self.scratchDb.execute(sql)
 
+                # NB we use an INSERT IGNORE here. This is because of a known issue where multiple DVO cpm
+                # files can include the same detection, with the same IMAGE_ID/DET_ID pairing, but different
+                # PSPS object IDs assigned in the corresponding cpt file. This is believed to be a chip-boundary 
+                # issue within DVO. So, for now, we take the first IMAGE_ID/DET_ID detection we find, and ignore the rest
                 self.logger.infoPair("Populating", self.dvoDetectionTable)
                 sql = "INSERT IGNORE INTO dvoDetectionFull (\
@@ -150,5 +156,9 @@
                        ,DB_FLAGS \
                        FROM " + cpmTableName
-                self.scratchDb.execute(sql)
+                try:
+                    self.scratchDb.execute(sql)
+                except:
+                    self.logger.error("FAILED: " + sql)
+                    return 
 
                 # now drop what we don't need
@@ -213,6 +223,11 @@
 logger.setLevel(logging.INFO)
 
-
-dvoToMySql = DvoToMySql(logger)
+RESETTABLES = 0
+
+if len(sys.argv) > 1 and sys.argv[1] == "reset": 
+    response = raw_input("* Are you ABSOLUTELY sure you want to recreate the DVO tables (y/n)? ")
+    if response == "y": RESETTABLES = 1
+
+dvoToMySql = DvoToMySql(logger, RESETTABLES)
 
 logger.infoPair("Program...", "complete")
