Index: trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 35770)
+++ trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 35777)
@@ -233,4 +233,5 @@
 
   int status = TRUE;
+  int Ninsert = 0;
 
   gettimeofday (&start, (void *) NULL);
@@ -239,4 +240,5 @@
     // XXX check return status
     insert_detections_mysql_detvalue (&buffer, &detections[i]);
+    Ninsert ++;
     if (buffer.Nbuffer > MAX_BUFFER) {
       if (!insert_detections_mysql_commit (&buffer, mysql)) {
@@ -247,9 +249,13 @@
       bzero (buffer.buffer, buffer.Nalloc);
       insert_detections_mysql_init (&buffer);
-    }
-  }
-  if (!insert_detections_mysql_commit (&buffer, mysql)) {
-    fprintf (stderr, "failure to insert detections in mysql (commit 2)\n");
-    status = FALSE;
+      Ninsert = 0;
+    }
+  }
+  if (Ninsert > 0) {
+    // insert the remaining detections loaded in the buffer
+    if (!insert_detections_mysql_commit (&buffer, mysql)) {
+      fprintf (stderr, "failure to insert detections in mysql (commit 2)\n");
+      status = FALSE;
+    }
   }
   FreeIOBuffer (&buffer);
Index: trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 35770)
+++ trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 35777)
@@ -104,4 +104,5 @@
   insert_detections_mysql_init (&buffer);
   int Ninsert = 0;
+  int Ntotal = 0;
 
   int status = TRUE;
@@ -125,4 +126,6 @@
 	status = FALSE;
       }
+      Ninsert ++;
+      Ntotal ++;
 
       if (buffer.Nbuffer > MAX_BUFFER) {
@@ -141,15 +144,16 @@
 	insert_detections_mysql_init (&buffer);
       }
-
-      Ninsert ++;
       found ++;
     }
   }
-  if (!insert_detections_mysql_commit (&buffer, mysql)) {
-    fprintf (stderr, "failure to insert detections in mysql (commit)\n");
-    status = FALSE;
+  if (Ninsert > 0) {
+    // insert the remaining detections loaded in the buffer
+    if (!insert_detections_mysql_commit (&buffer, mysql)) {
+      fprintf (stderr, "failure to insert detections in mysql (commit)\n");
+      status = FALSE;
+    }
   }
   
-  if (VERBOSE) fprintf (stderr, "inserted %d rows\n", Ninsert);
+  if (VERBOSE) fprintf (stderr, "inserted %d rows\n", Ntotal);
   FreeIOBuffer (&buffer);
 
@@ -169,5 +173,6 @@
   }
 
-  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
+  // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
+  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
 
   return TRUE;
@@ -188,5 +193,5 @@
   // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
   PrintIOBuffer (buffer, "%lu, ", average->extID);	  // objID
-  PrintIOBuffer (buffer, "%d, ", measure->photcode);	  // photcode
+  // XXX PrintIOBuffer (buffer, "%d, ", measure->photcode);	  // photcode
   PrintIOBuffer (buffer, "%u, ", measure->dbFlags);	  // flags
 
@@ -221,4 +226,6 @@
   } else {
     fprintf (stderr, "invalid sql?\n");
+    int Nstart = MAX(0, buffer->Nbuffer - 3000);
+    fprintf (stderr, "buffer: ...%s...\n", &buffer->buffer[Nstart]);
     return FALSE;
   }
