Index: trunk/ippTools/src/magictool.c
===================================================================
--- trunk/ippTools/src/magictool.c	(revision 18523)
+++ trunk/ippTools/src/magictool.c	(revision 18524)
@@ -40,4 +40,5 @@
 static bool toprocessMode(pxConfig *config);
 static bool addresultMode(pxConfig *config);
+static bool nodeMode(pxConfig *config);
 static bool tomaskMode(pxConfig *config);
 static bool addmaskMode(pxConfig *config);
@@ -73,4 +74,5 @@
         MODECASE(MAGICTOOL_MODE_TOPROCESS,      toprocessMode);
         MODECASE(MAGICTOOL_MODE_ADDRESULT,      addresultMode);
+        MODECASE(MAGICTOOL_MODE_NODE,           nodeMode);
         MODECASE(MAGICTOOL_MODE_TOMASK,         tomaskMode);
         MODECASE(MAGICTOOL_MODE_ADDMASK,        addmaskMode);
@@ -393,5 +395,5 @@
     }
     if (!psArrayLength(output)) {
-        psTrace("warptool", PS_LOG_INFO, "no rows found");
+        psTrace("magictool", PS_LOG_INFO, "no rows found");
         psFree(output);
         return true;
@@ -520,5 +522,7 @@
         psMetadataRemoveKey(work, "dep");
         psMetadataRemoveKey(work, "done");
+#if 0
         psMetadataRemoveKey(work, "uri");
+#endif
         pxNode *child = NULL;
         while ((child = psListGetAndIncrement(iter))) {
@@ -538,5 +542,5 @@
                 return true;
             }
-
+#if 0
             char *uri = psMetadataLookupStr(&status, data, "uri");
             if (!status) {
@@ -545,5 +549,5 @@
 
             psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri);
-
+#endif
         }
         psFree(iter);
@@ -634,5 +638,5 @@
 
     psArray *magicTree = p_psDBFetchResult(config->dbh);
-    if (!output) {
+    if (!magicTree) {
         psErrorCode err = psErrorCodeLast();
         switch (err) {
@@ -725,6 +729,5 @@
 }
 
-
-static bool tomaskMode(pxConfig *config)
+static bool nodeMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -733,9 +736,14 @@
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
-    // look for "inputs" that need to processed
-    psString query = pxDataGet("magictool_tomask.sql");
+    psString query = pxDataGet("magictool_node.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
         return false;
+    }
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
     }
 
@@ -776,4 +784,67 @@
     if (psArrayLength(output)) {
         // negative simple so the default is true
+        if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
+static bool tomaskMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
+    // look for "inputs" that need to processed
+    psString query = pxDataGet("magictool_tomask.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        psErrorCode err = psErrorCodeLast();
+        switch (err) {
+            case PS_ERR_DB_CLIENT:
+                psError(PXTOOLS_ERR_SYS, false, "database error");
+            case PS_ERR_DB_SERVER:
+                psError(PXTOOLS_ERR_PROG, false, "database error");
+            default:
+                psError(PXTOOLS_ERR_PROG, false, "unknown error");
+        }
+
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("magictool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (psArrayLength(output)) {
+        // negative simple so the default is true
         if (!ippdbPrintMetadatas(stdout, output, "toprocess", !simple)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print array");
