IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2007, 5:58:26 PM (19 years ago)
Author:
jhoblitt
Message:

VERSION 1.1.7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippdb/src/ippdb.c

    r11809 r11820  
    6969#define P5INPUTSCFILE_TABLE_NAME "p5InputScfile"
    7070#define P5DIFFSCFILE_TABLE_NAME "p5DiffScfile"
     71#define P6RUN_TABLE_NAME "p6Run"
    7172#define MAX_STRING_LENGTH 1024
    7273
     
    35233524static void rawExpRowFree(rawExpRow *object);
    35243525
    3525 rawExpRow *rawExpRowAlloc(const char *exp_tag, const char *exp_id, const char *camera, const char *telescope, psTime* dateobs, const char *exp_type, psS32 imfiles, const char *workdir, const char *filter, psF32 airmass, psF64 ra, psF64 decl, psF32 exp_time, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF64 alt, psF64 az, psF32 ccd_temp, psF64 posang, const char *object, psS16 fault)
     3526rawExpRow *rawExpRowAlloc(const char *exp_tag, const char *exp_id, const char *camera, const char *telescope, psTime* dateobs, const char *exp_type, psS32 imfiles, const char *workdir, const char *filter, psF32 airmass, psF64 ra, psF64 decl, psF32 exp_time, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF64 alt, psF64 az, psF32 ccd_temp, psF64 posang, const char *object, psF32 solang, psS16 fault)
    35263527{
    35273528    rawExpRow       *_object;
     
    35513552    _object->posang = posang;
    35523553    _object->object = psStringCopy(object);
     3554    _object->solang = solang;
    35533555    _object->fault = fault;
    35543556
     
    36773679        return false;
    36783680    }
     3681    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang", PS_DATA_F32, NULL, 0.0)) {
     3682        psError(PS_ERR_UNKNOWN, false, "failed to add item solang");
     3683        psFree(md);
     3684        return false;
     3685    }
    36793686    if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, "Key NOT NULL", 0)) {
    36803687        psError(PS_ERR_UNKNOWN, false, "failed to add item fault");
     
    36953702}
    36963703
    3697 bool rawExpInsert(psDB * dbh, const char *exp_tag, const char *exp_id, const char *camera, const char *telescope, psTime* dateobs, const char *exp_type, psS32 imfiles, const char *workdir, const char *filter, psF32 airmass, psF64 ra, psF64 decl, psF32 exp_time, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF64 alt, psF64 az, psF32 ccd_temp, psF64 posang, const char *object, psS16 fault)
     3704bool rawExpInsert(psDB * dbh, const char *exp_tag, const char *exp_id, const char *camera, const char *telescope, psTime* dateobs, const char *exp_type, psS32 imfiles, const char *workdir, const char *filter, psF32 airmass, psF64 ra, psF64 decl, psF32 exp_time, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF64 alt, psF64 az, psF32 ccd_temp, psF64 posang, const char *object, psF32 solang, psS16 fault)
    36983705{
    36993706    psMetadata *md = psMetadataAlloc();
     
    38003807    if (!psMetadataAdd(md, PS_LIST_TAIL, "object", PS_DATA_STRING, NULL, object)) {
    38013808        psError(PS_ERR_UNKNOWN, false, "failed to add item object");
     3809        psFree(md);
     3810        return false;
     3811    }
     3812    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang", PS_DATA_F32, NULL, solang)) {
     3813        psError(PS_ERR_UNKNOWN, false, "failed to add item solang");
    38023814        psFree(md);
    38033815        return false;
     
    38313843bool rawExpInsertObject(psDB *dbh, rawExpRow *object)
    38323844{
    3833     return rawExpInsert(dbh, object->exp_tag, object->exp_id, object->camera, object->telescope, object->dateobs, object->exp_type, object->imfiles, object->workdir, object->filter, object->airmass, object->ra, object->decl, object->exp_time, object->bg, object->bg_stdev, object->bg_mean_stdev, object->alt, object->az, object->ccd_temp, object->posang, object->object, object->fault);
     3845    return rawExpInsert(dbh, object->exp_tag, object->exp_id, object->camera, object->telescope, object->dateobs, object->exp_type, object->imfiles, object->workdir, object->filter, object->airmass, object->ra, object->decl, object->exp_time, object->bg, object->bg_stdev, object->bg_mean_stdev, object->alt, object->az, object->ccd_temp, object->posang, object->object, object->solang, object->fault);
    38343846}
    38353847
     
    40094021        return false;
    40104022    }
     4023    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang", PS_DATA_F32, NULL, object->solang)) {
     4024        psError(PS_ERR_UNKNOWN, false, "failed to add item solang");
     4025        psFree(md);
     4026        return false;
     4027    }
    40114028    if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, object->fault)) {
    40124029        psError(PS_ERR_UNKNOWN, false, "failed to add item fault");
     
    41284145        return false;
    41294146    }
     4147    psF32 solang = psMetadataLookupF32(&status, md, "solang");
     4148    if (!status) {
     4149        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item solang");
     4150        return false;
     4151    }
    41304152    psS16 fault = psMetadataLookupS16(&status, md, "fault");
    41314153    if (!status) {
     
    41344156    }
    41354157
    4136     return rawExpRowAlloc(exp_tag, exp_id, camera, telescope, dateobs, exp_type, imfiles, workdir, filter, airmass, ra, decl, exp_time, bg, bg_stdev, bg_mean_stdev, alt, az, ccd_temp, posang, object, fault);
     4158    return rawExpRowAlloc(exp_tag, exp_id, camera, telescope, dateobs, exp_type, imfiles, workdir, filter, airmass, ra, decl, exp_time, bg, bg_stdev, bg_mean_stdev, alt, az, ccd_temp, posang, object, solang, fault);
    41374159}
    41384160psArray *rawExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    83348356static void detRunRowFree(detRunRow *object);
    83358357
    8336 detRunRow *detRunRowAlloc(psS32 det_id, psS32 iteration, const char *det_type, const char *mode, const char *state, const char *workdir, const char *camera, const char *telescope, const char *exp_type, const char *filter, psF32 airmass_min, psF32 airmass_max, psF32 exp_time_min, psF32 exp_time_max, psF32 ccd_temp_min, psF32 ccd_temp_max, psF64 posang_min, psF64 posang_max, psTime* registered, psTime* time_begin, psTime* time_end, psTime* use_begin, psTime* use_end)
     8358detRunRow *detRunRowAlloc(psS32 det_id, psS32 iteration, const char *det_type, const char *mode, const char *state, const char *workdir, const char *camera, const char *telescope, const char *exp_type, const char *filter, psF32 airmass_min, psF32 airmass_max, psF32 exp_time_min, psF32 exp_time_max, psF32 ccd_temp_min, psF32 ccd_temp_max, psF64 posang_min, psF64 posang_max, psTime* registered, psTime* time_begin, psTime* time_end, psTime* use_begin, psTime* use_end, psF32 solang_min, psF32 solang_max, const char *label, psS32 parent)
    83378359{
    83388360    detRunRow       *_object;
     
    83648386    _object->use_begin = psTimeCopy(use_begin);
    83658387    _object->use_end = psTimeCopy(use_end);
     8388    _object->solang_min = solang_min;
     8389    _object->solang_max = solang_max;
     8390    _object->label = psStringCopy(label);
     8391    _object->parent = parent;
    83668392
    83678393    return _object;
     
    83838409    psFree(object->use_begin);
    83848410    psFree(object->use_end);
     8411    psFree(object->label);
    83858412}
    83868413
     
    85038530        return false;
    85048531    }
     8532    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_min", PS_DATA_F32, NULL, 0.0)) {
     8533        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_min");
     8534        psFree(md);
     8535        return false;
     8536    }
     8537    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_max", PS_DATA_F32, NULL, 0.0)) {
     8538        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_max");
     8539        psFree(md);
     8540        return false;
     8541    }
     8542    if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, "key", "64")) {
     8543        psError(PS_ERR_UNKNOWN, false, "failed to add item label");
     8544        psFree(md);
     8545        return false;
     8546    }
     8547    if (!psMetadataAdd(md, PS_LIST_TAIL, "parent", PS_DATA_S32, "Key", 0)) {
     8548        psError(PS_ERR_UNKNOWN, false, "failed to add item parent");
     8549        psFree(md);
     8550        return false;
     8551    }
    85058552
    85068553    bool status = psDBCreateTable(dbh, DETRUN_TABLE_NAME, md);
     
    85168563}
    85178564
    8518 bool detRunInsert(psDB * dbh, psS32 det_id, psS32 iteration, const char *det_type, const char *mode, const char *state, const char *workdir, const char *camera, const char *telescope, const char *exp_type, const char *filter, psF32 airmass_min, psF32 airmass_max, psF32 exp_time_min, psF32 exp_time_max, psF32 ccd_temp_min, psF32 ccd_temp_max, psF64 posang_min, psF64 posang_max, psTime* registered, psTime* time_begin, psTime* time_end, psTime* use_begin, psTime* use_end)
     8565bool detRunInsert(psDB * dbh, psS32 det_id, psS32 iteration, const char *det_type, const char *mode, const char *state, const char *workdir, const char *camera, const char *telescope, const char *exp_type, const char *filter, psF32 airmass_min, psF32 airmass_max, psF32 exp_time_min, psF32 exp_time_max, psF32 ccd_temp_min, psF32 ccd_temp_max, psF64 posang_min, psF64 posang_max, psTime* registered, psTime* time_begin, psTime* time_end, psTime* use_begin, psTime* use_end, psF32 solang_min, psF32 solang_max, const char *label, psS32 parent)
    85198566{
    85208567    psMetadata *md = psMetadataAlloc();
     
    86318678    if (!psMetadataAdd(md, PS_LIST_TAIL, "use_end", PS_DATA_TIME, NULL, use_end)) {
    86328679        psError(PS_ERR_UNKNOWN, false, "failed to add item use_end");
     8680        psFree(md);
     8681        return false;
     8682    }
     8683    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_min", PS_DATA_F32, NULL, solang_min)) {
     8684        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_min");
     8685        psFree(md);
     8686        return false;
     8687    }
     8688    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_max", PS_DATA_F32, NULL, solang_max)) {
     8689        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_max");
     8690        psFree(md);
     8691        return false;
     8692    }
     8693    if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, label)) {
     8694        psError(PS_ERR_UNKNOWN, false, "failed to add item label");
     8695        psFree(md);
     8696        return false;
     8697    }
     8698    if (!psMetadataAdd(md, PS_LIST_TAIL, "parent", PS_DATA_S32, NULL, parent)) {
     8699        psError(PS_ERR_UNKNOWN, false, "failed to add item parent");
    86338700        psFree(md);
    86348701        return false;
     
    86578724bool detRunInsertObject(psDB *dbh, detRunRow *object)
    86588725{
    8659     return detRunInsert(dbh, object->det_id, object->iteration, object->det_type, object->mode, object->state, object->workdir, object->camera, object->telescope, object->exp_type, object->filter, object->airmass_min, object->airmass_max, object->exp_time_min, object->exp_time_max, object->ccd_temp_min, object->ccd_temp_max, object->posang_min, object->posang_max, object->registered, object->time_begin, object->time_end, object->use_begin, object->use_end);
     8726    return detRunInsert(dbh, object->det_id, object->iteration, object->det_type, object->mode, object->state, object->workdir, object->camera, object->telescope, object->exp_type, object->filter, object->airmass_min, object->airmass_max, object->exp_time_min, object->exp_time_max, object->ccd_temp_min, object->ccd_temp_max, object->posang_min, object->posang_max, object->registered, object->time_begin, object->time_end, object->use_begin, object->use_end, object->solang_min, object->solang_max, object->label, object->parent);
    86608727}
    86618728
     
    88458912        return false;
    88468913    }
     8914    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_min", PS_DATA_F32, NULL, object->solang_min)) {
     8915        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_min");
     8916        psFree(md);
     8917        return false;
     8918    }
     8919    if (!psMetadataAdd(md, PS_LIST_TAIL, "solang_max", PS_DATA_F32, NULL, object->solang_max)) {
     8920        psError(PS_ERR_UNKNOWN, false, "failed to add item solang_max");
     8921        psFree(md);
     8922        return false;
     8923    }
     8924    if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, object->label)) {
     8925        psError(PS_ERR_UNKNOWN, false, "failed to add item label");
     8926        psFree(md);
     8927        return false;
     8928    }
     8929    if (!psMetadataAdd(md, PS_LIST_TAIL, "parent", PS_DATA_S32, NULL, object->parent)) {
     8930        psError(PS_ERR_UNKNOWN, false, "failed to add item parent");
     8931        psFree(md);
     8932        return false;
     8933    }
    88478934
    88488935
     
    89699056        return false;
    89709057    }
    8971 
    8972     return detRunRowAlloc(det_id, iteration, det_type, mode, state, workdir, camera, telescope, exp_type, filter, airmass_min, airmass_max, exp_time_min, exp_time_max, ccd_temp_min, ccd_temp_max, posang_min, posang_max, registered, time_begin, time_end, use_begin, use_end);
     9058    psF32 solang_min = psMetadataLookupF32(&status, md, "solang_min");
     9059    if (!status) {
     9060        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item solang_min");
     9061        return false;
     9062    }
     9063    psF32 solang_max = psMetadataLookupF32(&status, md, "solang_max");
     9064    if (!status) {
     9065        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item solang_max");
     9066        return false;
     9067    }
     9068    char* label = psMetadataLookupPtr(&status, md, "label");
     9069    if (!status) {
     9070        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item label");
     9071        return false;
     9072    }
     9073    psS32 parent = psMetadataLookupS32(&status, md, "parent");
     9074    if (!status) {
     9075        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item parent");
     9076        return false;
     9077    }
     9078
     9079    return detRunRowAlloc(det_id, iteration, det_type, mode, state, workdir, camera, telescope, exp_type, filter, airmass_min, airmass_max, exp_time_min, exp_time_max, ccd_temp_min, ccd_temp_max, posang_min, posang_max, registered, time_begin, time_end, use_begin, use_end, solang_min, solang_max, label, parent);
    89739080}
    89749081psArray *detRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    1385513962        return false;
    1385613963    }
    13857     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
     13964    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Key", 0)) {
    1385813965        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    1385913966        psFree(md);
    1386013967        return false;
    1386113968    }
    13862     if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Primary Key", 0)) {
     13969    if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Key", 0)) {
    1386313970        psError(PS_ERR_UNKNOWN, false, "failed to add item magiced");
    1386413971        psFree(md);
     
    1458614693        return false;
    1458714694    }
    14588     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
     14695    if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Key", "64")) {
    1458914696        psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    1459014697        psFree(md);
    1459114698        return false;
    1459214699    }
    14593     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
     14700    if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Key", 0)) {
    1459414701        psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    1459514702        psFree(md);
     
    1530415411static void p5InputScfileRowFree(p5InputScfileRow *object);
    1530515412
    15306 p5InputScfileRow *p5InputScfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind, bool template)
     15413p5InputScfileRow *p5InputScfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)
    1530715414{
    1530815415    p5InputScfileRow *_object;
     
    1531515422    _object->skycell_id = psStringCopy(skycell_id);
    1531615423    _object->tess_id = psStringCopy(tess_id);
    15317     _object->exp_tag = psStringCopy(exp_tag);
    15318     _object->p3_version = p3_version;
    1531915424    _object->kind = psStringCopy(kind);
    1532015425    _object->template = template;
     
    1532715432    psFree(object->skycell_id);
    1532815433    psFree(object->tess_id);
    15329     psFree(object->exp_tag);
    1533015434    psFree(object->kind);
    1533115435}
     
    1535415458        return false;
    1535515459    }
    15356     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) {
    15357         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15358         psFree(md);
    15359         return false;
    15360     }
    15361     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) {
    15362         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15363         psFree(md);
    15364         return false;
    15365     }
    1536615460    if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) {
    1536715461        psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
     
    1538715481}
    1538815482
    15389 bool p5InputScfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind, bool template)
     15483bool p5InputScfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)
    1539015484{
    1539115485    psMetadata *md = psMetadataAlloc();
     
    1540715501    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
    1540815502        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
    15409         psFree(md);
    15410         return false;
    15411     }
    15412     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {
    15413         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15414         psFree(md);
    15415         return false;
    15416     }
    15417     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {
    15418         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    1541915503        psFree(md);
    1542015504        return false;
     
    1545315537bool p5InputScfileInsertObject(psDB *dbh, p5InputScfileRow *object)
    1545415538{
    15455     return p5InputScfileInsert(dbh, object->p5_id, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind, object->template);
     15539    return p5InputScfileInsert(dbh, object->p5_id, object->p4_id, object->skycell_id, object->tess_id, object->kind, object->template);
    1545615540}
    1545715541
     
    1554615630        return false;
    1554715631    }
    15548     if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {
    15549         psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    15550         psFree(md);
    15551         return false;
    15552     }
    15553     if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {
    15554         psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");
    15555         psFree(md);
    15556         return false;
    15557     }
    1555815632    if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) {
    1555915633        psError(PS_ERR_UNKNOWN, false, "failed to add item kind");
     
    1559515669        return false;
    1559615670    }
    15597     char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");
    15598     if (!status) {
    15599         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");
    15600         return false;
    15601     }
    15602     psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");
    15603     if (!status) {
    15604         psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");
    15605         return false;
    15606     }
    1560715671    char* kind = psMetadataLookupPtr(&status, md, "kind");
    1560815672    if (!status) {
     
    1561615680    }
    1561715681
    15618     return p5InputScfileRowAlloc(p5_id, p4_id, skycell_id, tess_id, exp_tag, p3_version, kind, template);
     15682    return p5InputScfileRowAlloc(p5_id, p4_id, skycell_id, tess_id, kind, template);
    1561915683}
    1562015684psArray *p5InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     
    1610716171    return true;
    1610816172}
     16173static void p6RunRowFree(p6RunRow *object);
     16174
     16175p6RunRow *p6RunRowAlloc(psS32 p6_id, const char *state, const char *workdir, psTime* registered)
     16176{
     16177    p6RunRow        *_object;
     16178
     16179    _object = psAlloc(sizeof(p6RunRow));
     16180    psMemSetDeallocator(_object, (psFreeFunc)p6RunRowFree);
     16181
     16182    _object->p6_id = p6_id;
     16183    _object->state = psStringCopy(state);
     16184    _object->workdir = psStringCopy(workdir);
     16185    _object->registered = psTimeCopy(registered);
     16186
     16187    return _object;
     16188}
     16189
     16190static void p6RunRowFree(p6RunRow *object)
     16191{
     16192    psFree(object->state);
     16193    psFree(object->workdir);
     16194    psFree(object->registered);
     16195}
     16196
     16197bool p6RunCreateTable(psDB *dbh)
     16198{
     16199    psMetadata *md = psMetadataAlloc();
     16200    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {
     16201        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16202        psFree(md);
     16203        return false;
     16204    }
     16205    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) {
     16206        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     16207        psFree(md);
     16208        return false;
     16209    }
     16210    if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) {
     16211        psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");
     16212        psFree(md);
     16213        return false;
     16214    }
     16215    if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) {
     16216        psError(PS_ERR_UNKNOWN, false, "failed to add item registered");
     16217        psFree(md);
     16218        return false;
     16219    }
     16220
     16221    bool status = psDBCreateTable(dbh, P6RUN_TABLE_NAME, md);
     16222
     16223    psFree(md);
     16224
     16225    return status;
     16226}
     16227
     16228bool p6RunDropTable(psDB *dbh)
     16229{
     16230    return psDBDropTable(dbh, P6RUN_TABLE_NAME);
     16231}
     16232
     16233bool p6RunInsert(psDB * dbh, psS32 p6_id, const char *state, const char *workdir, psTime* registered)
     16234{
     16235    psMetadata *md = psMetadataAlloc();
     16236    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, p6_id)) {
     16237        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16238        psFree(md);
     16239        return false;
     16240    }
     16241    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {
     16242        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     16243        psFree(md);
     16244        return false;
     16245    }
     16246    if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) {
     16247        psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");
     16248        psFree(md);
     16249        return false;
     16250    }
     16251    if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) {
     16252        psError(PS_ERR_UNKNOWN, false, "failed to add item registered");
     16253        psFree(md);
     16254        return false;
     16255    }
     16256
     16257    bool status = psDBInsertOneRow(dbh, P6RUN_TABLE_NAME, md);
     16258    psFree(md);
     16259
     16260    return status;
     16261}
     16262
     16263long long p6RunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16264{
     16265    long long       deleted = 0;
     16266
     16267    long long count = psDBDeleteRows(dbh, P6RUN_TABLE_NAME, where, limit);
     16268    if (count < 0) {
     16269        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6Run");
     16270        return count;
     16271
     16272        deleted += count;
     16273    }
     16274
     16275    return deleted;
     16276}
     16277bool p6RunInsertObject(psDB *dbh, p6RunRow *object)
     16278{
     16279    return p6RunInsert(dbh, object->p6_id, object->state, object->workdir, object->registered);
     16280}
     16281
     16282bool p6RunInsertObjects(psDB *dbh, psArray *objects)
     16283{
     16284    for (long i = 0; i < psArrayLength(objects); i++) {
     16285        if (!p6RunInsertObject(dbh, objects->data[i])) {
     16286            return false;
     16287        }
     16288    }
     16289
     16290    return true;
     16291}
     16292
     16293bool p6RunInsertFits(psDB *dbh, const psFits *fits)
     16294{
     16295    psArray         *rowSet;
     16296
     16297    // move to (the first?) extension named  P6RUN_TABLE_NAME
     16298    if (!psFitsMoveExtName(fits, P6RUN_TABLE_NAME)) {
     16299        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6RUN_TABLE_NAME);
     16300        return false;
     16301    }
     16302
     16303    // check HDU type
     16304    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     16305        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     16306        return false;
     16307    }
     16308
     16309    // read fits table
     16310    rowSet = psFitsReadTable(fits);
     16311    if (!rowSet) {
     16312        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     16313        psFree(rowSet);
     16314        return false;
     16315    }
     16316
     16317    if (!psDBInsertRows(dbh, P6RUN_TABLE_NAME, rowSet)) {
     16318        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     16319        psFree(rowSet);
     16320        return false;
     16321    }
     16322
     16323    psFree(rowSet);
     16324
     16325    return true;
     16326}
     16327
     16328bool p6RunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     16329{
     16330    psArray         *rowSet;
     16331
     16332    rowSet = psDBSelectRows(dbh, P6RUN_TABLE_NAME, where, limit);
     16333    if (!rowSet) {
     16334        return false;
     16335    }
     16336
     16337    // output to fits
     16338    if (!psFitsWriteTable(fits, NULL, rowSet, P6RUN_TABLE_NAME)) {
     16339        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     16340        psFree(rowSet);
     16341        return false;
     16342    }
     16343
     16344    psFree(rowSet);
     16345
     16346    return true;
     16347}
     16348
     16349psMetadata *p6RunMetadataFromObject(const p6RunRow *object)
     16350{
     16351    psMetadata *md = psMetadataAlloc();
     16352    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, object->p6_id)) {
     16353        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16354        psFree(md);
     16355        return false;
     16356    }
     16357    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {
     16358        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     16359        psFree(md);
     16360        return false;
     16361    }
     16362    if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) {
     16363        psError(PS_ERR_UNKNOWN, false, "failed to add item workdir");
     16364        psFree(md);
     16365        return false;
     16366    }
     16367    if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) {
     16368        psError(PS_ERR_UNKNOWN, false, "failed to add item registered");
     16369        psFree(md);
     16370        return false;
     16371    }
     16372
     16373
     16374    return md;
     16375}
     16376
     16377p6RunRow *p6RunObjectFromMetadata(psMetadata *md)
     16378{
     16379
     16380bool status = false;
     16381    psS32 p6_id = psMetadataLookupS32(&status, md, "p6_id");
     16382    if (!status) {
     16383        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p6_id");
     16384        return false;
     16385    }
     16386    char* state = psMetadataLookupPtr(&status, md, "state");
     16387    if (!status) {
     16388        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");
     16389        return false;
     16390    }
     16391    char* workdir = psMetadataLookupPtr(&status, md, "workdir");
     16392    if (!status) {
     16393        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir");
     16394        return false;
     16395    }
     16396    psTime* registered = psMetadataLookupPtr(&status, md, "registered");
     16397    if (!status) {
     16398        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered");
     16399        return false;
     16400    }
     16401
     16402    return p6RunRowAlloc(p6_id, state, workdir, registered);
     16403}
     16404psArray *p6RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16405{
     16406    psArray         *rowSet;
     16407    psArray         *returnSet;
     16408    psU64           i;
     16409
     16410    rowSet = psDBSelectRows(dbh, P6RUN_TABLE_NAME, where, limit);
     16411    if (!rowSet) {
     16412        return NULL;
     16413    }
     16414
     16415    // convert psMetadata rows to row objects
     16416
     16417    returnSet = psArrayAllocEmpty(rowSet->n);
     16418
     16419    for (i = 0; i < rowSet->n; i++) {
     16420        p6RunRow *object = p6RunObjectFromMetadata(rowSet->data[i]);
     16421        psArrayAdd(returnSet, 0, object);
     16422        psFree(object);
     16423    }
     16424
     16425    psFree(rowSet);
     16426
     16427    return returnSet;
     16428}
     16429bool p6RunDeleteObject(psDB *dbh, const p6RunRow *object)
     16430{
     16431    psMetadata *where = p6RunMetadataFromObject(object);
     16432    long long count = psDBDeleteRows(dbh, P6RUN_TABLE_NAME, where, 0);
     16433    psFree(where);
     16434    if (count < 0) {
     16435        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6Run");
     16436        return false;
     16437    }
     16438    if (count > 1) {
     16439        // XXX should this be a psAbort() instead?  It is possible that
     16440        // having an object match multiple rows was by design.
     16441        psError(PS_ERR_UNKNOWN, true, "p6RunRow object matched more then one row.  Check your database schema");
     16442        return false;
     16443    }
     16444
     16445    return true;
     16446}
     16447long long p6RunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     16448{
     16449    long long       deleted = 0;
     16450
     16451    for (long long i = 0; i < objects->n; i++) {
     16452        p6RunRow *object = objects->data[i];
     16453        psMetadata *where = p6RunMetadataFromObject(object);
     16454        long long count = psDBDeleteRows(dbh, P6RUN_TABLE_NAME, where, limit);
     16455        psFree(where);
     16456        if (count < 0) {
     16457            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6Run");
     16458            return count;
     16459        }
     16460
     16461        deleted += count;
     16462    }
     16463
     16464    return deleted;
     16465}
     16466bool p6RunPrintObjects(FILE *stream, psArray *objects, bool mdcf)
     16467{
     16468    PS_ASSERT_PTR_NON_NULL(objects, false);
     16469
     16470    psMetadata *output = psMetadataAlloc();
     16471    for (long i = 0; i < psArrayLength(objects); i++) {
     16472        psMetadata *md = p6RunMetadataFromObject(objects->data[i]);
     16473        if (!psMetadataAddMetadata(
     16474            output,
     16475            PS_LIST_TAIL,
     16476            P6RUN_TABLE_NAME,
     16477            PS_META_DUPLICATE_OK,
     16478            NULL,
     16479            md
     16480        )) {
     16481            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     16482            psFree(md);
     16483            psFree(output);
     16484            return false;
     16485        }
     16486        psFree(md);
     16487    }
     16488
     16489    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     16490        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     16491        psFree(output);
     16492    }
     16493    psFree(output);
     16494
     16495    return true;
     16496}
     16497bool p6RunPrintObject(FILE *stream, p6RunRow *object, bool mdcf)
     16498{
     16499    PS_ASSERT_PTR_NON_NULL(object, false);
     16500
     16501    psMetadata *md = p6RunMetadataFromObject(object);
     16502
     16503    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     16504        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     16505        psFree(md);
     16506    }
     16507
     16508    psFree(md);
     16509
     16510    return true;
     16511}
Note: See TracChangeset for help on using the changeset viewer.