IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18674


Ignore:
Timestamp:
Jul 23, 2008, 11:45:02 AM (18 years ago)
Author:
Paul Price
Message:

Working out the HAVING clause(s) explicitly, since 2/3 are more
complicated than can be accomodated with "where".

File:
1 edited

Legend:

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

    r18579 r18674  
    125125    PXOPT_LOOKUP_S32(randomLimit, config->args, "-random", false, false);
    126126
    127     PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">=");
    128     PXOPT_COPY_S32(config->args, having, "-min_new", "(num_warp - num_stack)", ">=");
    129 
     127    PXOPT_LOOKUP_S32(min_num, config->args, "-min_num", false, false);
     128    PXOPT_LOOKUP_S32(min_new, config->args, "-min_new", false, false);
    130129    PXOPT_LOOKUP_F32(min_frac, config->args, "-min_frac", false, false);
    131130
     
    172171    psFree(groupby);
    173172
    174     if (psListLength(having->list)) {
    175         psString havingClause = psDBGenerateWhereConditionSQL(having, NULL);
    176         psStringAppend(&select, " HAVING %s", havingClause);
    177         psFree(havingClause);
    178     }
    179 
    180     // Gotta handle this one explicitly --- want to avoid divisions
     173    psString having = NULL;             // HAVING string
     174    if (min_num > 0) {
     175        psStringAppend(&having, " min_num >= %d", min_num);
     176    }
     177    if (min_new > 0) {
     178        if (having) {
     179            psStringAppend(&having, " AND");
     180        }
     181        psStringAppend(&having, " ((num_warp - num_stack >= %d) OR num_stack IS NULL)", min_new);
     182    }
    181183    if (isfinite(min_frac)) {
    182         if (psListLength(having->list)) {
    183             psStringAppend(&select, " AND");
    184         } else {
    185             psStringAppend(&select, " HAVING");
    186         }
    187         psStringAppend(&select, " num_warp >= %f * num_stack", (double)min_frac);
    188     }
    189 
    190     psFree(having);
     184        if (having) {
     185            psStringAppend(&having, " AND");
     186        }
     187        // Avoiding division by zero
     188        psStringAppend(&select, " ((num_warp >= %f * num_stack) OR num_stack IS NULL)", (double)min_frac);
     189    }
     190    if (having) {
     191        psStringAppend(&select, " HAVING %s", having);
     192        psFree(having);
     193    }
     194
    191195
    192196    if (!p_psDBRunQuery(config->dbh, select)) {
Note: See TracChangeset for help on using the changeset viewer.