Index: trunk/ippTools/src/p2insertPendingFrames.c
===================================================================
--- trunk/ippTools/src/p2insertPendingFrames.c	(revision 6032)
+++ trunk/ippTools/src/p2insertPendingFrames.c	(revision 6060)
@@ -1,2 +1,3 @@
+#include <metadatadb.h>
 # include "p2search.h"
 
@@ -4,5 +5,5 @@
 // NOTE this function converts the rawFrames to pendingFrames AND inserts them
 //      this is useful since the table must be locked the whole time, to get the versions
-bool p2insertPendingFrames (p2SearchConfig *config, psArray *rawFrames) {
+bool p2insertPendingFrames (p2Config *config, psArray *rawFrames) {
 
     psMetadata *where = psMetadataAlloc ();
@@ -12,46 +13,48 @@
 
 	// find the next available version numbers
-	psMetadataAddStr (where, PS_LIST_TAIL, "EXP_ID", PS_META_REPLACE, "==", rawFrame->exposure->expID);
-	psArray *exposures = p2PendingExposureSelectRows (config->database, where, MAX_ROWS);
+	psMetadataAddStr (where, PS_LIST_TAIL, "EXP_ID", PS_META_REPLACE, "==", rawFrame->exposure->exp_id);
+	psArray *exposures = p2PendingExpSelectRowObjects(config->database, where, MAX_ROWS);
 	int version = -1;
 	for (int j = 0; j < exposures->n; j++) {
-	    p2PendingExposure *exposure = exposures->data[j];
-	    version = PS_MAX (version, exposure->P2version);
+	    p2PendingExpRow *exposure = exposures->data[j];
+	    version = PS_MAX (version, exposure->p2_version);
 	}
 	version ++;
 
-	p2PendingExposureRow *pendingExposure = p2PendingExposureAlloc ();
-	strcpy (pendingExposure->expID, rawFrame->exposure->expID);
-	pendingExposure->class = rawFrame->exposure->class;
-	pendingExposure->Nclass = rawFrame->exposure->Nclass;
-	pendingExposure->Ndone = 0;
-	pendingExposure->P1version = 0xff;
-	pendingExposure->P2version = version;
-	pendingExposure->state = P2_STATE_PENDING;
+	p2PendingExpRow *pendingExposure = p2PendingExpRowAlloc(
+        rawFrame->exposure->exp_id,
+        rawFrame->exposure->class,
+        rawFrame->exposure->nclass,
+        0xff,
+        version
+        // pendingExposure->Ndone = 0;
+        // pendingExposure->state = P2_STATE_PENDING;
+    );
 
 	psArray *pendingImages = psArrayAlloc (rawFrame->images->n);
 	pendingImages->n = 0;
 	for (int j = 0; j < rawFrame->images->n; j++) {
-	    ppRawImage *rawImage = rawFrame->images->data[j];
-	    p2PendingImage *pendingImage = p2PendingImageAlloc ();
-
-	    strcpy (pendingImage->expID, rawImage->expID);
-	    pendingImage->P2version = version;
-	    pendingImage->class = rawImage->class;
-	    strcpy (pendingImage->classID, rawImage->classID);
-
-	    // XXX cleanup the url somehow
-	    strcpy (pendingImage->urlroot = rawImage->url);
-	    strcpy (pendingImage->input, "raw.fits");
-	    strcpy (pendingImage->output, "flt.fits");
-	    strcpy (pendingImage->log, "log");
-	    strcpy (pendingImage->smf, "smf");
-	    pendingImage->state = P2_STATE_PENDING;
+	    rawImfileRow *rawImage = rawFrame->images->data[j];
+	    p2PendingImfileRow *pendingImage = p2PendingImfileRowAlloc(
+	        rawImage->exp_id,
+	        rawImage->class,
+	        rawImage->class_id,
+	        version, // p1
+	        version, // p2
+            "",
+            "",
+	        // XXX cleanup the url somehow
+	        rawImage->url
+        );
 
 	    psArrayAdd (pendingImages, 100, pendingImage);
 	}
 	
-	p2PendingExposureInsertObject (config->database, pendingExposure);
-	p2PendingImageInsertObjects (config->database, pendingImages);
+	p2PendingExpInsertObject (config->database, pendingExposure);
+
+    for (int i = 0; i < pendingImages->n; i++) {
+	    p2PendingImfileInsertObject(config->database, pendingImages->data[i]);
+    }
+
     }
     return true;
