IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28364


Ignore:
Timestamp:
Jun 16, 2010, 2:41:22 PM (16 years ago)
Author:
Paul Price
Message:

Fixing advance mode: 'You can't specify target table 'diffPhotRun' for update in FROM clause' (error from MySQL)

Location:
trunk/ippTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/share/diffphottool_advance.sql

    r28343 r28364  
    1 UPDATE diffPhotRun
    2 SET state = 'full'
    3 WHERE diff_phot_id IN (
    4     SELECT
    5         diff_phot_id
    6     FROM diffPhotRun
    7     JOIN diffSkyfile USING(diff_id)
    8     JOIN diffPhotSkyfile USING(diff_phot_id)
    9     WHERE diffPhotRun.state = 'new'
    10         AND diffPhotSkyfile.fault = 0
    11         AND diffSkyfile.fault = 0
    12         AND diffSkyfile.quality = 0
    13         -- WHERE hook %s
    14     HAVING COUNT(diffPhotSkyfile.skycell_id) = COUNT(diffSkyfile.skycell_id)
    15 ) AS diffPhotRunsDone
     1SELECT
     2    diff_phot_id
     3FROM diffPhotRun
     4JOIN diffSkyfile USING(diff_id)
     5JOIN diffPhotSkyfile USING(diff_phot_id)
     6WHERE diffPhotRun.state = 'new'
     7    AND diffPhotSkyfile.fault = 0
     8    AND diffSkyfile.fault = 0
     9    AND diffSkyfile.quality = 0
     10-- WHERE hook %s
     11HAVING COUNT(diffPhotSkyfile.skycell_id) = COUNT(diffSkyfile.skycell_id)
  • trunk/ippTools/src/diffphottool.c

    r28358 r28364  
    126126
    127127    if (!psDBTransaction(config->dbh)) {
    128         psError(PS_ERR_UNKNOWN, false, "database error");
     128        psError(psErrorCodeLast(), false, "database error");
    129129        return false;
    130130    }
    131131
    132132    if (!p_psDBRunQuery(config->dbh, query)) {
    133         psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s", query);
     133        psError(psErrorCodeLast(), false, "Unable to run query: %s", query);
    134134        psFree(where);
    135135        return false;
     
    326326
    327327    if (!p_psDBRunQuery(config->dbh, query)) {
    328         psError(PS_ERR_UNKNOWN, false, "database error");
     328        psError(psErrorCodeLast(), false, "database error");
    329329        psFree(query);
    330330        return false;
     
    376376    if (!diffPhotSkyfileInsert(config->dbh, diff_phot_id, skycell_id, path_base, dtime_script, hostname,
    377377                               fault, quality, version)) {
    378         psError(PS_ERR_UNKNOWN, false, "database error");
     378        psError(psErrorCodeLast(), false, "database error");
    379379        return false;
    380380    }
     
    405405    psFree(where);
    406406
     407    if (!psDBTransaction(config->dbh)) {
     408        psError(psErrorCodeLast(), false, "database error");
     409        return false;
     410    }
     411
    407412    if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
    408413        psError(psErrorCodeLast(), false, "database error");
    409414        psFree(query);
    410         psFree(whereClause);
    411415        return false;
    412416    }
    413417    psFree(query);
    414     psFree(whereClause)
     418    psFree(whereClause);
     419
     420    psArray *output = p_psDBFetchResult(config->dbh);
     421    if (!output) {
     422        psError(psErrorCodeLast(), false, "database error");
     423        return false;
     424    }
     425
     426    for (int i = 0; i < output->n; i++) {
     427        psMetadata *row = output->data[i]; // Row of interest
     428        psS64 diff_phot_id = psMetadataLookupS64(NULL, row, "diff_phot_id");
     429
     430        const char *query = "UPDATE diffRun SET state = 'full' WHERE diff_id = %" PRId64;
     431        if (!p_psDBRunQueryF(config->dbh, query, diff_phot_id)) {
     432            psError(psErrorCodeLast(), false,
     433                    "failed to change state for diff_phot_id %" PRId64, diff_phot_id);
     434            if (!psDBRollback(config->dbh)) {
     435                psError(psErrorCodeLast(), false, "database error");
     436            }
     437            psFree(output);
     438            return false;
     439        }
     440    }
     441    psFree(output);
     442
     443    if (!psDBCommit(config->dbh)) {
     444        psError(psErrorCodeLast(), false, "database error");
     445        return false;
     446    }
    415447
    416448    return true;
     
    449481
    450482    if (!p_psDBRunQuery(config->dbh, query)) {
    451         psError(PS_ERR_UNKNOWN, false, "database error");
     483        psError(psErrorCodeLast(), false, "database error");
    452484        psFree(query);
    453485        return false;
Note: See TracChangeset for help on using the changeset viewer.