IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 27, 2011, 7:33:50 PM (15 years ago)
Author:
watersc1
Message:

pre-build test checkin of LAP code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406/ippTools/src/laptool.c

    r31385 r31396  
    4545
    4646  switch (config->mode) {
     47    MODECASE(LAPTOOL_MODE_DEFINESEQUENCE, definesequenceMode);
     48    MODECASE(LAPTOOL_MODE_LISTSEQUENCE,   listsequenceMode);
     49   
    4750    MODECASE(LAPTOOL_MODE_DEFINERUN,     definerunMode);
    4851    MODECASE(LAPTOOL_MODE_PENDINGRUN,    pendingrunMode);
    4952    MODECASE(LAPTOOL_MODE_UPDATERUN,     updaterunMode);
    5053
    51     MODECASE(LAPTOOL_MODE_PENDINGCHIPEXP,   pendingchipexpMode);
    52     MODECASE(LAPTOOL_MODE_PENDINGQUICKSTACK,pendingquickstackMode);
    53     MODECASE(LAPTOOL_MODE_PENDINGDIFF,      pendingdiffMode);
    54     MODECASE(LAPTOOL_MODE_PENDINGFINALSTACK,pendingfinalstackMode);
    55     MODECASE(LAPTOOL_MODE_UPDATEEXP,        updateexpMode);
     54    MODECASE(LAPTOOL_MODE_PENDINGEXP,    pendingexpMode);
     55    MODECASE(LAPTOOL_MODE_EXPOSURES,     exposuresMode);
     56    MODECASE(LAPTOOL_MODE_STACKS,        stacksMode);
     57    MODECASE(LAPTOOL_MODE_UPDATEEXP,     updateexpMode);
     58
     59    MODECASE(LAPTOOL_MODE_INACTIVEEXP,   inactiveexpMode);
    5660  default:
    5761    psAbort("invalid option (this should not happen)");
     
    7478}
    7579
     80// Sequence level
     81
     82static bool definesequenceMode(pxConfig *config)
     83{
     84  PS_ASSERT_PTR_NON_NULL(config, false);
     85
     86  PXOPT_LOOKUP_STR(name,        config->args, "-name",        true, false);
     87  PXOPT_LOOKUP_STR(description, config->args, "-description", true, false);
     88  PXOPT_LOOKUP_BOOL(simple,     config->args, "-simple",     false);
     89
     90  lapSequenceRow *run = lapSequenceRowAlloc(0, // seq_id
     91                                            name,
     92                                            description);
     93  if (!run) {
     94    psError(PS_ERR_UNKNOWN, false, "failed to alloc lapSequence object");
     95    return(true);
     96  }
     97
     98  if (!psDBTransaction(config->dbh)) {
     99    psError(PS_ERR_UNKNOWN, false, "database error");
     100    return false;
     101  }
     102
     103  if (!lapSequenceInsertObject(config->dbh, run)) {
     104    if (!psDBRollback(config->dbh)) {
     105      psError(PS_ERR_UNKNOWN, false, "database error");
     106    }
     107    psError(PS_ERR_UNKNOWN, false "database error");
     108    psFree(run);
     109    return(true);
     110  }
     111
     112  // point of no return
     113  if (!psDBCommit(config->dbh)) {
     114    psError(PS_ERR_UNKNOWN, false, "database error");
     115    return false;
     116  }
     117
     118  if (lapSequencePrintObject(stdout, run, !simple)) {
     119    psError(PS_ERR_UNKNOWN, false, "failed to print object");
     120    psFree(run);
     121    return false;
     122  }
     123
     124  psFree(run);
     125
     126  return true; 
     127}
     128
     129static bool listsequenceMode(pxConfig *config)
     130{
     131  PS_ASSERT_PTR_NON_NULL(config, false);
     132
     133  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     134  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     135 
     136  psMetadata *where = psMetadataAlloc();
     137  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     138  PXOPT_COPY_STR(config->args, where, "-name",   "name",   "LIKE");
     139
     140  psString query = pxDataGet("laptool_listsequence.sql");
     141  if (!query) {
     142    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
     143    return false;
     144  }
     145  if (psListLength(where->list)) {
     146    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     147    psStringAppend(&query, " WHERE %s", whereClause);
     148    psFree(whereClause);
     149  }
     150
     151  if (limit) {
     152    psString limitString = psDBGenerateLimitSQL(limit);
     153    psStringAppend(&query, " %s" limitString);
     154    psFree(limitString);
     155  }
     156  if (!p_psDBRunQuery(config->dbh, query)) {
     157    psError(PS_ERR_UNKNOWN, false, "database error");
     158    psFree(query);
     159    return false;
     160  }
     161  psFree(query);
     162
     163  psArray *output = p_psDBFetchResult(config->dbh);
     164  if (!output) {
     165    psErrorCode err = psErrorCodeLast();
     166    switch (err) {
     167    case PS_ERR_DB_CLIENT:
     168      psError(PXTOOLS_ERR_SYS, false, "database error");
     169    case PS_ERR_DB_SERVER:
     170      psError(PXTOOLS_ERR_PROG, false, "database error");
     171    default:
     172      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     173    }
     174
     175    return false;
     176  }
     177  if (!psArrayLength(output)) {
     178    psTrace("laptool", PS_LOG_INFO, "no rows found");
     179    psFree(output);
     180    return true;
     181  }
     182
     183  if (psArrayLength(output)) {
     184    if (!ippdbPrintMetadatas(stdout, output, "lapSequence", !simple)) {
     185      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     186      psFree(output);
     187      return false;
     188    }
     189  }
     190
     191  psFree(output);
     192
     193  return true;
     194}
     195 
     196
    76197// Run level
    77198static bool definerunMode(pxConfig *config)
     
    79200  PS_ASSERT_PTR_NON_NULL(config, false);
    80201
     202  PXOPT_LOOKUP_S64(seq_id,          config->args, "-seq_id",          true, false);
    81203  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
    82204  PXOPT_LOOKUP_STR(tess_id,         config->args, "-tess_id",         true, false);
     
    84206  PXOPT_LOOKUP_F64(decl,            config->args, "-decl",            true, false);
    85207  PXOPT_LOOKUP_F32(radius,          config->args, "-radius",          true, false);
    86 
    87   // Insert the run
    88   if (!lapRunInsert(config->dbh,
    89                        NULL,  // lap_id
    90                        projection_cell,
    91                        tess_id,
    92                        ra,
    93                        decl,
    94                        radius,
    95                        NULL,  // registered
    96                        "new", // state
    97                        0      // fault
    98                        )) {
    99     // rollback
     208  PXOPT_LOOKUP_STR(filter,          config->args, "-filter",          true, false);
     209  PXOPT_LOOKUP_STR(label,           config->args, "-label",           false, false);
     210  PXOPT_LOOKUP_STR(dist_group,      config->args, "-dist_group",      false, false);
     211
     212  lapRunRow *run = lapRunRowAlloc(0, // lap_id
     213                                  seq_id,
     214                                  tess_id,
     215                                  projection_cell,
     216                                  filter,
     217                                  "new", // state
     218                                  label,
     219                                  dist_group,
     220                                  NULL, // registered
     221                                  0,    // fault
     222                                  NULL, // quick_sass_id
     223                                  NULL, // final_sass_id
     224                                  );
     225  if (!run) {
     226    psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
     227    return(true);
     228  }
     229
     230  if (!psDBTransaction(config->dbh)) {
     231    psError(PS_ERR_UNKNOWN, false, "database error");
     232    return false;
     233  }
     234
     235  if (!lapSequenceInsertObject(config->dbh, run)) {
    100236    if (!psDBRollback(config->dbh)) {
    101237      psError(PS_ERR_UNKNOWN, false, "database error");
    102238    }
    103     psError(PS_ERR_UNKNOWN, false, "database error");
    104    
    105     return false;
    106   }
     239    psError(PS_ERR_UNKNOWN, false "database error");
     240    psFree(run);
     241    return(true);
     242  }
     243
     244  // point of no return
     245  if (!psDBCommit(config->dbh)) {
     246    psError(PS_ERR_UNKNOWN, false, "database error");
     247    return false;
     248  }
     249
     250  if (lapSequencePrintObject(stdout, run, !simple)) {
     251    psError(PS_ERR_UNKNOWN, false, "failed to print object");
     252    psFree(run);
     253    return false;
     254  }
     255
    107256  psS64 lap_id = psDBLastInsertID(config->dbh);
    108 
    109257
    110258  // Find the input exposures
     
    166314{
    167315  PS_ASSERT_PTR_NON_NULL(config, false);
     316
    168317  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    169318 
    170   psmetadata *where = psMetadataAlloc();
     319  psMetadata *where = psMetadataAlloc();
     320  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
    171321  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    172322  PXOPT_COPY_STR(config->args, where, "-projection_cell", "projection_cell", "==");
     323  PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
     324  PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     325  PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     326  PXOPT_COPY_STR(config->args, where, "-fault", "fault", "==");
    173327
    174328  psString query = pxDataGet("laptool_pendingrun.sql");
    175329  if (!query) {
    176330    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
     331    return false;
     332  }
     333  if (psListLength(where->list)) {
     334    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     335    psStringAppend(&query, " WHERE %s", whereClause);
     336    psFree(whereClause);
     337  }
     338  psStringAppend(&query, " ORDER BY rawExp.dateobs ");
     339 
     340  if (!p_psDBRunQuery(config->dbh, query)) {
     341    psError(PS_ERR_UNKNOWN, false, "database error");
     342    psFree(query);
     343    return false;
     344  }
     345  psFree(query);
     346
     347  psArray *output = p_psDBFetchResult(config->dbh);
     348  if (!output) {
     349    psErrorCode err = psErrorCodeLast();
     350    switch (err) {
     351    case PS_ERR_DB_CLIENT:
     352      psError(PXTOOLS_ERR_SYS, false, "database error");
     353    case PS_ERR_DB_SERVER:
     354      psError(PXTOOLS_ERR_PROG, false, "database error");
     355    default:
     356      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     357    }
     358
     359    return false;
     360  }
     361  if (!psArrayLength(output)) {
     362    psTrace("laptool", PS_LOG_INFO, "no rows found");
     363    psFree(output);
     364    return true;
     365  }
     366
     367  if (psArrayLength(output)) {
     368    if (!ippdbPrintMetadatas(stdout, output, "lapRun", !simple)) {
     369      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     370      psFree(output);
     371      return false;
     372    }
     373  }
     374
     375  psFree(output);
     376
     377  return true;
     378}
     379
     380static bool updaterunMode(pxConfig *config)
     381{
     382  PS_ASSERT_PTR_NON_NULL(config, false);
     383
     384  psMetadata *where = psMetadataAlloc();
     385  PXOPT_LOOKUP_S64(lap_id, config->args, "-lap_id", true, false);
     386  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
     387
     388  psMetadata *values = psMetadataAlloc();
     389  PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     390  PXOPT_COPY_STR(config->args, values, "-set_state", "state", "==");
     391  PXOPT_COPY_S16(config->args, values, "-fault",     "fault", "==");
     392  PXOPT_COPY_STR(config->args, values, "-set_label", "label", "==");
     393  PXOPT_COPY_S64(config->args, values, "-set_quick_sass_id", "quick_sass_id", "==");
     394  PXOPT_COPY_S64(config->args, values, "-set_final_sass_id", "final_sass_id", "==");
     395
     396  long rows = psDBUpdateRows(config->dbh, "lapRun", where, values);
     397  psFree(values);
     398 
     399  if (rows) {
     400    // We're done with these exposures now, so mark them as inactive.
     401    if ((strcmp(state,"drop") == 0)||
     402        (strcmp(state,"full") == 0)) {
     403      values = psMetadataAlloc();
     404      psMetadataAddBool(values, PS_LIST_TAIL, "active", 0, "", false);
     405      long exps = psDBUpdateRows(config->dbh, "lapExp", where, values);
     406
     407      if (exps) {
     408        return(true);
     409      }
     410      else {
     411        return(false);
     412      }
     413    }
     414    return(true);
     415  }
     416  else {
     417    return(false);
     418  }
     419}
     420
     421// Exposure level
     422
     423static bool pendingexpMode(pxConfig *config)
     424{
     425  PS_ASSERT_PTR_NON_NULL(config, false);
     426
     427  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     428  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     429 
     430  psMetadata *where = psMetadataAlloc();
     431  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
     432
     433  psString query = pxDataGet("laptool_pendingexp.sql");
     434  if (!query) {
     435    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
     436    return false;
     437  }
     438  if (psListLength(where->list)) {
     439    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     440    psStringAppend(&query, " WHERE %s", whereClause);
     441    psFree(whereClause);
     442  }
     443
     444  if (limit) {
     445    psString limitString = psDBGenerateLimitSQL(limit);
     446    psStringAppend(&query, " %s" limitString);
     447    psFree(limitString);
     448  }
     449  if (!p_psDBRunQuery(config->dbh, query)) {
     450    psError(PS_ERR_UNKNOWN, false, "database error");
     451    psFree(query);
     452    return false;
     453  }
     454  psFree(query);
     455
     456  psArray *output = p_psDBFetchResult(config->dbh);
     457  if (!output) {
     458    psErrorCode err = psErrorCodeLast();
     459    switch (err) {
     460    case PS_ERR_DB_CLIENT:
     461      psError(PXTOOLS_ERR_SYS, false, "database error");
     462    case PS_ERR_DB_SERVER:
     463      psError(PXTOOLS_ERR_PROG, false, "database error");
     464    default:
     465      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     466    }
     467
     468    return false;
     469  }
     470  if (!psArrayLength(output)) {
     471    psTrace("laptool", PS_LOG_INFO, "no rows found");
     472    psFree(output);
     473    return true;
     474  }
     475
     476  if (psArrayLength(output)) {
     477    if (!ippdbPrintMetadatas(stdout, output, "lapExp", !simple)) {
     478      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     479      psFree(output);
     480      return false;
     481    }
     482  }
     483
     484  psFree(output);
     485
     486  return true;
     487}
     488
     489
     490static bool exposuresMode(pxConfig *config)
     491{
     492  PS_ASSERT_PTR_NON_NULL(config, false);
     493  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     494  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     495 
     496  psMetadata *where = psMetadataAlloc();
     497  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
     498  PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     499 
     500  psString query = pxDataGet("laptool_exposures.sql");
     501  if (!query) {
     502    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
    177503    return(false);
    178504  }
    179505  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    180506  if (whereClause) {
    181     psStringPrepend(&whereClause, "\n AND ");
     507    psStringSubstitute(&query,whereClause,"@WHERE@");
    182508  }
    183509 
     
    218544  psFree(output);
    219545  return(true);
    220  
    221 }
    222 static bool updaterunMode(pxConfig *config)
    223 {
    224   PS_ASSERT_PTR_NON_NULL(config, false);
    225 
    226   psMetadata *where = psMetadataAlloc();
    227   PXOPT_LOOKUP_S64(lap_id, config->args, "-lap_id", true, false);
    228   PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    229   PXOPT_LOOKUP_STR(set_state, config->args, "-set_state", false, false);
    230 
    231   if ((fault == INT16_MAX)&&(!set_state)) {
    232     psError(PS_ERR_UNKNOWN, false, "one of -fault or -set_state must be selected");
    233     return(false);
    234   }
    235 
     546}
     547
     548static bool stacksMode(pxConfig *config)
     549{
     550  PS_ASSERT_PTR_NON_NULL(config, false);
     551  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     552  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     553 
    236554  psMetadata *where = psMetadataAlloc();
    237555  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    238 
    239   // Set a fault
    240   if (fault != INT16_MAX) {
    241     // this is fairly dangerous : can set all if the where is not set...
    242     if (!pxSetFaultCode(config->dbh, "lapRun", where, fault, 0)) {
    243       psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    244       psFree (where);
    245       return false;
    246     }
    247     psFree (where);
    248     return(true);
    249   }
    250 
    251   // Set the state, and deactivate the exposures if needed.
    252 
    253   if ((strcmp(set_state,"drop") == 0)||
    254       (strcmp(set_state,"full") == 0)) {
    255     // Deactivate exposures
    256 
    257     psString query = pxDataGet("laptool_updaterun_deactivate.sql");
    258     if (!query) {
    259       psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
    260       return(false);
    261     }
    262     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    263     psStringAppend(&query, whereClause, " \n ");
    264     if (!p_psDBRunQuery(config->dbh, query)) {
    265       psError(PS_ERR_UNKNOWN, false, "database error");
    266       psFree(query);
    267       return(false);
    268     }
    269     psFree(query);
    270   }
    271 
    272   char *query = "UPDATE lapRun SET state = '%s' WHERE lap_id = %"PRId64;
    273   if (!p_psDBRunQueryF(config->dbh, query, state, lap_id)) {
    274     psError(PS_ERR_UNKNOWN, false,
    275             "failed to change state for lap_id %"PRId64, lap_id);
    276     return(false);
    277   }
    278 
    279   return(true); 
    280 }
    281 // Exposure level
    282 
    283 static bool exposuresMode(pxConfig *config)
    284 {
    285   PS_ASSERT_PTR_NON_NULL(config, false);
    286   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    287  
    288   psmetadata *where = psMetadataAlloc();
    289   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    290 
    291   psString query = pxDataGet("laptool_exposures.sql");
     556 
     557  psString query = pxDataGet("laptool_stacks.sql");
    292558  if (!query) {
    293559    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
     
    327593  }
    328594 
    329   if (!ippdbPrintMetadatas(stdout, output, "lapExp", !simple)) {
     595  if (!ippdbPrintMetadatas(stdout, output, "lapRunStacks", !simple)) {
    330596    psError(PS_ERR_UNKNOWN, false, "failed to print array");
    331597    psFree(output);
     
    335601  psFree(output);
    336602  return(true);
    337  
    338 }
    339 
    340 
    341 static bool pendingchipexpMode(pxConfig *config)
    342 {
    343   PS_ASSERT_PTR_NON_NULL(config, false);
     603}
     604
     605static bool updateexpMode(pxConfig *config)
     606{
     607  PS_ASSERT_PTR_NON_NULL(config, false);
     608
     609  psMetadata *where = psMetadataAlloc();
     610  PXOPT_LOOKUP_S64(lap_id,  config->args, "-lap_id",  true, false);
     611  PXOPT_LOOKUP_S64(exp_id,  config->args, "-exp_id",  true, false);
     612  PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", false, false);
     613
     614  PXOPT_LOOKUP_S64(set_chip_id, config->args, "-set_chip_id", false, false);
     615  PXOPT_LOOKUP_S64(set_pair_id, config->args, "-set_pair_id", false, false);
     616  PXOPT_LOOKUP_BOOL(private,    config->args, "-private",     false, false);
     617  PXOPT_LOOKUP_BOOL(public,     config->args, "-public",      false, false);
     618  PXOPT_LOOKUP_BOOL(pairwise,   config->args, "-pairwise",    false, false);
     619  PXOPT_LOOKUP_BOOL(nopairwise, config->args, "-nopairwise",  false, false);
     620  PXOPT_LOOKUP_BOOL(active,     config->args, "-active",      false, false);
     621  PXOPT_LOOKUP_BOOL(inactive,   config->args, "-inactive",    false, false);
     622
     623
     624  if (private && public) {
     625    psError(PS_ERR_UNKNOWN, false, "only one of -private and -public may be selected");
     626  }
     627  if (active && inactive) {
     628    psError(PS_ERR_UNKNOWN, false, "only one of -active and -inactive may be selected");
     629  }
     630  if (pairwise && nopairwise) {
     631    psError(PS_ERR_UNKNOWN, false, "only one of -pairwise and -nopairwise may be selected");
     632  }
     633
     634  psMetadata *where = psMetadataAlloc();
     635  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
     636  PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     637  PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     638
     639  psMetadata *values = psMetadataAlloc();
     640  if (set_chip_id) {
     641    PXOPT_COPY_S64(config->args, values, "-set_chip_id", "chip_id", "==");
     642  }
     643  if (set_pair_id) {
     644    PXOPT_COPY_S64(config->args, values, "-set_pair_id", "pair_id", "==");
     645  }
     646  if (private) {
     647    psMetadataAddBool(values, PS_LIST_TAIL, "private", 1, "", false);
     648  }
     649  else if (public) {
     650    psMetadataAddBool(values, PS_LIST_TAIL, "private", 0, "", false);
     651  }
     652  if (active) {
     653    psMetadataAddBool(values, PS_LIST_TAIL, "active", 1, "", false);
     654  }
     655  else if (inactive) {
     656    psMetadataAddBool(values, PS_LIST_TAIL, "active", 0, "", false);
     657  }
     658  if (pairwise) {
     659    psMetadataAddBool(values, PS_LIST_TAIL, "pairwise", 1, "", false);
     660  }
     661  else if (nopairwise) {
     662    psMetadataAddBool(values, PS_LIST_TAIL, "pairwise", 0, "", false);
     663  }
     664 
     665  long rows = psDBUpdateRows(config->dbh,"lapExp",where,values);
     666  if (rows) {
     667    return(true);
     668  }
     669  else {
     670    return(false);
     671  } 
     672}
     673
     674
     675   
     676
     677static bool inactiveexpMode(pxConfig *config)
     678{
     679  PS_ASSERT_PTR_NON_NULL(config, false);
     680
     681  psMetadata *where = psMetadataAlloc();
     682  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    344683 
    345684  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    346  
    347   psmetadata *where = psMetadataAlloc();
    348   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    349   PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    350 
    351   psString query = pxDataGet("laptool_pendingchipexp.sql");
     685  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     686 
     687  psString query = pxDataGet("laptool_inactiveexp.sql");
    352688  if (!query) {
    353689    psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
     
    356692  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    357693  if (whereClause) {
    358     psStringPrepend(&whereClause, "\n AND ");
     694    psStringSubstitute(&query,whereClause,"@WHERE@");
    359695  }
    360696 
     
    395731  psFree(output);
    396732  return(true);
    397  
    398 
    399 }
    400 static bool pendingquickstackMode(pxConfig *config)
    401 {
    402   PS_ASSERT_PTR_NON_NULL(config, false);
    403   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    404  
    405   psmetadata *where = psMetadataAlloc();
    406   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    407   PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    408 
    409   psString query = pxDataGet("laptool_pendingquickstack.sql");
    410   if (!query) {
    411     psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
    412     return(false);
    413   }
    414   psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    415   if (whereClause) {
    416     psStringPrepend(&whereClause, "\n AND ");
    417   }
    418  
    419   psString limitString = NULL;
    420   if (limit) {
    421     limitString = psDBGenerateLimitSQL(limit);
    422     psStringPrepend(&limitString, "\n");
    423   }
    424 
    425   if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) {
    426     psError(PXTOOLS_ERR_PROG, false, "database error");
    427     psFree(limitString);
    428     psFree(query);
    429     psFree(whereClause);
    430     return(false);
    431   }
    432   psFree(limitString);
    433   psFree(query);
    434   psFree(whereClause);
    435  
    436   psArray *output = p_psDBFetchResult(config->dbh);
    437   if (!output) {
    438     psError(PS_ERR_UNKNOWN, false, "database error");
    439     return(false);
    440   }
    441   if (!psArrayLength(output)) {
    442     psTrace("laptool", PS_LOG_INFO, "no rows found");
    443     psFree(output);
    444     return(true);
    445   }
    446  
    447   if (!ippdbPrintMetadatas(stdout, output, "lapExp", !simple)) {
    448     psError(PS_ERR_UNKNOWN, false, "failed to print array");
    449     psFree(output);
    450     return(false);
    451   }
    452 
    453   psFree(output);
    454   return(true);
    455  
    456 
    457 }
    458 static bool pendingdiffMode(pxConfig *config)
    459 {
    460   PS_ASSERT_PTR_NON_NULL(config, false);
    461   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    462  
    463   psmetadata *where = psMetadataAlloc();
    464   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    465   PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    466 
    467   psString query = pxDataGet("laptool_pendingdiff.sql");
    468   if (!query) {
    469     psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
    470     return(false);
    471   }
    472   psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    473   if (whereClause) {
    474     psStringPrepend(&whereClause, "\n AND ");
    475   }
    476  
    477   psString limitString = NULL;
    478   if (limit) {
    479     limitString = psDBGenerateLimitSQL(limit);
    480     psStringPrepend(&limitString, "\n");
    481   }
    482 
    483   if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) {
    484     psError(PXTOOLS_ERR_PROG, false, "database error");
    485     psFree(limitString);
    486     psFree(query);
    487     psFree(whereClause);
    488     return(false);
    489   }
    490   psFree(limitString);
    491   psFree(query);
    492   psFree(whereClause);
    493  
    494   psArray *output = p_psDBFetchResult(config->dbh);
    495   if (!output) {
    496     psError(PS_ERR_UNKNOWN, false, "database error");
    497     return(false);
    498   }
    499   if (!psArrayLength(output)) {
    500     psTrace("laptool", PS_LOG_INFO, "no rows found");
    501     psFree(output);
    502     return(true);
    503   }
    504  
    505   if (!ippdbPrintMetadatas(stdout, output, "lapExp", !simple)) {
    506     psError(PS_ERR_UNKNOWN, false, "failed to print array");
    507     psFree(output);
    508     return(false);
    509   }
    510 
    511   psFree(output);
    512   return(true);
    513  
    514 
    515 }
    516 static bool pendingfinalstackMode(pxConfig *config)
    517 {
    518   PS_ASSERT_PTR_NON_NULL(config, false);
    519   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    520  
    521   psmetadata *where = psMetadataAlloc();
    522   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    523   PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
    524 
    525   psString query = pxDataGet("laptool_pendingfinalstack.sql");
    526   if (!query) {
    527     psError(PXTOOL_ERR_SYS, false, "failed to retrieve SQL statement");
    528     return(false);
    529   }
    530   psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    531   if (whereClause) {
    532     psStringPrepend(&whereClause, "\n AND ");
    533   }
    534  
    535   psString limitString = NULL;
    536   if (limit) {
    537     limitString = psDBGenerateLimitSQL(limit);
    538     psStringPrepend(&limitString, "\n");
    539   }
    540 
    541   if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) {
    542     psError(PXTOOLS_ERR_PROG, false, "database error");
    543     psFree(limitString);
    544     psFree(query);
    545     psFree(whereClause);
    546     return(false);
    547   }
    548   psFree(limitString);
    549   psFree(query);
    550   psFree(whereClause);
    551  
    552   psArray *output = p_psDBFetchResult(config->dbh);
    553   if (!output) {
    554     psError(PS_ERR_UNKNOWN, false, "database error");
    555     return(false);
    556   }
    557   if (!psArrayLength(output)) {
    558     psTrace("laptool", PS_LOG_INFO, "no rows found");
    559     psFree(output);
    560     return(true);
    561   }
    562  
    563   if (!ippdbPrintMetadatas(stdout, output, "lapExp", !simple)) {
    564     psError(PS_ERR_UNKNOWN, false, "failed to print array");
    565     psFree(output);
    566     return(false);
    567   }
    568 
    569   psFree(output);
    570   return(true);
    571  
    572 
    573 }
    574 static bool updateexpMode(pxConfig *config)
    575 {
    576   PS_ASSERT_PTR_NON_NULL(config, false);
    577 
    578   psMetadata *where = psMetadataAlloc();
    579   PXOPT_LOOKUP_S64(lap_id, config->args, "-lap_id", true, false);
    580   PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
    581   PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", false, false);
    582 
    583   PXOPT_LOOKUP_S64(set_chip_id, config->args, "-set_chip_id", false, false);
    584   PXOPT_LOOKUP_BOOL(private, config->args, "-private", false, false);
    585   PXOPT_LOOKUP_BOOL(active,  config->args, "-active", false, false);
    586   PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive", false, false);
    587 
    588   if (active == inactive) {
    589     psError(PS_ERR_UNKNOWN, false, "only one of -active and -inactive may be selected");
    590   }
    591 
    592   psMetadata *where = psMetadataAlloc();
    593   PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
    594   PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
    595   PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
    596 
    597   psMetadata *values = psMetadataAlloc();
    598   if (set_chip_id) {
    599     PXOPT_COPY_S64(config->args, values, "-set_chip_id", "chip_id", "==");
    600   }
    601   if (private) {
    602     PXOPT_COPY_BOOL(config->args, values, "-private", "private", "==");
    603   }
    604   if (active) {
    605     PXOPT_COPY_BOOL(config->args, values, "-active", "active", "==");
    606   }
    607   if (inactive) {
    608     psMetadataAddBool(values, PS_LIST_TAIL, "active", 0, "", false);
    609   }
    610 
    611   long rows = psDBUpdateRows(config->dbh,"lapExp",where,values);
    612   if (rows) {
    613     return(true);
    614   }
    615   else {
    616     return(false);
    617   } 
    618 }
    619 
    620 
    621    
    622              
     733}
     734
Note: See TracChangeset for help on using the changeset viewer.