Index: /trunk/ippTools/share/Makefile.am
===================================================================
--- /trunk/ippTools/share/Makefile.am	(revision 12188)
+++ /trunk/ippTools/share/Makefile.am	(revision 12189)
@@ -1,3 +1,6 @@
 dist_pkgdata_DATA = \
+	camtool_find_pendingexp.sql \
+	camtool_find_pendingimfile.sql \
+	camtool_find_processedexp.sql \
 	camtool_queue_chip_id.sql \
 	chiptool_completely_processed_exp.sql \
Index: /trunk/ippTools/share/camtool_find_pendingexp.sql
===================================================================
--- /trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 12189)
+++ /trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 12189)
@@ -0,0 +1,19 @@
+-- this query is used by both camtool -pendingexp & camtool -addprocessedexp it
+-- does a little more work then is necessary for -addprocessed but it seems
+-- "cleaner" to use the same query for both cases 
+SELECT
+    camPendingExp.*,
+    rawExp.camera,
+    rawExp.workdir
+FROM camPendingExp
+JOIN chipProcessedExp
+    USING(chip_id)
+JOIN rawExp
+    ON chipProcessedExp.exp_tag = rawExp.exp_tag
+LEFT JOIN camProcessedExp
+    ON camPendingExp.cam_id = camPendingExp.cam_id
+LEFT JOIN camMask
+    ON camPendingExp.label = camMask.label
+WHERE
+    camProcessedExp.cam_id IS NULL
+    AND camMask.label IS NULL
Index: /trunk/ippTools/share/camtool_find_pendingimfile.sql
===================================================================
--- /trunk/ippTools/share/camtool_find_pendingimfile.sql	(revision 12189)
+++ /trunk/ippTools/share/camtool_find_pendingimfile.sql	(revision 12189)
@@ -0,0 +1,19 @@
+SELECT
+    camPendingExp.cam_id,
+    chipProcessedImfile.*,
+    rawExp.camera,
+    rawExp.workdir
+FROM camPendingExp
+JOIN chipProcessedExp
+    USING(chip_id)
+JOIN chipProcessedImfile
+    USING(chip_id)
+JOIN rawExp
+    ON chipProcessedExp.exp_tag = rawExp.exp_tag
+LEFT JOIN camProcessedExp
+    ON camPendingExp.cam_id = camProcessedExp.cam_id
+LEFT JOIN camMask
+    ON camPendingExp.label = camMask.label
+WHERE
+    camProcessedExp.cam_id IS NULL
+    AND camMask.label IS NULL
Index: /trunk/ippTools/share/camtool_find_processedexp.sql
===================================================================
--- /trunk/ippTools/share/camtool_find_processedexp.sql	(revision 12189)
+++ /trunk/ippTools/share/camtool_find_processedexp.sql	(revision 12189)
@@ -0,0 +1,11 @@
+SELECT
+    camProcessedExp.*,
+    rawExp.camera,
+    rawExp.workdir
+FROM camProcessedExp
+JOIN chipProcessedExp
+    USING(chip_id)
+JOIN rawExp
+    chipProcessedExp.exp_tag = rawExp.exp_tag
+WHERE -- bogus condition so there is a pre-existing where to append to
+    camProcessedExp.cam_id IS NOT NULL
Index: /trunk/ippTools/src/camtool.c
===================================================================
--- /trunk/ippTools/src/camtool.c	(revision 12188)
+++ /trunk/ippTools/src/camtool.c	(revision 12189)
@@ -94,22 +94,9 @@
     }
 
-    psString query = psStringCopy(
-            "SELECT"
-            "   camPendingExp.*,"
-            "   rawExp.camera,"
-            "   rawExp.workdir"
-            " FROM camPendingExp"
-            " JOIN chipProcessedExp"
-            "   USING(chip_id)"
-            " JOIN rawExp"
-            "   ON chipProcessedExp.exp_tag = rawExp.exp_tag"
-            " LEFT JOIN camProcessedExp"
-            "   on camPendingExp.cam_id = camPendingExp.cam_id"
-            " LEFT JOIN camMask"
-            "   ON camPendingExp.label = camMask.label"
-            " WHERE"
-            "   camProcessedExp.cam_id IS NULL"
-            "   AND camMask.label IS NULL"
-    );
+    psString query = pxDataGet("camtool_find_pendingexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
 
     if (config->where) {
@@ -176,25 +163,9 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psString query = psStringCopy(
-            "SELECT"
-            "   camPendingExp.cam_id,"
-            "   chipProcessedImfile.*,"
-            "   rawExp.camera,"
-            "   rawExp.workdir"
-            " FROM camPendingExp"
-            " JOIN chipProcessedExp"
-            "   USING(chip_id)"
-            " JOIN chipProcessedImfile"
-            "   USING(chip_id)"
-            " JOIN rawExp"
-            "   ON chipProcessedExp.exp_tag = rawExp.exp_tag"
-            " LEFT JOIN camProcessedExp"
-            "   ON camPendingExp.cam_id = camProcessedExp.cam_id"
-            " LEFT JOIN camMask"
-            "   ON camPendingExp.label = camMask.label"
-            " WHERE"
-            "   camProcessedExp.cam_id IS NULL"
-            "   AND camMask.label IS NULL"
-    );
+    psString query = pxDataGet("camtool_find_pendingimfile.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
 
     if (config->where) {
@@ -238,22 +209,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) {
@@ -375,13 +328,9 @@
     }
 
-    psString query = psStringCopy(
-        "SELECT camPendingExp.*"
-        " FROM camPendingExp"
-        " LEFT JOIN camProcessedExp"
-        "   USING(cam_id)"
-        " WHERE"
-        "   camProcessedExp.cam_id IS NULL"
-        "   AND camPendingExp.cam_id = '%s'"
-    );
+    psString query = pxDataGet("camtool_find_pendingexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
 
     if (!p_psDBRunQuery(config->dbh, query, cam_id)) {
@@ -487,17 +436,9 @@
     }
 
-    psString query = psStringCopy(
-            "SELECT"
-            "   camProcessedExp.*,"
-            "   rawExp.camera,"
-            "   rawExp.workdir"
-            " FROM camProcessedExp"
-            " JOIN chipProcessedExp"
-            "   USING(chip_id)"
-            " JOIN rawExp"
-            "   chipProcessedExp.exp_tag = rawExp.exp_tag"
-            " WHERE"
-            "   camProcessedExp.cam_id IS NOT NULL" // bongus
-    );
+    psString query = pxDataGet("camtool_find_processedexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
 
     if (config->where) {
@@ -556,22 +497,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "camProcessedExp", !simple)) {
