IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2011, 2:09:53 PM (15 years ago)
Author:
watersc1
Message:

implementation of summit_id index in summit{Exp,Imfile},pzDownload{Exp,Imfile},newExp tables.

File:
1 edited

Legend:

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

    r30907 r31038  
    5353static psArray *pzGetPendingCameras(pxConfig *config);
    5454static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
    55 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state);
     55static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state);
    5656
    5757# define MODECASE(caseName, func) \
     
    222222
    223223    psMetadata *where = psMetadataAlloc();
     224    PXOPT_COPY_S64(config->args, where,  "-summit_id",    "summit_id", "==");
    224225    PXOPT_COPY_STR(config->args, where,  "-exp_name",     "exp_name", "==");
    225226    PXOPT_COPY_STR(config->args, where,  "-inst",         "camera", "==");
     
    237238            " FROM summitExp"
    238239            " LEFT JOIN pzDownloadExp"
    239             "   USING(exp_name, camera, telescope)"
     240            "   USING(summit_id)"
    240241            " WHERE"
    241             "   pzDownloadExp.exp_name IS NULL"
    242             "   AND pzDownloadExp.camera IS NULL"
    243             "   AND pzDownloadExp.telescope IS NULL"
     242            "   pzDownloadExp.summit_id IS NULL"
    244243            "   AND summitExp.fault = 0"
    245244        );
     
    260259    if (limit) {
    261260        psString limitString = psDBGenerateLimitSQL(limit);
     261
    262262        psStringAppend(&query, " %s", limitString);
    263263        psFree(limitString);
     
    299299
    300300    psMetadata *where = psMetadataAlloc();
     301    PXOPT_COPY_S64(config->args, where,  "-summit_id",     "summit_id", "==");
    301302    PXOPT_COPY_STR(config->args, where,  "-exp_name",      "exp_name",  "==");
    302303    PXOPT_COPY_STR(config->args, where,  "-inst",          "camera",    "==");
     
    401402
    402403    // required
     404    PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
    403405    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
    404406    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
     
    428430
    429431        psMetadata *where = psMetadataAlloc();
     432        PXOPT_COPY_S64(config->args, where,  "-summit_id", "summit_id", "==");
    430433        PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
    431434        PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
     
    459462
    460463    if (!pzDownloadImfileInsert(config->dbh,
     464            summit_id,                 
    461465            exp_name,
    462466            camera,
     
    505509
    506510    psMetadata *where = psMetadataAlloc();
     511    PXOPT_COPY_STR(config->args, where,  "-summit_id", "summit_id", "==");
    507512    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
    508513    PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
     
    560565
    561566    // required
     567    PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
    562568    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
    563569    PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false);
     
    579585    if (!newExpInsert(config->dbh,
    580586            0x0,        // exp_id
     587            summit_id,  // summit_id
    581588            exp_name,   // tmp_exp_name
    582589            inst,       // tmp_camera
     
    597604        }
    598605
    599         psS64 exp_id = psDBLastInsertID(config->dbh);
    600 
    601         // insert newImfiles
    602         {
    603             char *query =
     606    psS64 exp_id = psDBLastInsertID(config->dbh);
     607
     608    // insert newImfiles
     609    {
     610      char *query =
    604611                "INSERT INTO newImfile"
    605                 "   SElECT"
     612                "   SELECT"
    606613                "       %" PRId64 ","               // exp_id
     614                "       %" PRId64 ","               // summit_id
    607615                "       pzDownloadImfile.class_id," // tmp_class_id
    608616                "       pzDownloadImfile.uri,"      // uri
     
    616624                "       AND pzDownloadImfile.telescope = '%s'";
    617625
    618         if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) {
    619             psError(PS_ERR_UNKNOWN, false, "database error");
    620             return false;
    621         }
    622 
    623         // sanity check: we should have inserted at least one row
    624         psU64 affected = psDBAffectedRows(config->dbh);
    625         if (psDBAffectedRows(config->dbh) < 1) {
    626             psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
    627             return false;
    628         }
     626      if (!p_psDBRunQueryF(config->dbh, query, exp_id, summit_id, exp_name, inst, telescope)) {
     627        psError(PS_ERR_UNKNOWN, false, "database error");
     628        return false;
     629      }
     630
     631      // sanity check: we should have inserted at least one row
     632      psU64 affected = psDBAffectedRows(config->dbh);
     633      if (psDBAffectedRows(config->dbh) < 1) {
     634        psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
     635        return false;
     636      }
    629637    }
    630638
    631639    // set pzDownloadExp.state to 'stop'
    632     if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) {
    633         psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", exp_name, inst, telescope);
     640    if (!pzDownloadExpSetState(config, summit_id, "stop")) {
     641        psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %ld", summit_id);
    634642        return false;
    635643    }
     
    887895
    888896
    889 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
     897static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state)
    890898{
    891899    PS_ASSERT_PTR_NON_NULL(state, false);
     
    904912    }
    905913
    906     char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'";
    907     if (!p_psDBRunQueryF(config->dbh, query, state, exp_name, camera, telescope)) {
    908         psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope);
     914    char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE summit_id = %ld";
     915    if (!p_psDBRunQueryF(config->dbh, query, state, summit_id)) {
     916        psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
    909917        return false;
    910918    }
     
    916924{
    917925  PS_ASSERT_PTR_NON_NULL(config, false);
    918   PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
    919   PXOPT_LOOKUP_STR(camera,   config->args, "-inst",   true, false);
    920   PXOPT_LOOKUP_STR(telescope,config->args, "-telescope",true, false);
     926  PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
    921927  PXOPT_LOOKUP_STR(state,    config->args, "-set_state",true, false);
    922928
    923   if (!pzDownloadExpSetState(config,exp_name,camera,telescope,state)) {
    924     psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope);
     929  if (!pzDownloadExpSetState(config,summit_id, state)) {
     930    psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
    925931    return false;
    926932  }
Note: See TracChangeset for help on using the changeset viewer.