IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2009, 2:00:56 PM (17 years ago)
Author:
eugene
Message:

merging changes from head

Location:
branches/eam_branches/20090522
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090522

  • branches/eam_branches/20090522/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3434disttool
        3535receivetool
         36
         37pubtool
  • branches/eam_branches/20090522/ippTools/src/magicdstool.c

    r23974 r24557  
    3838static bool revertdestreakedfileMode(pxConfig *config);
    3939static bool getskycellsMode(pxConfig *config);
     40static bool toremoveMode(pxConfig *config);
     41static bool torestoreMode(pxConfig *config);
    4042
    4143static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
     
    6870        MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode);
    6971        MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS,         getskycellsMode);
     72        MODECASE(MAGICDSTOOL_MODE_TOREMOVE,            toremoveMode);
     73        MODECASE(MAGICDSTOOL_MODE_TORESTORE,           torestoreMode);
    7074        default:
    7175            psAbort("invalid option (this should not happen)");
     
    501505    // chose the appropriate query based on the stage
    502506    if (!strcmp(stage, "raw")) {
    503         query = "UPDATE rawImfile SET magicked = 1 where exp_id = %" PRId64 " AND class_id = '%s'";
     507        query = "UPDATE rawImfile SET magicked = %" PRId64 " where exp_id = %" PRId64 " AND class_id = '%s'";
    504508    } else if (!strcmp(stage, "chip")) {
    505         query = "UPDATE chipProcessedImfile SET magicked = 1 where chip_id = %" PRId64 " AND class_id = '%s'";
     509        query = "UPDATE chipProcessedImfile SET magicked = %" PRId64 " where chip_id = %" PRId64 " AND class_id = '%s'";
    506510    } else if (!strcmp(stage, "warp")) {
    507         query = "UPDATE warpSkyfile SET magicked = 1 where warp_id = %" PRId64 " AND skycell_id = '%s'";
     511        query = "UPDATE warpSkyfile SET magicked = %" PRId64 " where warp_id = %" PRId64 " AND skycell_id = '%s'";
    508512    } else if (!strcmp(stage, "diff")) {
    509         query = "UPDATE diffSkyfile SET magicked = 1 where diff_id = %" PRId64 " AND skycell_id = '%s'";
     513        query = "UPDATE diffSkyfile SET magicked = %" PRId64 " where diff_id = %" PRId64 " AND skycell_id = '%s'";
    510514    } else {
    511515        psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage);
     
    513517        return false;
    514518    }
    515     if (!p_psDBRunQueryF(config->dbh, query, stage_id, component)) {
     519    if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id, component)) {
    516520        psError(PS_ERR_UNKNOWN, false, "database error");
    517521        return false;
     
    563567    // chose the appropriate query based on the stage
    564568    if (!strcmp(stage, "raw")) {
    565         query = "UPDATE rawExp SET magicked = 1 where exp_id = %" PRId64;
     569        query = "UPDATE rawExp SET magicked = %" PRId64 " where exp_id = %" PRId64;
    566570    } else if (!strcmp(stage, "chip")) {
    567         query = "UPDATE chipRun SET magicked = 1 where chip_id = %" PRId64;
     571        query = "UPDATE chipRun SET magicked = %" PRId64 " where chip_id = %" PRId64;
    568572    } else if (!strcmp(stage, "warp")) {
    569         query = "UPDATE warpRun SET magicked = 1 where warp_id = %" PRId64;
     573        query = "UPDATE warpRun SET magicked = %" PRId64 " where warp_id = %" PRId64;
    570574    } else if (!strcmp(stage, "diff")) {
    571         query = "UPDATE diffRun SET magicked = 1 where diff_id = %" PRId64;
     575        query = "UPDATE diffRun SET magicked = %" PRId64 " where diff_id = %" PRId64;
    572576    } else {
    573577        psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage);
     
    575579        return false;
    576580    }
    577     if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
     581    if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id)) {
    578582        psError(PS_ERR_UNKNOWN, false, "database error");
    579583        return false;
     
    625629    }
    626630
    627     if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault)) {
     631    if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault, "full")) {
    628632            // rollback
    629633        if (!psDBRollback(config->dbh)) {
     
    889893}
    890894
     895static bool toremoveMode(pxConfig *config)
     896{
     897    PS_ASSERT_PTR_NON_NULL(config, false);
     898
     899    psMetadata *where = psMetadataAlloc();
     900    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     901    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     902    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     903
     904    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     905    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     906
     907    // look for "inputs" that need to processed
     908    psString query = pxDataGet("magicdstool_toremove.sql");
     909    if (!query) {
     910        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     911        return false;
     912    }
     913
     914    if (psListLength(where->list)) {
     915        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     916        psStringAppend(&query, " WHERE %s", whereClause);
     917        psFree(whereClause);
     918    }
     919    psFree(where);
     920
     921    // treat limit == 0 as "no limit"
     922    if (limit) {
     923        psString limitString = psDBGenerateLimitSQL(limit);
     924        psStringAppend(&query, " %s", limitString);
     925        psFree(limitString);
     926    }
     927
     928    if (!p_psDBRunQuery(config->dbh, query)) {
     929        psError(PS_ERR_UNKNOWN, false, "database error");
     930        psFree(query);
     931        return false;
     932    }
     933    psFree(query);
     934
     935    psArray *output = p_psDBFetchResult(config->dbh);
     936    if (!output) {
     937        psErrorCode err = psErrorCodeLast();
     938        switch (err) {
     939            case PS_ERR_DB_CLIENT:
     940                psError(PXTOOLS_ERR_SYS, false, "database error");
     941            case PS_ERR_DB_SERVER:
     942                psError(PXTOOLS_ERR_PROG, false, "database error");
     943            default:
     944                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     945        }
     946
     947        return false;
     948    }
     949    if (!psArrayLength(output)) {
     950        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     951        psFree(output);
     952        return true;
     953    }
     954
     955    if (psArrayLength(output)) {
     956        // negative simple so the default is true
     957        if (!ippdbPrintMetadatas(stdout, output, "toremove", !simple)) {
     958            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     959            psFree(output);
     960            return false;
     961        }
     962    }
     963
     964    psFree(output);
     965
     966    return true;
     967}
     968static bool torestoreMode(pxConfig *config)
     969{
     970    PS_ASSERT_PTR_NON_NULL(config, false);
     971
     972    psMetadata *where = psMetadataAlloc();
     973    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     974    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     975    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     976
     977    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     978    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     979
     980    // look for "inputs" that need to processed
     981    psString query = pxDataGet("magicdstool_torestore.sql");
     982    if (!query) {
     983        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     984        return false;
     985    }
     986
     987    if (psListLength(where->list)) {
     988        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     989        psStringAppend(&query, " WHERE %s", whereClause);
     990        psFree(whereClause);
     991    }
     992    psFree(where);
     993
     994    // treat limit == 0 as "no limit"
     995    if (limit) {
     996        psString limitString = psDBGenerateLimitSQL(limit);
     997        psStringAppend(&query, " %s", limitString);
     998        psFree(limitString);
     999    }
     1000
     1001    if (!p_psDBRunQuery(config->dbh, query)) {
     1002        psError(PS_ERR_UNKNOWN, false, "database error");
     1003        psFree(query);
     1004        return false;
     1005    }
     1006    psFree(query);
     1007
     1008    psArray *output = p_psDBFetchResult(config->dbh);
     1009    if (!output) {
     1010        psErrorCode err = psErrorCodeLast();
     1011        switch (err) {
     1012            case PS_ERR_DB_CLIENT:
     1013                psError(PXTOOLS_ERR_SYS, false, "database error");
     1014            case PS_ERR_DB_SERVER:
     1015                psError(PXTOOLS_ERR_PROG, false, "database error");
     1016            default:
     1017                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1018        }
     1019
     1020        return false;
     1021    }
     1022    if (!psArrayLength(output)) {
     1023        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1024        psFree(output);
     1025        return true;
     1026    }
     1027
     1028    if (psArrayLength(output)) {
     1029        // negative simple so the default is true
     1030        if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) {
     1031            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1032            psFree(output);
     1033            return false;
     1034        }
     1035    }
     1036
     1037    psFree(output);
     1038
     1039    return true;
     1040}
Note: See TracChangeset for help on using the changeset viewer.