IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 29, 2008, 2:44:04 PM (18 years ago)
Author:
eugene
Message:

merge cvs HEAD into cleanup branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/ippTools/src/regtool.c

    r18076 r18357  
    4343static bool revertprocessedexpMode(pxConfig *config);
    4444static bool updateprocessedexpMode(pxConfig *config);
     45static bool cleardupexpMode(pxConfig *config);
    4546
    4647# define MODECASE(caseName, func) \
     
    7475        MODECASE(REGTOOL_MODE_REVERTPROCESSEDEXP,    revertprocessedexpMode);
    7576        MODECASE(REGTOOL_MODE_UPDATEPROCESSEDEXP,    updateprocessedexpMode);
     77        MODECASE(REGTOOL_MODE_CLEARDUPEXP,           cleardupexpMode);
    7678        default:
    7779            psAbort("invalid option (this should not happen)");
     
    168170
    169171    // required
    170     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false);
     172    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
    171173    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
    172174    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
     
    228230    if (!rawImfileInsert(
    229231        config->dbh,
    230         (psS64)atoll(exp_id),
     232        exp_id,
    231233        exp_name,
    232234        camera,
     
    494496
    495497    // required
    496     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false);
     498    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
    497499    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
    498500    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
     
    567569        // build a query to search by exp_id
    568570        psMetadata *where = psMetadataAlloc();
    569         if (!psMetadataAddStr(where, PS_LIST_TAIL, "newExp.exp_id", 0, "==", exp_id)) {
     571        if (!psMetadataAddS64(where, PS_LIST_TAIL, "newExp.exp_id", 0, "==", exp_id)) {
    570572            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
    571573            psFree(where);
     
    650652
    651653    if (!rawExpInsert(config->dbh,
    652         (psS64)atoll(exp_id),
     654        exp_id,
    653655        exp_name,
    654656        camera,
     
    724726            psError(PS_ERR_UNKNOWN, false, "database error");
    725727        }
    726         psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_id: %s", exp_id);
     728        psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_id: %"PRId64, exp_id);
    727729    psFree(newExp);
    728730        return false;
     
    747749    // this can only be run as the newExp's state has been set to stop
    748750    if (!pxchipQueueByExpTag(config,
    749                 (psS64)atoll(exp_id),
     751                exp_id,
    750752                workdir,
    751753            label,
     
    795797
    796798    // XX test this out; need to make this consistent with the list in regtoolConfig.c
    797     PXOPT_COPY_STR(config->args, config->where,  "-exp_id", "exp_id", "==");
     799    PXOPT_COPY_S64(config->args, config->where,  "-exp_id", "exp_id", "==");
    798800    PXOPT_COPY_STR(config->args, config->where,  "-exp_name", "exp_name", "==");
    799801    PXOPT_COPY_STR(config->args, config->where,  "-inst", "camera", "==");
     
    941943    return true;
    942944}
     945
     946
     947static bool cleardupexpMode(pxConfig *config)
     948{
     949    PS_ASSERT_PTR_NON_NULL(config, false);
     950
     951    if (!psDBTransaction(config->dbh)) {
     952        psError(PS_ERR_UNKNOWN, false, "database error");
     953        return false;
     954    }
     955
     956// create temp table of exp_ids to be removed
     957{
     958    psString query = pxDataGet("regtool_create_dup_table.sql");
     959    if (!query) {
     960        // rollback
     961        if (!psDBRollback(config->dbh)) {
     962            psError(PS_ERR_UNKNOWN, false, "database error");
     963        }
     964        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     965        return false;
     966    }
     967
     968    if (!p_psDBRunQuery(config->dbh, query)) {
     969        // rollback
     970        if (!psDBRollback(config->dbh)) {
     971            psError(PS_ERR_UNKNOWN, false, "database error");
     972        }
     973        psError(PS_ERR_UNKNOWN, false, "database error");
     974        psFree(query);
     975        return false;
     976    }
     977    psFree(query);
     978}
     979
     980// populate that table
     981// XXX note that this query currently doesn't not correctly handle the case
     982// where there is more than one duplicate
     983{
     984    psString query = pxDataGet("regtool_populate_dup_table.sql");
     985    if (!query) {
     986        // rollback
     987        if (!psDBRollback(config->dbh)) {
     988            psError(PS_ERR_UNKNOWN, false, "database error");
     989        }
     990        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     991        return false;
     992    }
     993
     994    if (!p_psDBRunQuery(config->dbh, query)) {
     995        // rollback
     996        if (!psDBRollback(config->dbh)) {
     997            psError(PS_ERR_UNKNOWN, false, "database error");
     998        }
     999        psError(PS_ERR_UNKNOWN, false, "database error");
     1000        psFree(query);
     1001        return false;
     1002    }
     1003    psFree(query);
     1004}
     1005
     1006    if (!p_psDBRunQuery(config->dbh, "DELETE FROM rawImfile USING rawImfile, duplicate WHERE duplicate.exp_id = rawImfile.exp_id")) {
     1007        // rollback
     1008        if (!psDBRollback(config->dbh)) {
     1009            psError(PS_ERR_UNKNOWN, false, "database error");
     1010        }
     1011        psError(PS_ERR_UNKNOWN, false, "database error");
     1012        return false;
     1013    }
     1014
     1015    if (!p_psDBRunQuery(config->dbh, "DELETE FROM rawExp USING rawExp, duplicate WHERE duplicate.exp_id = rawExp.exp_id")) {
     1016        // rollback
     1017        if (!psDBRollback(config->dbh)) {
     1018            psError(PS_ERR_UNKNOWN, false, "database error");
     1019        }
     1020        psError(PS_ERR_UNKNOWN, false, "database error");
     1021        return false;
     1022    }
     1023
     1024    if (!p_psDBRunQuery(config->dbh, "DELETE FROM newImfile USING newImfile, duplicate WHERE duplicate.exp_id = newImfile.exp_id")) {
     1025        // rollback
     1026        if (!psDBRollback(config->dbh)) {
     1027            psError(PS_ERR_UNKNOWN, false, "database error");
     1028        }
     1029        psError(PS_ERR_UNKNOWN, false, "database error");
     1030        return false;
     1031    }
     1032
     1033    if (!p_psDBRunQuery(config->dbh, "DELETE FROM newExp USING newExp, duplicate WHERE duplicate.exp_id = newExp.exp_id")) {
     1034        // rollback
     1035        if (!psDBRollback(config->dbh)) {
     1036            psError(PS_ERR_UNKNOWN, false, "database error");
     1037        }
     1038        psError(PS_ERR_UNKNOWN, false, "database error");
     1039        return false;
     1040    }
     1041
     1042    if (!psDBCommit(config->dbh)) {
     1043        psError(PS_ERR_UNKNOWN, false, "database error");
     1044        return false;
     1045    }
     1046
     1047    return true;
     1048}
Note: See TracChangeset for help on using the changeset viewer.