IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2009, 11:48:59 AM (17 years ago)
Author:
eugene
Message:

fix definebyquery insert sql so it can handle SQL wildcards; add -pretend mode to definebyquery

File:
1 edited

Legend:

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

    r24661 r24664  
    153153
    154154    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     155    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    155156    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
    156157
     
    236237    }
    237238    if (!psArrayLength(output)) {
    238         psTrace("stacktool", PS_LOG_INFO, "no rows found");
     239        psWarning("stacktool: no rows found");
     240        psFree(output);
     241        psFree(where);
     242        return true;
     243    }
     244    if (pretend) {
     245        // negative simple so the default is true
     246        if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
     247            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     248            psFree(output);
     249            psFree(where);
     250            return false;
     251        }
    239252        psFree(output);
    240253        psFree(where);
     
    362375        psFree(idString);
    363376
     377        // replace @FILTER@, @SKYCELL_ID@, @RANDOM_LIMIT@
     378        psStringSubstitute(&thisInsert, filter, "@FILTER@");
     379        psStringSubstitute(&thisInsert, skycell_id, "@SKYCELL_ID@");
     380
     381        if (randomLimit > 0) {
     382          psString limString = NULL;
     383          psStringAppend(&limString, "%d", randomLimit);
     384          psStringSubstitute(&thisInsert, limString, "@RANDOM_LIMIT@");
     385          psFree(limString);
     386        }
     387
    364388        // XXX this insert uses a select to generate the list of warp_ids for the stack,
    365389        // we have applied a set of criteria above (WHERE) to select the relevant warps
    366390        // this insert needs to use exactly the same restrictions (race condition is probably not critical)
    367391        // the insert below seems to only restrict matches to the skycell, tess, and filter
    368         if ((randomLimit > 0 && !p_psDBRunQueryF(config->dbh, thisInsert, skycell_id, filter, randomLimit)) ||
    369             (randomLimit <= 0 && !p_psDBRunQueryF(config->dbh, thisInsert, skycell_id, filter))) {
     392        if (!p_psDBRunQuery(config->dbh, thisInsert)) {
    370393            psError(PS_ERR_UNKNOWN, false, "database error");
    371394            psFree(thisInsert);
     
    379402        }
    380403        psFree(thisInsert);
     404
     405# if (0)
     406        {
     407          psArray *output = p_psDBFetchResult(config->dbh);
     408          if (!output) {
     409            psErrorCode err = psErrorCodeLast();
     410            switch (err) {
     411            case PS_ERR_DB_CLIENT:
     412              psError(PXTOOLS_ERR_SYS, false, "database error");
     413            case PS_ERR_DB_SERVER:
     414              psError(PXTOOLS_ERR_PROG, false, "database error");
     415            default:
     416              psError(PXTOOLS_ERR_PROG, false, "unknown error");
     417            }
     418            psFree(where);
     419            return false;
     420          }
     421          if (!psArrayLength(output)) {
     422            psWarning("stacktool (definebyquery, insert): no rows found");
     423            psFree(output);
     424            psFree(where);
     425            return true;
     426          }
     427          // negative simple so the default is true
     428          if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
     429            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     430            psFree(output);
     431            psFree(where);
     432            return false;
     433          }
     434          psFree(output);
     435          psFree(where);
     436          return true;
     437        }
     438# endif
     439
    381440    }
    382441    psFree(output);
Note: See TracChangeset for help on using the changeset viewer.