IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 24, 2009, 2:24:35 PM (17 years ago)
Author:
bills
Message:

adapt to new multiple label processing
properly implement -limit in -toprocess mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magictool.c

    r23688 r23970  
    457457    psMetadata *where = psMetadataAlloc();
    458458    PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "==");
    459     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     459    pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
    460460
    461461    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    739739    psMetadata *where = psMetadataAlloc();
    740740    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    741     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     741    pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
    742742
    743743    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     744    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    744745
    745746    // look for "inputs" that need to processed
     
    750751    }
    751752
    752     psString whereClause = NULL;
     753    psString whereString = NULL;
    753754    if (psListLength(where->list)) {
    754         whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    755         psStringAppend(&query, " AND %s", whereClause);
     755        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     756        psStringAppend(&whereString, "\nAND %s", whereClause);
     757        psFree(whereClause);
    756758    }
    757759    psFree(where);
    758760
    759     if (!p_psDBRunQuery(config->dbh, query)) {
    760         psError(PS_ERR_UNKNOWN, false, "database error");
     761    // treat limit == 0 as "no limit"
     762    if (limit) {
     763        psString limitString = psDBGenerateLimitSQL(limit);
     764        psStringAppend(&query, " %s", limitString);
     765        psFree(limitString);
     766    }
     767
     768    if (!p_psDBRunQueryF(config->dbh, query, whereString, whereString)) {
     769        psError(PS_ERR_UNKNOWN, false, "database error");
     770        psFree(whereString);
    761771        psFree(query);
    762772        return false;
     
    782792    }
    783793
     794    if (limit) {
     795        if (psArrayLength(output) >= limit) {
     796            // we've found enough (not that limit was applied to the query so '> limit' won't happen)
     797            // negative simple so the default is true
     798            if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) {
     799                psError(PS_ERR_UNKNOWN, false, "failed to print array");
     800                psFree(output);
     801                return false;
     802            }
     803            psFree(output);
     804            return true;
     805        }
     806    }
     807
    784808    // look for tree nodes that need to be processed
     809    // XXX: This gets all nodes from all magicRuns that are in 'new'state
     810    // That doens't seem particularly efficient
    785811    query = pxDataGet("magictool_toprocess_tree.sql");
    786812    if (!query) {
     
    789815    }
    790816
    791     if (whereClause) {
    792         psString new  = NULL;
    793         psStringAppend(&new, "\n AND %s", whereClause);
    794         psFree(whereClause);
    795         whereClause = new;
    796     }
    797     if (!p_psDBRunQueryF(config->dbh, query, whereClause ? whereClause :  "")) {
    798         psError(PS_ERR_UNKNOWN, false, "database error");
    799         psFree(whereClause);
     817
     818    if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString :  "")) {
     819        psError(PS_ERR_UNKNOWN, false, "database error");
     820        psFree(whereString);
    800821        psFree(query);
    801822        return false;
    802823    }
    803     psFree(whereClause);
     824    psFree(whereString);
    804825    psFree(query);
    805826
     
    828849    while (index <  psArrayLength(magicTree)) {
    829850        bool status;
     851        if (limit && (psArrayLength(output) >= limit)) {
     852            break;
     853        }
    830854        psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id");
    831855        if (!status) {
     
    879903
    880904    }
     905    psFree(magicTree);
    881906
    882907    if (psArrayLength(output)) {
     908        if (limit && (limit < psArrayLength(output))) {
     909            // truncate the array
     910            long arrayLength = psArrayLength(output);
     911            for (long i = arrayLength - 1; i >= limit; i--) {
     912                psArrayRemoveIndex(output, i);
     913            }
     914        }
    883915        // negative simple so the default is true
    884916        if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) {
     
    889921    }
    890922
    891     psFree(magicTree);
    892923    psFree(output);
    893924
Note: See TracChangeset for help on using the changeset viewer.