IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16588


Ignore:
Timestamp:
Feb 21, 2008, 6:09:46 PM (18 years ago)
Author:
jhoblitt
Message:

replumb pz* steps

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/dbconfig/tasks.md

    r16509 r16588  
    1 # $Id: tasks.md,v 1.147 2008-02-15 19:54:44 eugene Exp $
     1# $Id: tasks.md,v 1.148 2008-02-22 04:09:46 jhoblitt Exp $
    22
    33# this table records all exposure ID ever seen from the summit
     
    4343# list of source images -- updated as exposures/filesets are queried
    4444summitImfile METADATA
    45     exp_name    STR         64      # Primary Key
     45    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
    4646    camera      STR         64      # Primary Key
    4747    telescope   STR         64      # Primary Key
     
    5656# list of exposures that have had their imfiles/files registered (but not
    5757# downloaded)
    58 pzPendingExp METADATA
    59     exp_name    STR         64      # Primary Key
    60     camera      STR         64      # Primary Key
    61     telescope   STR         64      # Primary Key
    62 END
    63 
    64 pzPendingImfile METADATA
    65     exp_name    STR         64      # Primary Key
    66     camera      STR         64      # Primary Key
    67     telescope   STR         64      # Primary Key
    68     class       STR         64      # Primary Key
    69     class_id    STR         64      # Primary Key
    70 END
    71 
    72 # list of exposures that have had all of their imfiles downloaded
    73 pzDoneExp METADATA
    74     exp_name    STR         64      # Primary Key
    75     camera      STR         64      # Primary Key
    76     telescope   STR         64      # Primary Key
    77 END
    78 
    79 pzDoneImfile METADATA
    80     exp_name    STR         64      # Primary Key
    81     camera      STR         64      # Primary Key
     58pzDownloadExp METADATA
     59    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
     60    camera      STR         64      # Primary Key
     61    telescope   STR         64      # Primary Key
     62    state       STR         64      # Key
     63END
     64
     65pzDownloadImfile METADATA
     66    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref pzDownloadExp(exp_name, camera, telescope)
     67    camera      STR         64      # Primary Key fkey(exp_name, camera, telescope, class, class_id) ref summitImfile(exp_name, camera, telescope, class, class_id)
    8268    telescope   STR         64      # Primary Key
    8369    class       STR         64      # Primary Key
  • trunk/ippTools/share/pztool_find_completed_exp.sql

    r16334 r16588  
    11SELECT DISTINCT
    2     exp_name, -- return should match pzDoneExp
     2    exp_name, -- return should match pzDownloadExp
    33    camera,
    4     telescope
     4    telescope,
     5    state
    56FROM (
    67    SELECT
    7         pzDoneImfile.*,
     8        pzDownloadImfile.*,
     9        pzDownloadExp.state,
    810        summitExp.imfiles
    9     FROM pzDoneExp
     11    FROM pzDownloadExp
    1012    JOIN summitExp
    1113        USING(exp_name, camera, telescope)
    12     LEFT JOIN pzDoneImfile
     14    LEFT JOIN pzDownloadImfile
    1315        USING(exp_name, camera, telescope)
    1416    LEFT JOIN newExp
    15         ON pzDoneExp.exp_name = newExp.tmp_exp_name
    16         AND pzDoneExp.camera = newExp.tmp_camera
    17         AND pzDoneExp.telescope = newExp.tmp_telescope
     17        ON pzDownloadExp.exp_name = newExp.tmp_exp_name
     18        AND pzDownloadExp.camera = newExp.tmp_camera
     19        AND pzDownloadExp.telescope = newExp.tmp_telescope
    1820    WHERE
    19         newExp.tmp_exp_name IS NULL
     21        pzDownloadExp.state = 'run'
     22        AND newExp.tmp_exp_name IS NULL
    2023        AND newExp.tmp_camera IS NULL
    2124        AND newExp.tmp_telescope IS NULL
    2225    GROUP BY
    23         pzDoneExp.exp_name,
    24         pzDoneExp.camera,
    25         pzDoneExp.telescope
    26     -- it doesn't matter which field in pzDoneImfile we count as we've already
    27     -- done a group by
     26        pzDownloadExp.exp_name,
     27        pzDownloadExp.camera,
     28        pzDownloadExp.telescope
     29    -- it doesn't matter which field in pzDownloadImfile we count as we've
     30    -- already Download a group by
    2831    HAVING
    29         COUNT(pzDoneImfile.exp_name) = summitExp.imfiles
    30         AND SUM(pzDoneImfile.fault) = 0
     32        COUNT(pzDownloadImfile.exp_name) = summitExp.imfiles
     33        AND SUM(pzDownloadImfile.fault) = 0
    3134    ) as Foo
  • trunk/ippTools/share/pztool_pendingimfile.sql

    r15821 r16588  
    44        summitImfile.*,
    55        summitExp.dateobs
    6     FROM pzPendingImfile
    7     JOIN summitImfile
     6    FROM summitImfile
     7    JOIN pzDownloadExp
     8        USING(exp_name, camera, telescope)
     9    JOIN pzDownloadImfile
    810        USING(exp_name, camera, telescope, class, class_id)
    911    JOIN summitExp
    1012        USING(exp_name, camera, telescope)
     13    WHERE
     14        pzDownloadExp.state = 'run'
    1115    ORDER BY
    1216        summitExp.dateobs
  • trunk/ippTools/share/pztool_revertcopied.sql

    r16364 r16588  
    1 DELETE FROM pzDoneImfile
     1DELETE FROM pzDownloadImfile
    22WHERE
    33    fault != 0
  • trunk/ippTools/src/pxadminConfig.c

    r16507 r16588  
    3131    bool status;
    3232
    33     fprintf (stderr, "\nPan-STARRS Phase 2 Admin Tool\n\n");
     33    fprintf (stderr, "\nPan-STARRS DataBase Admin Tool\n\n");
    3434    fprintf (stderr, "Usage: %s [mode]\n", program);
    3535    fprintf (stderr, " [mode] : -create | -delete\n\n");
     
    9090    // paul's argument parsing convention requires: -key value
    9191    psMetadataAddStr(arguments, PS_LIST_TAIL, "-create", 0,
    92             "create the P2 tables", "");
     92            "create all IPP tables", "");
    9393    psMetadataAddStr(arguments, PS_LIST_TAIL, "-delete", 0,
    94             "delete the P2 tables", "");
     94            "delete all IPP tables", "");
    9595    psMetadataAddStr(arguments, PS_LIST_TAIL, "-recreate", 0,
    96             "delete and recreate the P2 tables", "");
     96            "delete and recreate all tables", "");
    9797
    9898    if (config->mode == PXADMIN_MODE_NONE) {
  • trunk/ippTools/src/pxtables.c

    r16508 r16588  
    5454    CREATE_TABLE(summitExpCreateTable);
    5555    CREATE_TABLE(summitImfileCreateTable);
    56     CREATE_TABLE(pzPendingExpCreateTable);
    57     CREATE_TABLE(pzPendingImfileCreateTable);
    58     CREATE_TABLE(pzDoneExpCreateTable);
    59     CREATE_TABLE(pzDoneImfileCreateTable);
     56//    CREATE_TABLE(pzPendingExpCreateTable);
     57//    CREATE_TABLE(pzPendingImfileCreateTable);
     58//    CREATE_TABLE(pzDoneExpCreateTable);
     59//    CREATE_TABLE(pzDoneImfileCreateTable);
     60    CREATE_TABLE(pzDownloadExpCreateTable);
     61    CREATE_TABLE(pzDownloadImfileCreateTable);
    6062    CREATE_TABLE(newExpCreateTable);
    6163    CREATE_TABLE(newImfileCreateTable);
     
    151153    DROP_TABLE(summitExpDropTable);
    152154    DROP_TABLE(summitImfileDropTable);
    153     DROP_TABLE(pzPendingExpDropTable);
    154     DROP_TABLE(pzPendingImfileDropTable);
    155     DROP_TABLE(pzDoneExpDropTable);
    156     DROP_TABLE(pzDoneImfileDropTable);
     155//    DROP_TABLE(pzPendingExpDropTable);
     156//    DROP_TABLE(pzPendingImfileDropTable);
     157//    DROP_TABLE(pzDoneExpDropTable);
     158//    DROP_TABLE(pzDoneImfileDropTable);
     159    DROP_TABLE(pzDownloadExpDropTable);
     160    DROP_TABLE(pzDownloadImfileDropTable);
    157161    DROP_TABLE(newExpDropTable);
    158162    DROP_TABLE(newImfileDropTable);
  • trunk/ippTools/src/pzgetexp.c

    r16170 r16588  
    22 * pzgetexp.c
    33 *
    4  * Copyright (C) 2006  Joshua Hoblitt
     4 * Copyright (C) 2006-2008  Joshua Hoblitt
    55 *
    66 * This program is free software; you can redistribute it and/or modify it
     
    186186    psFree(newSummitExps);
    187187
    188     // add new exps to pzPendingExp -- must be done before the new exps are
    189     // added to summitExp because of the SQL logic
    190     {
    191         char *query =
    192             "INSERT INTO pzPendingExp"
    193             "   SElECT"
    194             "       incoming.exp_name,"
    195             "       incoming.camera,"
    196             "       incoming.telescope"
    197             "   FROM incoming"
    198             "   LEFT JOIN summitExp"
    199             "       USING(exp_name, camera, telescope)"
    200             "   WHERE"
    201             "       summitExp.exp_name is NULL"
    202             "       AND summitExp.camera is NULL"
    203             "       AND summitExp.telescope is NULL";
    204 
    205         if (!p_psDBRunQuery(config->dbh, query)) {
    206             // rollback
    207             if (!psDBRollback(config->dbh)) {
    208                 psError(PS_ERR_UNKNOWN, false, "database error");
    209             }
    210             psError(PS_ERR_UNKNOWN, false, "database error");
    211             return false;
    212         }
    213     }
    214 
    215188    // add new exps to summitExp
    216189    {
  • trunk/ippTools/src/pzgetimfiles.c

    r16170 r16588  
    226226    psFree(newImfiles);
    227227
    228     // queue the imfiles (files) dest. for pzPendingImfile in pending -- must
    229     // be done before the imfile is insterted into summitImfile (after that
    230     // happens when don't know which imfiles are new anymore (well thats not
    231     // exactly true but it may be someday if we have to beable to resync to
    232     // modified datastore entries)
    233     {
    234         char *query =
    235             "INSERT IGNORE INTO pzPendingImfile"
    236             "   SElECT"
    237             "       incoming.exp_name,"
    238             "       incoming.camera,"
    239             "       incoming.telescope,"
    240             "       incoming.class,"
    241             "       incoming.class_id"
    242             "   FROM incoming";
    243 
    244         if (!p_psDBRunQuery(config->dbh, query)) {
    245             // rollback
    246             if (!psDBRollback(config->dbh)) {
    247                 psError(PS_ERR_UNKNOWN, false, "database error");
    248             }
    249             psError(PS_ERR_UNKNOWN, false, "database error");
    250             return false;
    251         }
    252     }
    253 
    254228    // copy imfiles (files) from the temp table into summitImfiles
    255229    {
    256230        char *query =
    257231            "INSERT IGNORE INTO summitImfile"
    258             "   SElECT"
     232            "   SELECT"
    259233            "       incoming.exp_name,"
    260234            "       incoming.camera,"
     
    313287    }
    314288
    315     // cp the pzPendingExp entry to pzDoneExp
     289    // add new exps to pzDownloadExp -- must be done before the new exps are
     290    // added to summitExp because of the SQL logic
    316291    {
    317292        char *query =
    318             "INSERT INTO pzDoneExp"
     293            "INSERT INTO pzDownloadExp"
    319294            "   SELECT"
    320             "       pzPendingExp.*"
    321             "   FROM pzPendingExp"
     295            "       incoming.exp_name,"
     296            "       incoming.camera,"
     297            "       incoming.telescope,"
     298            "       \"run\""
     299            "   FROM incoming"
     300            "   LEFT JOIN pzDownloadExp"
     301            "       USING(exp_name, camera, telescope)"
    322302            "   WHERE"
    323             "       pzPendingExp.exp_name = '%s'"
    324             "       AND pzPendingExp.camera = '%s'"
    325             "       AND pzPendingExp.telescope = '%s'";
    326         if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
    327             // rollback
    328             if (!psDBRollback(config->dbh)) {
    329                 psError(PS_ERR_UNKNOWN, false, "database error");
    330             }
    331             psError(PS_ERR_UNKNOWN, false, "database error");
    332             return false;
    333         }
    334  
    335         // sanity check: we should have inserted only one row
    336         psU64 affected = psDBAffectedRows(config->dbh);
    337         if (psDBAffectedRows(config->dbh) != 1) {
    338             // rollback
    339             if (!psDBRollback(config->dbh)) {
    340                 psError(PS_ERR_UNKNOWN, false, "database error");
    341             }
    342             psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);
    343             return false;
    344         }
    345     }
    346  
    347     // remove the pzPendingExp entry for this exp (fileset)
    348     {
    349         char *query =
    350             "DELETE FROM pzPendingExp"
    351             " WHERE"
    352             "   exp_name = '%s'"
    353             "   AND camera = '%s'"
    354             "   AND telescope = '%s'";
    355         if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
    356             // rollback
    357             if (!psDBRollback(config->dbh)) {
    358                 psError(PS_ERR_UNKNOWN, false, "database error");
    359             }
    360             psError(PS_ERR_UNKNOWN, false, "database error");
    361             return false;
    362         }
    363  
    364         // sanity check: we should have removed only one row
    365         psU64 affected = psDBAffectedRows(config->dbh);
    366         if (psDBAffectedRows(config->dbh) != 1) {
    367             // rollback
    368             if (!psDBRollback(config->dbh)) {
    369                 psError(PS_ERR_UNKNOWN, false, "database error");
    370             }
    371             psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);
     303            "       pzDownloadExp.exp_name is NULL"
     304            "       AND pzDownloadExp.camera is NULL"
     305            "       AND pzDownloadExp.telescope is NULL"
     306            "   GROUP BY"
     307            "       incoming.exp_name,"
     308            "       incoming.camera,"
     309            "       incoming.telescope";
     310
     311        if (!p_psDBRunQuery(config->dbh, query)) {
     312            // rollback
     313            if (!psDBRollback(config->dbh)) {
     314                psError(PS_ERR_UNKNOWN, false, "database error");
     315            }
     316            psError(PS_ERR_UNKNOWN, false, "database error");
    372317            return false;
    373318        }
  • trunk/ippTools/src/pztool.c

    r16509 r16588  
    4545static psArray *pzGetPendingCameras(pxConfig *config);
    4646static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
     47static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state);
    4748
    4849# define MODECASE(caseName, func) \
     
    204205            "SELECT"
    205206            "   summitExp.*"
    206             " FROM pzPendingExp"
    207             " JOIN summitExp"
     207            " FROM summitExp"
     208            " LEFT JOIN pzDownloadExp"
    208209            "   USING(exp_name, camera, telescope)"
     210            " WHERE"
     211            "   pzDownloadExp.exp_name IS NULL"
     212            "   AND pzDownloadExp.camera IS NULL"
     213            "   AND pzDownloadExp.telescope IS NULL"
    209214        );
    210215
    211216    if (config->where) {
    212         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzPendingExp");
     217        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadExp");
    213218        psStringAppend(&query, " AND %s", whereClause);
    214219        psFree(whereClause);
     
    281286
    282287        if (config->where) {
    283             psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzPendingImfile");
     288            psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile");
    284289            psStringAppend(&query, " AND %s", whereClause);
    285290            psFree(whereClause);
     
    355360
    356361    // need to know exp_name, camera, telescope, class, class_id (to find the
    357     // pzPendingImfile entry and the URI for the newImfile entry.
     362    // pzDownloadImfile entry and the URI for the newImfile entry.
    358363
    359364    // start a transaction so it's all rows or nothing
     
    363368    }
    364369
    365     // cp the imfile into pzDoneImfile
     370    // cp the imfile into pzDownloadImfile
    366371    {
    367372        char *query =
    368             "INSERT INTO pzDoneImfile"
     373            "INSERT INTO pzDownloadImfile"
    369374            "   SELECT"
    370             "       pzPendingImfile.*,"
     375            "       exp_name,"
     376            "       camera,"
     377            "       telescope,"
     378            "       class,"
     379            "       class_id,"
    371380            "       '%s'," // uri of downloaded file
    372381            "       '%d'" // fault code
    373             "   FROM pzPendingImfile"
     382            "   FROM summitImfile"
    374383            "   WHERE"
    375             "       pzPendingImfile.exp_name = '%s'"
    376             "       AND pzPendingImfile.camera = '%s'"
    377             "       AND pzPendingImfile.telescope = '%s'"
    378             "       AND pzPendingImfile.class = '%s'"
    379             "       AND pzPendingImfile.class_id = '%s'";
     384            "       summitImfile.exp_name = '%s'"
     385            "       AND summitImfile.camera = '%s'"
     386            "       AND summitImfile.telescope = '%s'"
     387            "       AND summitImfile.class = '%s'"
     388            "       AND summitImfile.class_id = '%s'";
    380389
    381390        if (!p_psDBRunQuery(config->dbh, query, uri, code, exp_name, camera, telescope, class, class_id)) {
     
    400409    }
    401410
    402     // removve the entry from pzPendingImfile
    403     {
    404         char *query =
    405             "DELETE FROM pzPendingImfile"
    406             "   WHERE"
    407             "       pzPendingImfile.exp_name = '%s'"
    408             "       AND pzPendingImfile.camera = '%s'"
    409             "       AND pzPendingImfile.telescope = '%s'"
    410             "       AND pzPendingImfile.class = '%s'"
    411             "       AND pzPendingImfile.class_id = '%s'";
    412 
    413         if (!p_psDBRunQuery(config->dbh, query, exp_name, camera, telescope, class, class_id)) {
    414             // rollback
    415             if (!psDBRollback(config->dbh)) {
    416                 psError(PS_ERR_UNKNOWN, false, "database error");
    417             }
     411    if (!copydoneCompleteExp(config)) {
     412        // rollback
     413        if (!psDBRollback(config->dbh)) {
    418414            psError(PS_ERR_UNKNOWN, false, "database error");
    419             return false;
    420         }
    421 
    422         // sanity check: we should have removed only one row
    423         psU64 affected = psDBAffectedRows(config->dbh);
    424         if (psDBAffectedRows(config->dbh) != 1) {
    425             // rollback
    426             if (!psDBRollback(config->dbh)) {
    427                 psError(PS_ERR_UNKNOWN, false, "database error");
    428             }
    429             psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);
    430             return false;
    431         }
     415        }
     416        psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");
     417        return false;
    432418    }
    433419
     
    439425        }
    440426        psError(PS_ERR_UNKNOWN, false, "database error");
    441         return false;
    442     }
    443 
    444     if (!copydoneCompleteExp(config)) {
    445         psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");
    446427        return false;
    447428    }
     
    493474    }
    494475
    495     // start a transaction so all newExp's can start off with a state of run
    496     if (!psDBTransaction(config->dbh)) {
    497         psError(PS_ERR_UNKNOWN, false, "database error");
    498         psFree(output);
    499         return false;
    500     }
    501 
    502 
    503476   for (long i = 0; i < psArrayLength(output); i++) {
    504477        psMetadata *row = output->data[i];
    505478
    506         pzDoneExpRow *doneExp = pzDoneExpObjectFromMetadata(row);
     479        pzDownloadExpRow *doneExp = pzDownloadExpObjectFromMetadata(row);
    507480
    508481        if (!newExpInsert(config->dbh,
     
    521494                )
    522495        ) {
    523             // rollback
    524             if (!psDBRollback(config->dbh)) {
    525                 psError(PS_ERR_UNKNOWN, false, "database error");
    526             }
    527496            psError(PS_ERR_UNKNOWN, false, "database error");
    528497            psFree(doneExp);
     
    533502        psS64 exp_id = psDBLastInsertID(config->dbh);
    534503
    535         // insert new all pzDoneImfile for the exp into newImfile
     504        // insert newImfiles
    536505        {
    537506            char *query =
     
    539508                "   SElECT"
    540509                "       %" PRId64 "," // exp_id
    541                 "       pzDoneImfile.class_id," // tmp_class_id
    542                 "       pzDoneImfile.uri" // uri
    543                 "   FROM pzDoneImfile"
     510                "       pzDownloadImfile.class_id," // tmp_class_id
     511                "       pzDownloadImfile.uri" // uri
     512                "   FROM pzDownloadImfile"
    544513                "   WHERE"
    545                 "       pzDoneImfile.exp_name = '%s'"
    546                 "       AND pzDoneImfile.camera = '%s'"
    547                 "       AND pzDoneImfile.telescope = '%s'";
     514                "       pzDownloadImfile.exp_name = '%s'"
     515                "       AND pzDownloadImfile.camera = '%s'"
     516                "       AND pzDownloadImfile.telescope = '%s'";
    548517
    549518            if (!p_psDBRunQuery(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) {
    550                 // rollback
    551                 if (!psDBRollback(config->dbh)) {
    552                     psError(PS_ERR_UNKNOWN, false, "database error");
    553                 }
    554519                psError(PS_ERR_UNKNOWN, false, "database error");
    555520                psFree(doneExp);
     
    561526            psU64 affected = psDBAffectedRows(config->dbh);
    562527            if (psDBAffectedRows(config->dbh) < 1) {
    563                 // rollback
    564                 if (!psDBRollback(config->dbh)) {
    565                     psError(PS_ERR_UNKNOWN, false, "database error");
    566                 }
    567528                psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
    568529                psFree(doneExp);
     
    572533        }
    573534
     535        // set pzDownloadExp.state to 'stop'
     536        if (!pzDownloadExpSetState(config, doneExp->exp_name, doneExp->camera, doneExp->telescope, "stop")) {
     537            psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", doneExp->exp_name, doneExp->camera, doneExp->telescope);
     538            psFree(doneExp);
     539            psFree(output);
     540            return false;
     541        }
     542
    574543        psFree(doneExp);
    575544    }
     
    577546    psFree(output);
    578547
    579     if (!psDBCommit(config->dbh)) {
    580         psError(PS_ERR_UNKNOWN, false, "database error");
    581         return false;
    582     }
    583 
    584548    return true;
    585549}
     
    588552{
    589553    // get a list of cameras we've seen exps for
    590     if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM pzPendingImfile")) {
     554    if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM pzDownloadExp")) {
    591555        psError(PS_ERR_UNKNOWN, false, "database error");
    592556        return false;
     
    666630    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    667631
    668     psString query = psStringCopy("SELECT * FROM pzDoneImfile");
     632    psString query = psStringCopy("SELECT * FROM pzDownloadImfile");
    669633
    670634    if (faulted) {
    671635        // list only faulted rows
    672         psStringAppend(&query, " %s", "WHERE pzDoneImfile.fault != 0");
     636        psStringAppend(&query, " %s", "WHERE pzDownloadImfile.fault != 0");
    673637    } else {
    674638        // don't list faulted rows
    675         psStringAppend(&query, " %s", "WHERE pzDoneImfile.fault = 0");
     639        psStringAppend(&query, " %s", "WHERE pzDownloadImfile.fault = 0");
    676640    }
    677641
    678642    if (psListLength(where->list)) {
    679         psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDoneImfile");
     643        psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadImfile");
    680644        psStringAppend(&query, " AND %s", whereClause);
    681645        psFree(whereClause);
     
    727691    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
    728692
    729     if (!pxSetFaultCode(config->dbh, "pzDoneImfile", config->where, code)) {
     693    if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", config->where, code)) {
    730694        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    731695        return false;
     
    747711
    748712    if (config->where) {
    749         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDoneImfile");
     713        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pzDownloadImfile");
    750714        psStringAppend(&query, " AND %s", whereClause);
    751715        psFree(whereClause);
     
    768732
    769733
     734static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
     735{
     736    PS_ASSERT_PTR_NON_NULL(state, false);
     737
     738    // check that state is a valid string value
     739    if (!(
     740            (strncmp(state, "run", 4) == 0)
     741            || (strncmp(state, "stop", 5) == 0)
     742            || (strncmp(state, "reg", 4) == 0)
     743        )
     744    ) {
     745        psError(PS_ERR_UNKNOWN, false,
     746                "invalid pzDownloadExp state: %s", state);
     747        return false;
     748    }
     749
     750    char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'";
     751    if (!p_psDBRunQuery(config->dbh, query, state, exp_name, camera, telescope)) {
     752        psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope);
     753        return false;
     754    }
     755
     756    return true;
     757}
     758
     759
    770760#if 0
    771761static psArray *pzArrayAddArray(psArray *array, psArray *input)
Note: See TracChangeset for help on using the changeset viewer.