Changeset 11820 for trunk/ippdb/src/ippdb.c
- Timestamp:
- Feb 14, 2007, 5:58:26 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippdb/src/ippdb.c (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/src/ippdb.c
r11809 r11820 69 69 #define P5INPUTSCFILE_TABLE_NAME "p5InputScfile" 70 70 #define P5DIFFSCFILE_TABLE_NAME "p5DiffScfile" 71 #define P6RUN_TABLE_NAME "p6Run" 71 72 #define MAX_STRING_LENGTH 1024 72 73 … … 3523 3524 static void rawExpRowFree(rawExpRow *object); 3524 3525 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, ps S16 fault)3526 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, psF32 solang, psS16 fault) 3526 3527 { 3527 3528 rawExpRow *_object; … … 3551 3552 _object->posang = posang; 3552 3553 _object->object = psStringCopy(object); 3554 _object->solang = solang; 3553 3555 _object->fault = fault; 3554 3556 … … 3677 3679 return false; 3678 3680 } 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 } 3679 3686 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, "Key NOT NULL", 0)) { 3680 3687 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); … … 3695 3702 } 3696 3703 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, ps S16 fault)3704 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, psF32 solang, psS16 fault) 3698 3705 { 3699 3706 psMetadata *md = psMetadataAlloc(); … … 3800 3807 if (!psMetadataAdd(md, PS_LIST_TAIL, "object", PS_DATA_STRING, NULL, object)) { 3801 3808 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"); 3802 3814 psFree(md); 3803 3815 return false; … … 3831 3843 bool rawExpInsertObject(psDB *dbh, rawExpRow *object) 3832 3844 { 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); 3834 3846 } 3835 3847 … … 4009 4021 return false; 4010 4022 } 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 } 4011 4028 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, object->fault)) { 4012 4029 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); … … 4128 4145 return false; 4129 4146 } 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 } 4130 4152 psS16 fault = psMetadataLookupS16(&status, md, "fault"); 4131 4153 if (!status) { … … 4134 4156 } 4135 4157 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); 4137 4159 } 4138 4160 psArray *rawExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 8334 8356 static void detRunRowFree(detRunRow *object); 8335 8357 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 )8358 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, psF32 solang_min, psF32 solang_max, const char *label, psS32 parent) 8337 8359 { 8338 8360 detRunRow *_object; … … 8364 8386 _object->use_begin = psTimeCopy(use_begin); 8365 8387 _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; 8366 8392 8367 8393 return _object; … … 8383 8409 psFree(object->use_begin); 8384 8410 psFree(object->use_end); 8411 psFree(object->label); 8385 8412 } 8386 8413 … … 8503 8530 return false; 8504 8531 } 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 } 8505 8552 8506 8553 bool status = psDBCreateTable(dbh, DETRUN_TABLE_NAME, md); … … 8516 8563 } 8517 8564 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 )8565 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, psF32 solang_min, psF32 solang_max, const char *label, psS32 parent) 8519 8566 { 8520 8567 psMetadata *md = psMetadataAlloc(); … … 8631 8678 if (!psMetadataAdd(md, PS_LIST_TAIL, "use_end", PS_DATA_TIME, NULL, use_end)) { 8632 8679 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"); 8633 8700 psFree(md); 8634 8701 return false; … … 8657 8724 bool detRunInsertObject(psDB *dbh, detRunRow *object) 8658 8725 { 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); 8660 8727 } 8661 8728 … … 8845 8912 return false; 8846 8913 } 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 } 8847 8934 8848 8935 … … 8969 9056 return false; 8970 9057 } 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); 8973 9080 } 8974 9081 psArray *detRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 13855 13962 return false; 13856 13963 } 13857 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, " PrimaryKey", 0)) {13964 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Key", 0)) { 13858 13965 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13859 13966 psFree(md); 13860 13967 return false; 13861 13968 } 13862 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, " PrimaryKey", 0)) {13969 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Key", 0)) { 13863 13970 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 13864 13971 psFree(md); … … 14586 14693 return false; 14587 14694 } 14588 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, " PrimaryKey", "64")) {14695 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Key", "64")) { 14589 14696 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14590 14697 psFree(md); 14591 14698 return false; 14592 14699 } 14593 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, " PrimaryKey", 0)) {14700 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Key", 0)) { 14594 14701 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14595 14702 psFree(md); … … 15304 15411 static void p5InputScfileRowFree(p5InputScfileRow *object); 15305 15412 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)15413 p5InputScfileRow *p5InputScfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 15307 15414 { 15308 15415 p5InputScfileRow *_object; … … 15315 15422 _object->skycell_id = psStringCopy(skycell_id); 15316 15423 _object->tess_id = psStringCopy(tess_id); 15317 _object->exp_tag = psStringCopy(exp_tag);15318 _object->p3_version = p3_version;15319 15424 _object->kind = psStringCopy(kind); 15320 15425 _object->template = template; … … 15327 15432 psFree(object->skycell_id); 15328 15433 psFree(object->tess_id); 15329 psFree(object->exp_tag);15330 15434 psFree(object->kind); 15331 15435 } … … 15354 15458 return false; 15355 15459 } 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 }15366 15460 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) { 15367 15461 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); … … 15387 15481 } 15388 15482 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)15483 bool p5InputScfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 15390 15484 { 15391 15485 psMetadata *md = psMetadataAlloc(); … … 15407 15501 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 15408 15502 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");15419 15503 psFree(md); 15420 15504 return false; … … 15453 15537 bool p5InputScfileInsertObject(psDB *dbh, p5InputScfileRow *object) 15454 15538 { 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); 15456 15540 } 15457 15541 … … 15546 15630 return false; 15547 15631 } 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 }15558 15632 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) { 15559 15633 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); … … 15595 15669 return false; 15596 15670 } 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 }15607 15671 char* kind = psMetadataLookupPtr(&status, md, "kind"); 15608 15672 if (!status) { … … 15616 15680 } 15617 15681 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); 15619 15683 } 15620 15684 psArray *p5InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 16107 16171 return true; 16108 16172 } 16173 static void p6RunRowFree(p6RunRow *object); 16174 16175 p6RunRow *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 16190 static void p6RunRowFree(p6RunRow *object) 16191 { 16192 psFree(object->state); 16193 psFree(object->workdir); 16194 psFree(object->registered); 16195 } 16196 16197 bool 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 16228 bool p6RunDropTable(psDB *dbh) 16229 { 16230 return psDBDropTable(dbh, P6RUN_TABLE_NAME); 16231 } 16232 16233 bool 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 16263 long 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 } 16277 bool p6RunInsertObject(psDB *dbh, p6RunRow *object) 16278 { 16279 return p6RunInsert(dbh, object->p6_id, object->state, object->workdir, object->registered); 16280 } 16281 16282 bool 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 16293 bool 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 16328 bool 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 16349 psMetadata *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 16377 p6RunRow *p6RunObjectFromMetadata(psMetadata *md) 16378 { 16379 16380 bool 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 } 16404 psArray *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 } 16429 bool 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 } 16447 long 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 } 16466 bool 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 } 16497 bool 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.
