Index: trunk/ippTools/src/magicdstool.c
===================================================================
--- trunk/ippTools/src/magicdstool.c	(revision 26495)
+++ trunk/ippTools/src/magicdstool.c	(revision 26567)
@@ -44,5 +44,5 @@
 static bool tocleanupMode(pxConfig *config);
 
-static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psMetadata *where, const char *state);
+static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state);
 
 # define MODECASE(caseName, func) \
@@ -326,8 +326,15 @@
     PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
 
+    // optional
+    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
+    psString setString = NULL;
+    if (set_label) {
+        psStringAppend(&setString, ", label = '%s'", set_label);
+    } 
+
     PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", false, false);
     if (magic_ds_id) {
 
-        return setmagicDSRunState(config, magic_ds_id, NULL, state);
+        return setmagicDSRunState(config, magic_ds_id, setString, NULL, state);
 
     } else if (!strcmp(state, "full")) {
@@ -336,4 +343,5 @@
     }
     // we can transition by query as well
+
 
     psMetadata *where = psMetadataAlloc();
@@ -342,5 +350,4 @@
     PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
 
-
     if (psListLength(where->list) < 2) {
         psError(PS_ERR_UNKNOWN, true, "at least 2 search arguments are required");
@@ -353,5 +360,5 @@
         psMetadataAddS32(where, PS_LIST_TAIL, "re_place", 0, ">", 0);
     }
-    bool result = setmagicDSRunState(config, magic_ds_id, where, state);
+    bool result = setmagicDSRunState(config, magic_ds_id, setString, where, state);
     psFree(where);
 
@@ -445,5 +452,5 @@
 {
     // first query the magicDSRun to find the stage and the stage_id
-    psString query = "SELECT stage, stage_id from magicDSRun where magic_ds_id = %" PRId64;
+    psString query = "SELECT stage, stage_id, magic_id from magicDSRun where magic_ds_id = %" PRId64;
 
     if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) {
@@ -472,4 +479,5 @@
     psString stage= psMetadataLookupStr(NULL, row, "stage");
     psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id");
+    psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id");
 
     ippStage stageNum = ippStringToStage(stage);
@@ -499,5 +507,5 @@
     }
 
-    if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id, component)) {
+    if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id, component)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -518,5 +526,5 @@
 {
     // first query the magicDSRun to find the stage and the stage_id
-    psString query = "SELECT stage, stage_id from magicDSRun where magic_ds_id = %" PRId64;
+    psString query = "SELECT stage, stage_id, magic_id from magicDSRun where magic_ds_id = %" PRId64;
 
     if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) {
@@ -545,4 +553,5 @@
     psString stage = psMetadataLookupStr(NULL, row, "stage");
     psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id");
+    psS64 magic_id = psMetadataLookupS64(NULL, row, "magic_id");
 
     ippStage stageNum = ippStringToStage(stage);
@@ -570,5 +579,5 @@
         return false;
     }
-    if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id)) {
+    if (!p_psDBRunQueryF(config->dbh, query, magic_id, stage_id)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -710,5 +719,5 @@
 
         // set magicDSRun.state to 'full'
-        if (!setmagicDSRunState(config, magic_ds_id, NULL, "full")) {
+        if (!setmagicDSRunState(config, magic_ds_id, NULL, NULL, "full")) {
             psError(PS_ERR_UNKNOWN, false, "failed to change magicDSRun.state for magic_ds_id: %" PRId64,
                 magic_ds_id);
@@ -927,5 +936,5 @@
 }
 
-static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, psMetadata *where, const char *state)
+static bool setmagicDSRunState(pxConfig *config, psS64 magic_ds_id, psString extraSetStr, psMetadata *where, const char *state)
 {
     PS_ASSERT_PTR_NON_NULL(state, false);
@@ -937,5 +946,6 @@
     }
 
-    psString query = psStringCopy("UPDATE magicDSRun SET state = '%s'");
+    psString query = NULL;
+    psStringAppend(&query, "UPDATE magicDSRun SET state = '%s' %s\n", state, extraSetStr ? extraSetStr : "");
     if (magic_ds_id) {
         psStringAppend(&query, " WHERE magic_ds_id = %" PRId64, magic_ds_id);
@@ -949,5 +959,5 @@
     }
 
-    if (!p_psDBRunQueryF(config->dbh, query, state)) {
+    if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false,
                 "failed to change state for magic_id %" PRId64, magic_ds_id);
