IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10024 for trunk/ippTools/src


Ignore:
Timestamp:
Nov 16, 2006, 2:57:02 PM (20 years ago)
Author:
jhoblitt
Message:

complete support of the new database schema

File:
1 edited

Legend:

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

    r10021 r10024  
    139139    long imfiles = psArrayLength(newImfiles);
    140140
     141    // start a transaction so it's all rows or nothing
     142    if (!psDBTransaction(config->dbh)) {
     143        psError(PS_ERR_UNKNOWN, false, "database error");
     144        return false;
     145    }
     146
    141147    // if the fileset was empty (no files) then we can bail out early
    142148    if (imfiles == 0) {
     149        psFree(newImfiles);
     150
    143151        char *query =
    144152            "UPDATE summitExp"
     
    148156            " AND telescope = '%s'";
    149157        if (!p_psDBRunQuery(config->dbh, query, imfiles, filesetid, camera, telescope)) {
    150             psError(PS_ERR_UNKNOWN, false, "database error");
    151             return false;
    152         }
    153         psFree(newImfiles);
     158            // rollback
     159            if (!psDBRollback(config->dbh)) {
     160                psError(PS_ERR_UNKNOWN, false, "database error");
     161            }
     162            psError(PS_ERR_UNKNOWN, false, "database error");
     163            return false;
     164        }
     165
     166        // remove the pzPendingExp entry for this exp (fileset)
     167        {
     168            char *query =
     169                "DELETE FROM pzPendingExp"
     170                " WHERE"
     171                "   exp_id = '%s'"
     172                "   AND camera = '%s'"
     173                "   AND telescope = '%s'";
     174            if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
     175                // rollback
     176                if (!psDBRollback(config->dbh)) {
     177                    psError(PS_ERR_UNKNOWN, false, "database error");
     178                }
     179                psError(PS_ERR_UNKNOWN, false, "database error");
     180                return false;
     181            }
     182        }
     183
     184        // point of no return
     185        if (!psDBCommit(config->dbh)) {
     186            psError(PS_ERR_UNKNOWN, false, "database error");
     187            return false;
     188        }
     189
    154190        return true;
    155191    }
    156 
    157     // start a transaction so it's all rows or nothing
    158     if (!psDBTransaction(config->dbh)) {
    159         psError(PS_ERR_UNKNOWN, false, "database error");
    160         return false;
    161     }
    162192
    163193    // try not to insert duplicate pzPendingExp/pzPendingImfile entries
     
    179209    }
    180210
     211    // load the imfiles (files) into the temp table
    181212    {
    182213        char *query = "INSERT INTO incoming (exp_id, camera, telescope, bytes, md5sum, class, class_id, uri) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     
    206237    psFree(newImfiles);
    207238
     239    // queue the imfiles (files) in pzPendingImfile
    208240    {
    209241        char *query =
     
    238270    }
    239271
    240 
     272    // move imfiles (files) from the temp table into summitImfiles
    241273    {
    242274        char *query =
     
    271303    }
    272304
    273     // update summitExp.imfiles
     305    // update summitExp.imfiles (should have been NULL)
    274306    {
    275307        char *query =
    276308            "UPDATE summitExp"
    277309            " SET imfiles = (SELECT COUNT(*) FROM summitImfile"
    278             "   WHERE exp_id = '%s'"
     310            "   WHERE"
     311            "       exp_id = '%s'"
     312            "       AND camera = '%s'"
     313            "       AND telescope = '%s'"
     314            ")"
     315            " WHERE"
     316            "   exp_id = '%s'"
    279317            "   AND camera = '%s'"
    280             "   AND telescope = '%s'"
    281             ")"
    282             " WHERE exp_id = '%s'"
    283             " AND camera = '%s'"
    284             " AND telescope = '%s'";
     318            "   AND telescope = '%s'";
    285319        if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope, filesetid, camera, telescope)) {
    286             psError(PS_ERR_UNKNOWN, false, "database error");
    287             return false;
    288         }
    289     }
    290 
     320            // rollback
     321            if (!psDBRollback(config->dbh)) {
     322                psError(PS_ERR_UNKNOWN, false, "database error");
     323            }
     324            psError(PS_ERR_UNKNOWN, false, "database error");
     325            return false;
     326        }
     327    }
     328
     329    // remove the pzPendingExp entry for this exp (fileset)
     330    {
     331        char *query =
     332            "DELETE FROM pzPendingExp"
     333            " WHERE"
     334            "   exp_id = '%s'"
     335            "   AND camera = '%s'"
     336            "   AND telescope = '%s'";
     337        if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
     338            // rollback
     339            if (!psDBRollback(config->dbh)) {
     340                psError(PS_ERR_UNKNOWN, false, "database error");
     341            }
     342            psError(PS_ERR_UNKNOWN, false, "database error");
     343            return false;
     344        }
     345    }
     346
     347    // point of no return
    291348    if (!psDBCommit(config->dbh)) {
    292349        psError(PS_ERR_UNKNOWN, false, "database error");
Note: See TracChangeset for help on using the changeset viewer.