Changeset 10681
- Timestamp:
- Dec 12, 2006, 5:52:50 PM (20 years ago)
- Location:
- trunk/ippdb
- Files:
-
- 15 edited
-
Makefile.am (modified) (1 diff)
-
configure.ac (modified) (1 diff)
-
src/ippdb.c (modified) (2 diffs)
-
src/ippdb.h (modified) (2 diffs)
-
tests/alloc.c (modified) (1 diff)
-
tests/createtable.c (modified) (1 diff)
-
tests/dbcleanup.c (modified) (1 diff)
-
tests/dbsetup.c (modified) (1 diff)
-
tests/droptable.c (modified) (1 diff)
-
tests/insert.c (modified) (1 diff)
-
tests/insertfits.c (modified) (1 diff)
-
tests/insertobject.c (modified) (1 diff)
-
tests/metadatafromobject.c (modified) (1 diff)
-
tests/objectfrommetadata.c (modified) (1 diff)
-
tests/selectrowsfits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/Makefile.am
r10238 r10681 41 41 $(top_builddir)/docs/man/man3/detResidImfileRow.3 \ 42 42 $(top_builddir)/docs/man/man3/detResidExpRow.3 \ 43 $(top_builddir)/docs/man/man3/detRunSummaryRow.3 43 $(top_builddir)/docs/man/man3/detRunSummaryRow.3 \ 44 $(top_builddir)/docs/man/man3/p4RunRow.3 \ 45 $(top_builddir)/docs/man/man3/p4InputImfileRow.3 \ 46 $(top_builddir)/docs/man/man3/p4PWarpedImfileRow.3 \ 47 $(top_builddir)/docs/man/man3/p4PStackedImfileRow.3 \ 48 $(top_builddir)/docs/man/man3/p4PDiffImfileRow.3 \ 49 $(top_builddir)/docs/man/man3/p4PMagicMaskImfileRow.3 44 50 45 51 46 docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 :52 docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/p4RunRow.3 docs/man/man3/p4InputImfileRow.3 docs/man/man3/p4PWarpedImfileRow.3 docs/man/man3/p4PStackedImfileRow.3 docs/man/man3/p4PDiffImfileRow.3 docs/man/man3/p4PMagicMaskImfileRow.3: 47 53 $(DOXYGEN) 48 54 -
trunk/ippdb/configure.ac
r10449 r10681 7 7 AC_PREREQ(2.59) 8 8 9 AC_INIT([ippdb], [0.0.6 4], [pan-starrs.ifa.hawaii.edu])9 AC_INIT([ippdb], [0.0.65], [pan-starrs.ifa.hawaii.edu]) 10 10 AC_CONFIG_SRCDIR([ippdb.pc.in]) 11 11 -
trunk/ippdb/src/ippdb.c
r10449 r10681 63 63 #define DETRESIDEXP_TABLE_NAME "detResidExp" 64 64 #define DETRUNSUMMARY_TABLE_NAME "detRunSummary" 65 #define P4RUN_TABLE_NAME "p4Run" 66 #define P4INPUTIMFILE_TABLE_NAME "p4InputImfile" 67 #define P4PWARPEDIMFILE_TABLE_NAME "p4PWarpedImfile" 68 #define P4PSTACKEDIMFILE_TABLE_NAME "p4PStackedImfile" 69 #define P4PDIFFIMFILE_TABLE_NAME "p4PDiffImfile" 70 #define P4PMAGICMASKIMFILE_TABLE_NAME "p4PMagicMaskImfile" 65 71 #define MAX_STRING_LENGTH 1024 66 72 … … 13164 13170 return true; 13165 13171 } 13172 static void p4RunRowFree(p4RunRow *object); 13173 13174 p4RunRow *p4RunRowAlloc(psS32 p4_id, const char *survey_mode, const char *state, const char *filter, const char *skycell_id, const char *tess_id, psF64 ra, psF64 decl, const char *input_ss, const char *output_ss) 13175 { 13176 p4RunRow *_object; 13177 13178 _object = psAlloc(sizeof(p4RunRow)); 13179 psMemSetDeallocator(_object, (psFreeFunc)p4RunRowFree); 13180 13181 _object->p4_id = p4_id; 13182 _object->survey_mode = psStringCopy(survey_mode); 13183 _object->state = psStringCopy(state); 13184 _object->filter = psStringCopy(filter); 13185 _object->skycell_id = psStringCopy(skycell_id); 13186 _object->tess_id = psStringCopy(tess_id); 13187 _object->ra = ra; 13188 _object->decl = decl; 13189 _object->input_ss = psStringCopy(input_ss); 13190 _object->output_ss = psStringCopy(output_ss); 13191 13192 return _object; 13193 } 13194 13195 static void p4RunRowFree(p4RunRow *object) 13196 { 13197 psFree(object->survey_mode); 13198 psFree(object->state); 13199 psFree(object->filter); 13200 psFree(object->skycell_id); 13201 psFree(object->tess_id); 13202 psFree(object->input_ss); 13203 psFree(object->output_ss); 13204 } 13205 13206 bool p4RunCreateTable(psDB *dbh) 13207 { 13208 psMetadata *md = psMetadataAlloc(); 13209 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) { 13210 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13211 psFree(md); 13212 return false; 13213 } 13214 if (!psMetadataAdd(md, PS_LIST_TAIL, "survey_mode", PS_DATA_STRING, "Key", "64")) { 13215 psError(PS_ERR_UNKNOWN, false, "failed to add item survey_mode"); 13216 psFree(md); 13217 return false; 13218 } 13219 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 13220 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 13221 psFree(md); 13222 return false; 13223 } 13224 if (!psMetadataAdd(md, PS_LIST_TAIL, "filter", PS_DATA_STRING, NULL, "64")) { 13225 psError(PS_ERR_UNKNOWN, false, "failed to add item filter"); 13226 psFree(md); 13227 return false; 13228 } 13229 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, "64")) { 13230 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 13231 psFree(md); 13232 return false; 13233 } 13234 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, "64")) { 13235 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 13236 psFree(md); 13237 return false; 13238 } 13239 if (!psMetadataAdd(md, PS_LIST_TAIL, "ra", PS_DATA_F64, NULL, 0.0)) { 13240 psError(PS_ERR_UNKNOWN, false, "failed to add item ra"); 13241 psFree(md); 13242 return false; 13243 } 13244 if (!psMetadataAdd(md, PS_LIST_TAIL, "decl", PS_DATA_F64, NULL, 0.0)) { 13245 psError(PS_ERR_UNKNOWN, false, "failed to add item decl"); 13246 psFree(md); 13247 return false; 13248 } 13249 if (!psMetadataAdd(md, PS_LIST_TAIL, "input_ss", PS_DATA_STRING, NULL, "64")) { 13250 psError(PS_ERR_UNKNOWN, false, "failed to add item input_ss"); 13251 psFree(md); 13252 return false; 13253 } 13254 if (!psMetadataAdd(md, PS_LIST_TAIL, "output_ss", PS_DATA_STRING, NULL, "64")) { 13255 psError(PS_ERR_UNKNOWN, false, "failed to add item output_ss"); 13256 psFree(md); 13257 return false; 13258 } 13259 13260 bool status = psDBCreateTable(dbh, P4RUN_TABLE_NAME, md); 13261 13262 psFree(md); 13263 13264 return status; 13265 } 13266 13267 bool p4RunDropTable(psDB *dbh) 13268 { 13269 return psDBDropTable(dbh, P4RUN_TABLE_NAME); 13270 } 13271 13272 bool p4RunInsert(psDB * dbh, psS32 p4_id, const char *survey_mode, const char *state, const char *filter, const char *skycell_id, const char *tess_id, psF64 ra, psF64 decl, const char *input_ss, const char *output_ss) 13273 { 13274 psMetadata *md = psMetadataAlloc(); 13275 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 13276 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13277 psFree(md); 13278 return false; 13279 } 13280 if (!psMetadataAdd(md, PS_LIST_TAIL, "survey_mode", PS_DATA_STRING, NULL, survey_mode)) { 13281 psError(PS_ERR_UNKNOWN, false, "failed to add item survey_mode"); 13282 psFree(md); 13283 return false; 13284 } 13285 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 13286 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 13287 psFree(md); 13288 return false; 13289 } 13290 if (!psMetadataAdd(md, PS_LIST_TAIL, "filter", PS_DATA_STRING, NULL, filter)) { 13291 psError(PS_ERR_UNKNOWN, false, "failed to add item filter"); 13292 psFree(md); 13293 return false; 13294 } 13295 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 13296 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 13297 psFree(md); 13298 return false; 13299 } 13300 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 13301 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 13302 psFree(md); 13303 return false; 13304 } 13305 if (!psMetadataAdd(md, PS_LIST_TAIL, "ra", PS_DATA_F64, NULL, ra)) { 13306 psError(PS_ERR_UNKNOWN, false, "failed to add item ra"); 13307 psFree(md); 13308 return false; 13309 } 13310 if (!psMetadataAdd(md, PS_LIST_TAIL, "decl", PS_DATA_F64, NULL, decl)) { 13311 psError(PS_ERR_UNKNOWN, false, "failed to add item decl"); 13312 psFree(md); 13313 return false; 13314 } 13315 if (!psMetadataAdd(md, PS_LIST_TAIL, "input_ss", PS_DATA_STRING, NULL, input_ss)) { 13316 psError(PS_ERR_UNKNOWN, false, "failed to add item input_ss"); 13317 psFree(md); 13318 return false; 13319 } 13320 if (!psMetadataAdd(md, PS_LIST_TAIL, "output_ss", PS_DATA_STRING, NULL, output_ss)) { 13321 psError(PS_ERR_UNKNOWN, false, "failed to add item output_ss"); 13322 psFree(md); 13323 return false; 13324 } 13325 13326 bool status = psDBInsertOneRow(dbh, P4RUN_TABLE_NAME, md); 13327 psFree(md); 13328 13329 return status; 13330 } 13331 13332 long long p4RunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 13333 { 13334 long long deleted = 0; 13335 13336 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, limit); 13337 if (count < 0) { 13338 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13339 return count; 13340 13341 deleted += count; 13342 } 13343 13344 return deleted; 13345 } 13346 bool p4RunInsertObject(psDB *dbh, p4RunRow *object) 13347 { 13348 return p4RunInsert(dbh, object->p4_id, object->survey_mode, object->state, object->filter, object->skycell_id, object->tess_id, object->ra, object->decl, object->input_ss, object->output_ss); 13349 } 13350 13351 bool p4RunInsertObjects(psDB *dbh, psArray *objects) 13352 { 13353 for (long i = 0; i < psArrayLength(objects); i++) { 13354 if (!p4RunInsertObject(dbh, objects->data[i])) { 13355 return false; 13356 } 13357 } 13358 13359 return true; 13360 } 13361 13362 bool p4RunInsertFits(psDB *dbh, const psFits *fits) 13363 { 13364 psArray *rowSet; 13365 13366 // move to (the first?) extension named P4RUN_TABLE_NAME 13367 if (!psFitsMoveExtName(fits, P4RUN_TABLE_NAME)) { 13368 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4RUN_TABLE_NAME); 13369 return false; 13370 } 13371 13372 // check HDU type 13373 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 13374 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 13375 return false; 13376 } 13377 13378 // read fits table 13379 rowSet = psFitsReadTable(fits); 13380 if (!rowSet) { 13381 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 13382 psFree(rowSet); 13383 return false; 13384 } 13385 13386 if (!psDBInsertRows(dbh, P4RUN_TABLE_NAME, rowSet)) { 13387 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 13388 psFree(rowSet); 13389 return false; 13390 } 13391 13392 psFree(rowSet); 13393 13394 return true; 13395 } 13396 13397 bool p4RunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 13398 { 13399 psArray *rowSet; 13400 13401 rowSet = psDBSelectRows(dbh, P4RUN_TABLE_NAME, where, limit); 13402 if (!rowSet) { 13403 return false; 13404 } 13405 13406 // output to fits 13407 if (!psFitsWriteTable(fits, NULL, rowSet, P4RUN_TABLE_NAME)) { 13408 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 13409 psFree(rowSet); 13410 return false; 13411 } 13412 13413 psFree(rowSet); 13414 13415 return true; 13416 } 13417 13418 psMetadata *p4RunMetadataFromObject(const p4RunRow *object) 13419 { 13420 psMetadata *md = psMetadataAlloc(); 13421 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 13422 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13423 psFree(md); 13424 return false; 13425 } 13426 if (!psMetadataAdd(md, PS_LIST_TAIL, "survey_mode", PS_DATA_STRING, NULL, object->survey_mode)) { 13427 psError(PS_ERR_UNKNOWN, false, "failed to add item survey_mode"); 13428 psFree(md); 13429 return false; 13430 } 13431 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 13432 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 13433 psFree(md); 13434 return false; 13435 } 13436 if (!psMetadataAdd(md, PS_LIST_TAIL, "filter", PS_DATA_STRING, NULL, object->filter)) { 13437 psError(PS_ERR_UNKNOWN, false, "failed to add item filter"); 13438 psFree(md); 13439 return false; 13440 } 13441 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 13442 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 13443 psFree(md); 13444 return false; 13445 } 13446 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 13447 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 13448 psFree(md); 13449 return false; 13450 } 13451 if (!psMetadataAdd(md, PS_LIST_TAIL, "ra", PS_DATA_F64, NULL, object->ra)) { 13452 psError(PS_ERR_UNKNOWN, false, "failed to add item ra"); 13453 psFree(md); 13454 return false; 13455 } 13456 if (!psMetadataAdd(md, PS_LIST_TAIL, "decl", PS_DATA_F64, NULL, object->decl)) { 13457 psError(PS_ERR_UNKNOWN, false, "failed to add item decl"); 13458 psFree(md); 13459 return false; 13460 } 13461 if (!psMetadataAdd(md, PS_LIST_TAIL, "input_ss", PS_DATA_STRING, NULL, object->input_ss)) { 13462 psError(PS_ERR_UNKNOWN, false, "failed to add item input_ss"); 13463 psFree(md); 13464 return false; 13465 } 13466 if (!psMetadataAdd(md, PS_LIST_TAIL, "output_ss", PS_DATA_STRING, NULL, object->output_ss)) { 13467 psError(PS_ERR_UNKNOWN, false, "failed to add item output_ss"); 13468 psFree(md); 13469 return false; 13470 } 13471 13472 13473 return md; 13474 } 13475 13476 p4RunRow *p4RunObjectFromMetadata(psMetadata *md) 13477 { 13478 13479 bool status = false; 13480 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 13481 if (!status) { 13482 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 13483 return false; 13484 } 13485 char* survey_mode = psMetadataLookupPtr(&status, md, "survey_mode"); 13486 if (!status) { 13487 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item survey_mode"); 13488 return false; 13489 } 13490 char* state = psMetadataLookupPtr(&status, md, "state"); 13491 if (!status) { 13492 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 13493 return false; 13494 } 13495 char* filter = psMetadataLookupPtr(&status, md, "filter"); 13496 if (!status) { 13497 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item filter"); 13498 return false; 13499 } 13500 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 13501 if (!status) { 13502 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 13503 return false; 13504 } 13505 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 13506 if (!status) { 13507 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 13508 return false; 13509 } 13510 psF64 ra = psMetadataLookupF64(&status, md, "ra"); 13511 if (!status) { 13512 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item ra"); 13513 return false; 13514 } 13515 psF64 decl = psMetadataLookupF64(&status, md, "decl"); 13516 if (!status) { 13517 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item decl"); 13518 return false; 13519 } 13520 char* input_ss = psMetadataLookupPtr(&status, md, "input_ss"); 13521 if (!status) { 13522 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item input_ss"); 13523 return false; 13524 } 13525 char* output_ss = psMetadataLookupPtr(&status, md, "output_ss"); 13526 if (!status) { 13527 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item output_ss"); 13528 return false; 13529 } 13530 13531 return p4RunRowAlloc(p4_id, survey_mode, state, filter, skycell_id, tess_id, ra, decl, input_ss, output_ss); 13532 } 13533 psArray *p4RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 13534 { 13535 psArray *rowSet; 13536 psArray *returnSet; 13537 psU64 i; 13538 13539 rowSet = psDBSelectRows(dbh, P4RUN_TABLE_NAME, where, limit); 13540 if (!rowSet) { 13541 return NULL; 13542 } 13543 13544 // convert psMetadata rows to row objects 13545 13546 returnSet = psArrayAllocEmpty(rowSet->n); 13547 13548 for (i = 0; i < rowSet->n; i++) { 13549 p4RunRow *object = p4RunObjectFromMetadata(rowSet->data[i]); 13550 psArrayAdd(returnSet, 0, object); 13551 psFree(object); 13552 } 13553 13554 psFree(rowSet); 13555 13556 return returnSet; 13557 } 13558 bool p4RunDeleteObject(psDB *dbh, const p4RunRow *object) 13559 { 13560 psMetadata *where = p4RunMetadataFromObject(object); 13561 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, 0); 13562 psFree(where) 13563 if (count < 0) { 13564 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13565 return false; 13566 } 13567 if (count > 1) { 13568 // XXX should this be a psAbort() instead? It is possible that 13569 // having an object match multiple rows was by design. 13570 psError(PS_ERR_UNKNOWN, true, "p4RunRow object matched more then one row. Check your database schema"); 13571 return false; 13572 } 13573 13574 return true; 13575 } 13576 long long p4RunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 13577 { 13578 long long deleted = 0; 13579 13580 for (long long i = 0; i < objects->n; i++) { 13581 p4RunRow *object = objects->data[i]; 13582 psMetadata *where = p4RunMetadataFromObject(object); 13583 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, limit); 13584 psFree(where) 13585 if (count < 0) { 13586 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13587 return count; 13588 } 13589 13590 deleted += count; 13591 } 13592 13593 return deleted; 13594 } 13595 bool p4RunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 13596 { 13597 PS_ASSERT_PTR_NON_NULL(objects, false); 13598 13599 psMetadata *output = psMetadataAlloc(); 13600 for (long i = 0; i < psArrayLength(objects); i++) { 13601 psMetadata *md = p4RunMetadataFromObject(objects->data[i]); 13602 if (!psMetadataAddMetadata( 13603 output, 13604 PS_LIST_TAIL, 13605 P4RUN_TABLE_NAME, 13606 PS_META_DUPLICATE_OK, 13607 NULL, 13608 md 13609 )) { 13610 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 13611 psFree(md); 13612 psFree(output); 13613 return false; 13614 } 13615 psFree(md); 13616 } 13617 13618 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 13619 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 13620 psFree(output); 13621 } 13622 psFree(output); 13623 13624 return true; 13625 } 13626 static void p4InputImfileRowFree(p4InputImfileRow *object); 13627 13628 p4InputImfileRow *p4InputImfileRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id) 13629 { 13630 p4InputImfileRow *_object; 13631 13632 _object = psAlloc(sizeof(p4InputImfileRow)); 13633 psMemSetDeallocator(_object, (psFreeFunc)p4InputImfileRowFree); 13634 13635 _object->p4_id = p4_id; 13636 _object->exp_tag = psStringCopy(exp_tag); 13637 _object->p3_version = p3_version; 13638 _object->class_id = psStringCopy(class_id); 13639 13640 return _object; 13641 } 13642 13643 static void p4InputImfileRowFree(p4InputImfileRow *object) 13644 { 13645 psFree(object->exp_tag); 13646 psFree(object->class_id); 13647 } 13648 13649 bool p4InputImfileCreateTable(psDB *dbh) 13650 { 13651 psMetadata *md = psMetadataAlloc(); 13652 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 13653 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13654 psFree(md); 13655 return false; 13656 } 13657 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 13658 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 13659 psFree(md); 13660 return false; 13661 } 13662 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 13663 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13664 psFree(md); 13665 return false; 13666 } 13667 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 13668 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 13669 psFree(md); 13670 return false; 13671 } 13672 13673 bool status = psDBCreateTable(dbh, P4INPUTIMFILE_TABLE_NAME, md); 13674 13675 psFree(md); 13676 13677 return status; 13678 } 13679 13680 bool p4InputImfileDropTable(psDB *dbh) 13681 { 13682 return psDBDropTable(dbh, P4INPUTIMFILE_TABLE_NAME); 13683 } 13684 13685 bool p4InputImfileInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id) 13686 { 13687 psMetadata *md = psMetadataAlloc(); 13688 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 13689 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13690 psFree(md); 13691 return false; 13692 } 13693 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 13694 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 13695 psFree(md); 13696 return false; 13697 } 13698 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 13699 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13700 psFree(md); 13701 return false; 13702 } 13703 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 13704 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 13705 psFree(md); 13706 return false; 13707 } 13708 13709 bool status = psDBInsertOneRow(dbh, P4INPUTIMFILE_TABLE_NAME, md); 13710 psFree(md); 13711 13712 return status; 13713 } 13714 13715 long long p4InputImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 13716 { 13717 long long deleted = 0; 13718 13719 long long count = psDBDeleteRows(dbh, P4INPUTIMFILE_TABLE_NAME, where, limit); 13720 if (count < 0) { 13721 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputImfile"); 13722 return count; 13723 13724 deleted += count; 13725 } 13726 13727 return deleted; 13728 } 13729 bool p4InputImfileInsertObject(psDB *dbh, p4InputImfileRow *object) 13730 { 13731 return p4InputImfileInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->class_id); 13732 } 13733 13734 bool p4InputImfileInsertObjects(psDB *dbh, psArray *objects) 13735 { 13736 for (long i = 0; i < psArrayLength(objects); i++) { 13737 if (!p4InputImfileInsertObject(dbh, objects->data[i])) { 13738 return false; 13739 } 13740 } 13741 13742 return true; 13743 } 13744 13745 bool p4InputImfileInsertFits(psDB *dbh, const psFits *fits) 13746 { 13747 psArray *rowSet; 13748 13749 // move to (the first?) extension named P4INPUTIMFILE_TABLE_NAME 13750 if (!psFitsMoveExtName(fits, P4INPUTIMFILE_TABLE_NAME)) { 13751 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4INPUTIMFILE_TABLE_NAME); 13752 return false; 13753 } 13754 13755 // check HDU type 13756 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 13757 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 13758 return false; 13759 } 13760 13761 // read fits table 13762 rowSet = psFitsReadTable(fits); 13763 if (!rowSet) { 13764 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 13765 psFree(rowSet); 13766 return false; 13767 } 13768 13769 if (!psDBInsertRows(dbh, P4INPUTIMFILE_TABLE_NAME, rowSet)) { 13770 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 13771 psFree(rowSet); 13772 return false; 13773 } 13774 13775 psFree(rowSet); 13776 13777 return true; 13778 } 13779 13780 bool p4InputImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 13781 { 13782 psArray *rowSet; 13783 13784 rowSet = psDBSelectRows(dbh, P4INPUTIMFILE_TABLE_NAME, where, limit); 13785 if (!rowSet) { 13786 return false; 13787 } 13788 13789 // output to fits 13790 if (!psFitsWriteTable(fits, NULL, rowSet, P4INPUTIMFILE_TABLE_NAME)) { 13791 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 13792 psFree(rowSet); 13793 return false; 13794 } 13795 13796 psFree(rowSet); 13797 13798 return true; 13799 } 13800 13801 psMetadata *p4InputImfileMetadataFromObject(const p4InputImfileRow *object) 13802 { 13803 psMetadata *md = psMetadataAlloc(); 13804 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 13805 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13806 psFree(md); 13807 return false; 13808 } 13809 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 13810 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 13811 psFree(md); 13812 return false; 13813 } 13814 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 13815 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13816 psFree(md); 13817 return false; 13818 } 13819 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 13820 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 13821 psFree(md); 13822 return false; 13823 } 13824 13825 13826 return md; 13827 } 13828 13829 p4InputImfileRow *p4InputImfileObjectFromMetadata(psMetadata *md) 13830 { 13831 13832 bool status = false; 13833 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 13834 if (!status) { 13835 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 13836 return false; 13837 } 13838 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 13839 if (!status) { 13840 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 13841 return false; 13842 } 13843 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 13844 if (!status) { 13845 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 13846 return false; 13847 } 13848 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 13849 if (!status) { 13850 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 13851 return false; 13852 } 13853 13854 return p4InputImfileRowAlloc(p4_id, exp_tag, p3_version, class_id); 13855 } 13856 psArray *p4InputImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 13857 { 13858 psArray *rowSet; 13859 psArray *returnSet; 13860 psU64 i; 13861 13862 rowSet = psDBSelectRows(dbh, P4INPUTIMFILE_TABLE_NAME, where, limit); 13863 if (!rowSet) { 13864 return NULL; 13865 } 13866 13867 // convert psMetadata rows to row objects 13868 13869 returnSet = psArrayAllocEmpty(rowSet->n); 13870 13871 for (i = 0; i < rowSet->n; i++) { 13872 p4InputImfileRow *object = p4InputImfileObjectFromMetadata(rowSet->data[i]); 13873 psArrayAdd(returnSet, 0, object); 13874 psFree(object); 13875 } 13876 13877 psFree(rowSet); 13878 13879 return returnSet; 13880 } 13881 bool p4InputImfileDeleteObject(psDB *dbh, const p4InputImfileRow *object) 13882 { 13883 psMetadata *where = p4InputImfileMetadataFromObject(object); 13884 long long count = psDBDeleteRows(dbh, P4INPUTIMFILE_TABLE_NAME, where, 0); 13885 psFree(where) 13886 if (count < 0) { 13887 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputImfile"); 13888 return false; 13889 } 13890 if (count > 1) { 13891 // XXX should this be a psAbort() instead? It is possible that 13892 // having an object match multiple rows was by design. 13893 psError(PS_ERR_UNKNOWN, true, "p4InputImfileRow object matched more then one row. Check your database schema"); 13894 return false; 13895 } 13896 13897 return true; 13898 } 13899 long long p4InputImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 13900 { 13901 long long deleted = 0; 13902 13903 for (long long i = 0; i < objects->n; i++) { 13904 p4InputImfileRow *object = objects->data[i]; 13905 psMetadata *where = p4InputImfileMetadataFromObject(object); 13906 long long count = psDBDeleteRows(dbh, P4INPUTIMFILE_TABLE_NAME, where, limit); 13907 psFree(where) 13908 if (count < 0) { 13909 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputImfile"); 13910 return count; 13911 } 13912 13913 deleted += count; 13914 } 13915 13916 return deleted; 13917 } 13918 bool p4InputImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 13919 { 13920 PS_ASSERT_PTR_NON_NULL(objects, false); 13921 13922 psMetadata *output = psMetadataAlloc(); 13923 for (long i = 0; i < psArrayLength(objects); i++) { 13924 psMetadata *md = p4InputImfileMetadataFromObject(objects->data[i]); 13925 if (!psMetadataAddMetadata( 13926 output, 13927 PS_LIST_TAIL, 13928 P4INPUTIMFILE_TABLE_NAME, 13929 PS_META_DUPLICATE_OK, 13930 NULL, 13931 md 13932 )) { 13933 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 13934 psFree(md); 13935 psFree(output); 13936 return false; 13937 } 13938 psFree(md); 13939 } 13940 13941 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 13942 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 13943 psFree(output); 13944 } 13945 psFree(output); 13946 13947 return true; 13948 } 13949 static void p4PWarpedImfileRowFree(p4PWarpedImfileRow *object); 13950 13951 p4PWarpedImfileRow *p4PWarpedImfileRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 13952 { 13953 p4PWarpedImfileRow *_object; 13954 13955 _object = psAlloc(sizeof(p4PWarpedImfileRow)); 13956 psMemSetDeallocator(_object, (psFreeFunc)p4PWarpedImfileRowFree); 13957 13958 _object->p4_id = p4_id; 13959 _object->exp_tag = psStringCopy(exp_tag); 13960 _object->p3_version = p3_version; 13961 _object->class_id = psStringCopy(class_id); 13962 _object->uri = psStringCopy(uri); 13963 _object->b1_uri = psStringCopy(b1_uri); 13964 _object->b2_uri = psStringCopy(b2_uri); 13965 13966 return _object; 13967 } 13968 13969 static void p4PWarpedImfileRowFree(p4PWarpedImfileRow *object) 13970 { 13971 psFree(object->exp_tag); 13972 psFree(object->class_id); 13973 psFree(object->uri); 13974 psFree(object->b1_uri); 13975 psFree(object->b2_uri); 13976 } 13977 13978 bool p4PWarpedImfileCreateTable(psDB *dbh) 13979 { 13980 psMetadata *md = psMetadataAlloc(); 13981 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 13982 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 13983 psFree(md); 13984 return false; 13985 } 13986 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 13987 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 13988 psFree(md); 13989 return false; 13990 } 13991 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 13992 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13993 psFree(md); 13994 return false; 13995 } 13996 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 13997 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 13998 psFree(md); 13999 return false; 14000 } 14001 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 14002 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14003 psFree(md); 14004 return false; 14005 } 14006 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, "255")) { 14007 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14008 psFree(md); 14009 return false; 14010 } 14011 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, "255")) { 14012 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14013 psFree(md); 14014 return false; 14015 } 14016 14017 bool status = psDBCreateTable(dbh, P4PWARPEDIMFILE_TABLE_NAME, md); 14018 14019 psFree(md); 14020 14021 return status; 14022 } 14023 14024 bool p4PWarpedImfileDropTable(psDB *dbh) 14025 { 14026 return psDBDropTable(dbh, P4PWARPEDIMFILE_TABLE_NAME); 14027 } 14028 14029 bool p4PWarpedImfileInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 14030 { 14031 psMetadata *md = psMetadataAlloc(); 14032 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 14033 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14034 psFree(md); 14035 return false; 14036 } 14037 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 14038 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14039 psFree(md); 14040 return false; 14041 } 14042 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 14043 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14044 psFree(md); 14045 return false; 14046 } 14047 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 14048 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14049 psFree(md); 14050 return false; 14051 } 14052 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 14053 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14054 psFree(md); 14055 return false; 14056 } 14057 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, b1_uri)) { 14058 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14059 psFree(md); 14060 return false; 14061 } 14062 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, b2_uri)) { 14063 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14064 psFree(md); 14065 return false; 14066 } 14067 14068 bool status = psDBInsertOneRow(dbh, P4PWARPEDIMFILE_TABLE_NAME, md); 14069 psFree(md); 14070 14071 return status; 14072 } 14073 14074 long long p4PWarpedImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14075 { 14076 long long deleted = 0; 14077 14078 long long count = psDBDeleteRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, where, limit); 14079 if (count < 0) { 14080 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PWarpedImfile"); 14081 return count; 14082 14083 deleted += count; 14084 } 14085 14086 return deleted; 14087 } 14088 bool p4PWarpedImfileInsertObject(psDB *dbh, p4PWarpedImfileRow *object) 14089 { 14090 return p4PWarpedImfileInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->class_id, object->uri, object->b1_uri, object->b2_uri); 14091 } 14092 14093 bool p4PWarpedImfileInsertObjects(psDB *dbh, psArray *objects) 14094 { 14095 for (long i = 0; i < psArrayLength(objects); i++) { 14096 if (!p4PWarpedImfileInsertObject(dbh, objects->data[i])) { 14097 return false; 14098 } 14099 } 14100 14101 return true; 14102 } 14103 14104 bool p4PWarpedImfileInsertFits(psDB *dbh, const psFits *fits) 14105 { 14106 psArray *rowSet; 14107 14108 // move to (the first?) extension named P4PWARPEDIMFILE_TABLE_NAME 14109 if (!psFitsMoveExtName(fits, P4PWARPEDIMFILE_TABLE_NAME)) { 14110 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4PWARPEDIMFILE_TABLE_NAME); 14111 return false; 14112 } 14113 14114 // check HDU type 14115 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 14116 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 14117 return false; 14118 } 14119 14120 // read fits table 14121 rowSet = psFitsReadTable(fits); 14122 if (!rowSet) { 14123 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 14124 psFree(rowSet); 14125 return false; 14126 } 14127 14128 if (!psDBInsertRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, rowSet)) { 14129 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14130 psFree(rowSet); 14131 return false; 14132 } 14133 14134 psFree(rowSet); 14135 14136 return true; 14137 } 14138 14139 bool p4PWarpedImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14140 { 14141 psArray *rowSet; 14142 14143 rowSet = psDBSelectRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, where, limit); 14144 if (!rowSet) { 14145 return false; 14146 } 14147 14148 // output to fits 14149 if (!psFitsWriteTable(fits, NULL, rowSet, P4PWARPEDIMFILE_TABLE_NAME)) { 14150 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14151 psFree(rowSet); 14152 return false; 14153 } 14154 14155 psFree(rowSet); 14156 14157 return true; 14158 } 14159 14160 psMetadata *p4PWarpedImfileMetadataFromObject(const p4PWarpedImfileRow *object) 14161 { 14162 psMetadata *md = psMetadataAlloc(); 14163 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 14164 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14165 psFree(md); 14166 return false; 14167 } 14168 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 14169 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14170 psFree(md); 14171 return false; 14172 } 14173 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 14174 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14175 psFree(md); 14176 return false; 14177 } 14178 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 14179 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14180 psFree(md); 14181 return false; 14182 } 14183 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 14184 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14185 psFree(md); 14186 return false; 14187 } 14188 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, object->b1_uri)) { 14189 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14190 psFree(md); 14191 return false; 14192 } 14193 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, object->b2_uri)) { 14194 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14195 psFree(md); 14196 return false; 14197 } 14198 14199 14200 return md; 14201 } 14202 14203 p4PWarpedImfileRow *p4PWarpedImfileObjectFromMetadata(psMetadata *md) 14204 { 14205 14206 bool status = false; 14207 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 14208 if (!status) { 14209 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 14210 return false; 14211 } 14212 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 14213 if (!status) { 14214 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 14215 return false; 14216 } 14217 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 14218 if (!status) { 14219 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 14220 return false; 14221 } 14222 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 14223 if (!status) { 14224 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 14225 return false; 14226 } 14227 char* uri = psMetadataLookupPtr(&status, md, "uri"); 14228 if (!status) { 14229 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 14230 return false; 14231 } 14232 char* b1_uri = psMetadataLookupPtr(&status, md, "b1_uri"); 14233 if (!status) { 14234 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri"); 14235 return false; 14236 } 14237 char* b2_uri = psMetadataLookupPtr(&status, md, "b2_uri"); 14238 if (!status) { 14239 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri"); 14240 return false; 14241 } 14242 14243 return p4PWarpedImfileRowAlloc(p4_id, exp_tag, p3_version, class_id, uri, b1_uri, b2_uri); 14244 } 14245 psArray *p4PWarpedImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14246 { 14247 psArray *rowSet; 14248 psArray *returnSet; 14249 psU64 i; 14250 14251 rowSet = psDBSelectRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, where, limit); 14252 if (!rowSet) { 14253 return NULL; 14254 } 14255 14256 // convert psMetadata rows to row objects 14257 14258 returnSet = psArrayAllocEmpty(rowSet->n); 14259 14260 for (i = 0; i < rowSet->n; i++) { 14261 p4PWarpedImfileRow *object = p4PWarpedImfileObjectFromMetadata(rowSet->data[i]); 14262 psArrayAdd(returnSet, 0, object); 14263 psFree(object); 14264 } 14265 14266 psFree(rowSet); 14267 14268 return returnSet; 14269 } 14270 bool p4PWarpedImfileDeleteObject(psDB *dbh, const p4PWarpedImfileRow *object) 14271 { 14272 psMetadata *where = p4PWarpedImfileMetadataFromObject(object); 14273 long long count = psDBDeleteRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, where, 0); 14274 psFree(where) 14275 if (count < 0) { 14276 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PWarpedImfile"); 14277 return false; 14278 } 14279 if (count > 1) { 14280 // XXX should this be a psAbort() instead? It is possible that 14281 // having an object match multiple rows was by design. 14282 psError(PS_ERR_UNKNOWN, true, "p4PWarpedImfileRow object matched more then one row. Check your database schema"); 14283 return false; 14284 } 14285 14286 return true; 14287 } 14288 long long p4PWarpedImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 14289 { 14290 long long deleted = 0; 14291 14292 for (long long i = 0; i < objects->n; i++) { 14293 p4PWarpedImfileRow *object = objects->data[i]; 14294 psMetadata *where = p4PWarpedImfileMetadataFromObject(object); 14295 long long count = psDBDeleteRows(dbh, P4PWARPEDIMFILE_TABLE_NAME, where, limit); 14296 psFree(where) 14297 if (count < 0) { 14298 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PWarpedImfile"); 14299 return count; 14300 } 14301 14302 deleted += count; 14303 } 14304 14305 return deleted; 14306 } 14307 bool p4PWarpedImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 14308 { 14309 PS_ASSERT_PTR_NON_NULL(objects, false); 14310 14311 psMetadata *output = psMetadataAlloc(); 14312 for (long i = 0; i < psArrayLength(objects); i++) { 14313 psMetadata *md = p4PWarpedImfileMetadataFromObject(objects->data[i]); 14314 if (!psMetadataAddMetadata( 14315 output, 14316 PS_LIST_TAIL, 14317 P4PWARPEDIMFILE_TABLE_NAME, 14318 PS_META_DUPLICATE_OK, 14319 NULL, 14320 md 14321 )) { 14322 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 14323 psFree(md); 14324 psFree(output); 14325 return false; 14326 } 14327 psFree(md); 14328 } 14329 14330 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 14331 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 14332 psFree(output); 14333 } 14334 psFree(output); 14335 14336 return true; 14337 } 14338 static void p4PStackedImfileRowFree(p4PStackedImfileRow *object); 14339 14340 p4PStackedImfileRow *p4PStackedImfileRowAlloc(psS32 p4_id, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 14341 { 14342 p4PStackedImfileRow *_object; 14343 14344 _object = psAlloc(sizeof(p4PStackedImfileRow)); 14345 psMemSetDeallocator(_object, (psFreeFunc)p4PStackedImfileRowFree); 14346 14347 _object->p4_id = p4_id; 14348 _object->class_id = psStringCopy(class_id); 14349 _object->uri = psStringCopy(uri); 14350 _object->b1_uri = psStringCopy(b1_uri); 14351 _object->b2_uri = psStringCopy(b2_uri); 14352 14353 return _object; 14354 } 14355 14356 static void p4PStackedImfileRowFree(p4PStackedImfileRow *object) 14357 { 14358 psFree(object->class_id); 14359 psFree(object->uri); 14360 psFree(object->b1_uri); 14361 psFree(object->b2_uri); 14362 } 14363 14364 bool p4PStackedImfileCreateTable(psDB *dbh) 14365 { 14366 psMetadata *md = psMetadataAlloc(); 14367 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 14368 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14369 psFree(md); 14370 return false; 14371 } 14372 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 14373 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14374 psFree(md); 14375 return false; 14376 } 14377 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 14378 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14379 psFree(md); 14380 return false; 14381 } 14382 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, "255")) { 14383 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14384 psFree(md); 14385 return false; 14386 } 14387 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, "255")) { 14388 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14389 psFree(md); 14390 return false; 14391 } 14392 14393 bool status = psDBCreateTable(dbh, P4PSTACKEDIMFILE_TABLE_NAME, md); 14394 14395 psFree(md); 14396 14397 return status; 14398 } 14399 14400 bool p4PStackedImfileDropTable(psDB *dbh) 14401 { 14402 return psDBDropTable(dbh, P4PSTACKEDIMFILE_TABLE_NAME); 14403 } 14404 14405 bool p4PStackedImfileInsert(psDB * dbh, psS32 p4_id, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 14406 { 14407 psMetadata *md = psMetadataAlloc(); 14408 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 14409 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14410 psFree(md); 14411 return false; 14412 } 14413 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 14414 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14415 psFree(md); 14416 return false; 14417 } 14418 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 14419 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14420 psFree(md); 14421 return false; 14422 } 14423 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, b1_uri)) { 14424 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14425 psFree(md); 14426 return false; 14427 } 14428 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, b2_uri)) { 14429 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14430 psFree(md); 14431 return false; 14432 } 14433 14434 bool status = psDBInsertOneRow(dbh, P4PSTACKEDIMFILE_TABLE_NAME, md); 14435 psFree(md); 14436 14437 return status; 14438 } 14439 14440 long long p4PStackedImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14441 { 14442 long long deleted = 0; 14443 14444 long long count = psDBDeleteRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, where, limit); 14445 if (count < 0) { 14446 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PStackedImfile"); 14447 return count; 14448 14449 deleted += count; 14450 } 14451 14452 return deleted; 14453 } 14454 bool p4PStackedImfileInsertObject(psDB *dbh, p4PStackedImfileRow *object) 14455 { 14456 return p4PStackedImfileInsert(dbh, object->p4_id, object->class_id, object->uri, object->b1_uri, object->b2_uri); 14457 } 14458 14459 bool p4PStackedImfileInsertObjects(psDB *dbh, psArray *objects) 14460 { 14461 for (long i = 0; i < psArrayLength(objects); i++) { 14462 if (!p4PStackedImfileInsertObject(dbh, objects->data[i])) { 14463 return false; 14464 } 14465 } 14466 14467 return true; 14468 } 14469 14470 bool p4PStackedImfileInsertFits(psDB *dbh, const psFits *fits) 14471 { 14472 psArray *rowSet; 14473 14474 // move to (the first?) extension named P4PSTACKEDIMFILE_TABLE_NAME 14475 if (!psFitsMoveExtName(fits, P4PSTACKEDIMFILE_TABLE_NAME)) { 14476 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4PSTACKEDIMFILE_TABLE_NAME); 14477 return false; 14478 } 14479 14480 // check HDU type 14481 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 14482 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 14483 return false; 14484 } 14485 14486 // read fits table 14487 rowSet = psFitsReadTable(fits); 14488 if (!rowSet) { 14489 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 14490 psFree(rowSet); 14491 return false; 14492 } 14493 14494 if (!psDBInsertRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, rowSet)) { 14495 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14496 psFree(rowSet); 14497 return false; 14498 } 14499 14500 psFree(rowSet); 14501 14502 return true; 14503 } 14504 14505 bool p4PStackedImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14506 { 14507 psArray *rowSet; 14508 14509 rowSet = psDBSelectRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, where, limit); 14510 if (!rowSet) { 14511 return false; 14512 } 14513 14514 // output to fits 14515 if (!psFitsWriteTable(fits, NULL, rowSet, P4PSTACKEDIMFILE_TABLE_NAME)) { 14516 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14517 psFree(rowSet); 14518 return false; 14519 } 14520 14521 psFree(rowSet); 14522 14523 return true; 14524 } 14525 14526 psMetadata *p4PStackedImfileMetadataFromObject(const p4PStackedImfileRow *object) 14527 { 14528 psMetadata *md = psMetadataAlloc(); 14529 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 14530 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14531 psFree(md); 14532 return false; 14533 } 14534 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 14535 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14536 psFree(md); 14537 return false; 14538 } 14539 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 14540 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14541 psFree(md); 14542 return false; 14543 } 14544 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, object->b1_uri)) { 14545 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14546 psFree(md); 14547 return false; 14548 } 14549 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, object->b2_uri)) { 14550 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14551 psFree(md); 14552 return false; 14553 } 14554 14555 14556 return md; 14557 } 14558 14559 p4PStackedImfileRow *p4PStackedImfileObjectFromMetadata(psMetadata *md) 14560 { 14561 14562 bool status = false; 14563 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 14564 if (!status) { 14565 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 14566 return false; 14567 } 14568 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 14569 if (!status) { 14570 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 14571 return false; 14572 } 14573 char* uri = psMetadataLookupPtr(&status, md, "uri"); 14574 if (!status) { 14575 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 14576 return false; 14577 } 14578 char* b1_uri = psMetadataLookupPtr(&status, md, "b1_uri"); 14579 if (!status) { 14580 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri"); 14581 return false; 14582 } 14583 char* b2_uri = psMetadataLookupPtr(&status, md, "b2_uri"); 14584 if (!status) { 14585 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri"); 14586 return false; 14587 } 14588 14589 return p4PStackedImfileRowAlloc(p4_id, class_id, uri, b1_uri, b2_uri); 14590 } 14591 psArray *p4PStackedImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14592 { 14593 psArray *rowSet; 14594 psArray *returnSet; 14595 psU64 i; 14596 14597 rowSet = psDBSelectRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, where, limit); 14598 if (!rowSet) { 14599 return NULL; 14600 } 14601 14602 // convert psMetadata rows to row objects 14603 14604 returnSet = psArrayAllocEmpty(rowSet->n); 14605 14606 for (i = 0; i < rowSet->n; i++) { 14607 p4PStackedImfileRow *object = p4PStackedImfileObjectFromMetadata(rowSet->data[i]); 14608 psArrayAdd(returnSet, 0, object); 14609 psFree(object); 14610 } 14611 14612 psFree(rowSet); 14613 14614 return returnSet; 14615 } 14616 bool p4PStackedImfileDeleteObject(psDB *dbh, const p4PStackedImfileRow *object) 14617 { 14618 psMetadata *where = p4PStackedImfileMetadataFromObject(object); 14619 long long count = psDBDeleteRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, where, 0); 14620 psFree(where) 14621 if (count < 0) { 14622 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PStackedImfile"); 14623 return false; 14624 } 14625 if (count > 1) { 14626 // XXX should this be a psAbort() instead? It is possible that 14627 // having an object match multiple rows was by design. 14628 psError(PS_ERR_UNKNOWN, true, "p4PStackedImfileRow object matched more then one row. Check your database schema"); 14629 return false; 14630 } 14631 14632 return true; 14633 } 14634 long long p4PStackedImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 14635 { 14636 long long deleted = 0; 14637 14638 for (long long i = 0; i < objects->n; i++) { 14639 p4PStackedImfileRow *object = objects->data[i]; 14640 psMetadata *where = p4PStackedImfileMetadataFromObject(object); 14641 long long count = psDBDeleteRows(dbh, P4PSTACKEDIMFILE_TABLE_NAME, where, limit); 14642 psFree(where) 14643 if (count < 0) { 14644 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PStackedImfile"); 14645 return count; 14646 } 14647 14648 deleted += count; 14649 } 14650 14651 return deleted; 14652 } 14653 bool p4PStackedImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 14654 { 14655 PS_ASSERT_PTR_NON_NULL(objects, false); 14656 14657 psMetadata *output = psMetadataAlloc(); 14658 for (long i = 0; i < psArrayLength(objects); i++) { 14659 psMetadata *md = p4PStackedImfileMetadataFromObject(objects->data[i]); 14660 if (!psMetadataAddMetadata( 14661 output, 14662 PS_LIST_TAIL, 14663 P4PSTACKEDIMFILE_TABLE_NAME, 14664 PS_META_DUPLICATE_OK, 14665 NULL, 14666 md 14667 )) { 14668 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 14669 psFree(md); 14670 psFree(output); 14671 return false; 14672 } 14673 psFree(md); 14674 } 14675 14676 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 14677 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 14678 psFree(output); 14679 } 14680 psFree(output); 14681 14682 return true; 14683 } 14684 static void p4PDiffImfileRowFree(p4PDiffImfileRow *object); 14685 14686 p4PDiffImfileRow *p4PDiffImfileRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 14687 { 14688 p4PDiffImfileRow *_object; 14689 14690 _object = psAlloc(sizeof(p4PDiffImfileRow)); 14691 psMemSetDeallocator(_object, (psFreeFunc)p4PDiffImfileRowFree); 14692 14693 _object->p4_id = p4_id; 14694 _object->exp_tag = psStringCopy(exp_tag); 14695 _object->p3_version = p3_version; 14696 _object->class_id = psStringCopy(class_id); 14697 _object->uri = psStringCopy(uri); 14698 _object->b1_uri = psStringCopy(b1_uri); 14699 _object->b2_uri = psStringCopy(b2_uri); 14700 14701 return _object; 14702 } 14703 14704 static void p4PDiffImfileRowFree(p4PDiffImfileRow *object) 14705 { 14706 psFree(object->exp_tag); 14707 psFree(object->class_id); 14708 psFree(object->uri); 14709 psFree(object->b1_uri); 14710 psFree(object->b2_uri); 14711 } 14712 14713 bool p4PDiffImfileCreateTable(psDB *dbh) 14714 { 14715 psMetadata *md = psMetadataAlloc(); 14716 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 14717 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14718 psFree(md); 14719 return false; 14720 } 14721 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 14722 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14723 psFree(md); 14724 return false; 14725 } 14726 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 14727 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14728 psFree(md); 14729 return false; 14730 } 14731 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 14732 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14733 psFree(md); 14734 return false; 14735 } 14736 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 14737 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14738 psFree(md); 14739 return false; 14740 } 14741 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, "255")) { 14742 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14743 psFree(md); 14744 return false; 14745 } 14746 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, "255")) { 14747 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14748 psFree(md); 14749 return false; 14750 } 14751 14752 bool status = psDBCreateTable(dbh, P4PDIFFIMFILE_TABLE_NAME, md); 14753 14754 psFree(md); 14755 14756 return status; 14757 } 14758 14759 bool p4PDiffImfileDropTable(psDB *dbh) 14760 { 14761 return psDBDropTable(dbh, P4PDIFFIMFILE_TABLE_NAME); 14762 } 14763 14764 bool p4PDiffImfileInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri, const char *b1_uri, const char *b2_uri) 14765 { 14766 psMetadata *md = psMetadataAlloc(); 14767 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 14768 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14769 psFree(md); 14770 return false; 14771 } 14772 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 14773 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14774 psFree(md); 14775 return false; 14776 } 14777 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 14778 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14779 psFree(md); 14780 return false; 14781 } 14782 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 14783 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14784 psFree(md); 14785 return false; 14786 } 14787 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 14788 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14789 psFree(md); 14790 return false; 14791 } 14792 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, b1_uri)) { 14793 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14794 psFree(md); 14795 return false; 14796 } 14797 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, b2_uri)) { 14798 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14799 psFree(md); 14800 return false; 14801 } 14802 14803 bool status = psDBInsertOneRow(dbh, P4PDIFFIMFILE_TABLE_NAME, md); 14804 psFree(md); 14805 14806 return status; 14807 } 14808 14809 long long p4PDiffImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14810 { 14811 long long deleted = 0; 14812 14813 long long count = psDBDeleteRows(dbh, P4PDIFFIMFILE_TABLE_NAME, where, limit); 14814 if (count < 0) { 14815 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PDiffImfile"); 14816 return count; 14817 14818 deleted += count; 14819 } 14820 14821 return deleted; 14822 } 14823 bool p4PDiffImfileInsertObject(psDB *dbh, p4PDiffImfileRow *object) 14824 { 14825 return p4PDiffImfileInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->class_id, object->uri, object->b1_uri, object->b2_uri); 14826 } 14827 14828 bool p4PDiffImfileInsertObjects(psDB *dbh, psArray *objects) 14829 { 14830 for (long i = 0; i < psArrayLength(objects); i++) { 14831 if (!p4PDiffImfileInsertObject(dbh, objects->data[i])) { 14832 return false; 14833 } 14834 } 14835 14836 return true; 14837 } 14838 14839 bool p4PDiffImfileInsertFits(psDB *dbh, const psFits *fits) 14840 { 14841 psArray *rowSet; 14842 14843 // move to (the first?) extension named P4PDIFFIMFILE_TABLE_NAME 14844 if (!psFitsMoveExtName(fits, P4PDIFFIMFILE_TABLE_NAME)) { 14845 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4PDIFFIMFILE_TABLE_NAME); 14846 return false; 14847 } 14848 14849 // check HDU type 14850 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 14851 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 14852 return false; 14853 } 14854 14855 // read fits table 14856 rowSet = psFitsReadTable(fits); 14857 if (!rowSet) { 14858 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 14859 psFree(rowSet); 14860 return false; 14861 } 14862 14863 if (!psDBInsertRows(dbh, P4PDIFFIMFILE_TABLE_NAME, rowSet)) { 14864 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14865 psFree(rowSet); 14866 return false; 14867 } 14868 14869 psFree(rowSet); 14870 14871 return true; 14872 } 14873 14874 bool p4PDiffImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14875 { 14876 psArray *rowSet; 14877 14878 rowSet = psDBSelectRows(dbh, P4PDIFFIMFILE_TABLE_NAME, where, limit); 14879 if (!rowSet) { 14880 return false; 14881 } 14882 14883 // output to fits 14884 if (!psFitsWriteTable(fits, NULL, rowSet, P4PDIFFIMFILE_TABLE_NAME)) { 14885 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14886 psFree(rowSet); 14887 return false; 14888 } 14889 14890 psFree(rowSet); 14891 14892 return true; 14893 } 14894 14895 psMetadata *p4PDiffImfileMetadataFromObject(const p4PDiffImfileRow *object) 14896 { 14897 psMetadata *md = psMetadataAlloc(); 14898 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 14899 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 14900 psFree(md); 14901 return false; 14902 } 14903 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 14904 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14905 psFree(md); 14906 return false; 14907 } 14908 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 14909 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14910 psFree(md); 14911 return false; 14912 } 14913 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 14914 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14915 psFree(md); 14916 return false; 14917 } 14918 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 14919 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 14920 psFree(md); 14921 return false; 14922 } 14923 if (!psMetadataAdd(md, PS_LIST_TAIL, "b1_uri", PS_DATA_STRING, NULL, object->b1_uri)) { 14924 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 14925 psFree(md); 14926 return false; 14927 } 14928 if (!psMetadataAdd(md, PS_LIST_TAIL, "b2_uri", PS_DATA_STRING, NULL, object->b2_uri)) { 14929 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 14930 psFree(md); 14931 return false; 14932 } 14933 14934 14935 return md; 14936 } 14937 14938 p4PDiffImfileRow *p4PDiffImfileObjectFromMetadata(psMetadata *md) 14939 { 14940 14941 bool status = false; 14942 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 14943 if (!status) { 14944 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 14945 return false; 14946 } 14947 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 14948 if (!status) { 14949 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 14950 return false; 14951 } 14952 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 14953 if (!status) { 14954 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 14955 return false; 14956 } 14957 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 14958 if (!status) { 14959 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 14960 return false; 14961 } 14962 char* uri = psMetadataLookupPtr(&status, md, "uri"); 14963 if (!status) { 14964 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 14965 return false; 14966 } 14967 char* b1_uri = psMetadataLookupPtr(&status, md, "b1_uri"); 14968 if (!status) { 14969 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri"); 14970 return false; 14971 } 14972 char* b2_uri = psMetadataLookupPtr(&status, md, "b2_uri"); 14973 if (!status) { 14974 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri"); 14975 return false; 14976 } 14977 14978 return p4PDiffImfileRowAlloc(p4_id, exp_tag, p3_version, class_id, uri, b1_uri, b2_uri); 14979 } 14980 psArray *p4PDiffImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14981 { 14982 psArray *rowSet; 14983 psArray *returnSet; 14984 psU64 i; 14985 14986 rowSet = psDBSelectRows(dbh, P4PDIFFIMFILE_TABLE_NAME, where, limit); 14987 if (!rowSet) { 14988 return NULL; 14989 } 14990 14991 // convert psMetadata rows to row objects 14992 14993 returnSet = psArrayAllocEmpty(rowSet->n); 14994 14995 for (i = 0; i < rowSet->n; i++) { 14996 p4PDiffImfileRow *object = p4PDiffImfileObjectFromMetadata(rowSet->data[i]); 14997 psArrayAdd(returnSet, 0, object); 14998 psFree(object); 14999 } 15000 15001 psFree(rowSet); 15002 15003 return returnSet; 15004 } 15005 bool p4PDiffImfileDeleteObject(psDB *dbh, const p4PDiffImfileRow *object) 15006 { 15007 psMetadata *where = p4PDiffImfileMetadataFromObject(object); 15008 long long count = psDBDeleteRows(dbh, P4PDIFFIMFILE_TABLE_NAME, where, 0); 15009 psFree(where) 15010 if (count < 0) { 15011 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PDiffImfile"); 15012 return false; 15013 } 15014 if (count > 1) { 15015 // XXX should this be a psAbort() instead? It is possible that 15016 // having an object match multiple rows was by design. 15017 psError(PS_ERR_UNKNOWN, true, "p4PDiffImfileRow object matched more then one row. Check your database schema"); 15018 return false; 15019 } 15020 15021 return true; 15022 } 15023 long long p4PDiffImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15024 { 15025 long long deleted = 0; 15026 15027 for (long long i = 0; i < objects->n; i++) { 15028 p4PDiffImfileRow *object = objects->data[i]; 15029 psMetadata *where = p4PDiffImfileMetadataFromObject(object); 15030 long long count = psDBDeleteRows(dbh, P4PDIFFIMFILE_TABLE_NAME, where, limit); 15031 psFree(where) 15032 if (count < 0) { 15033 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PDiffImfile"); 15034 return count; 15035 } 15036 15037 deleted += count; 15038 } 15039 15040 return deleted; 15041 } 15042 bool p4PDiffImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15043 { 15044 PS_ASSERT_PTR_NON_NULL(objects, false); 15045 15046 psMetadata *output = psMetadataAlloc(); 15047 for (long i = 0; i < psArrayLength(objects); i++) { 15048 psMetadata *md = p4PDiffImfileMetadataFromObject(objects->data[i]); 15049 if (!psMetadataAddMetadata( 15050 output, 15051 PS_LIST_TAIL, 15052 P4PDIFFIMFILE_TABLE_NAME, 15053 PS_META_DUPLICATE_OK, 15054 NULL, 15055 md 15056 )) { 15057 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15058 psFree(md); 15059 psFree(output); 15060 return false; 15061 } 15062 psFree(md); 15063 } 15064 15065 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15066 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15067 psFree(output); 15068 } 15069 psFree(output); 15070 15071 return true; 15072 } 15073 static void p4PMagicMaskImfileRowFree(p4PMagicMaskImfileRow *object); 15074 15075 p4PMagicMaskImfileRow *p4PMagicMaskImfileRowAlloc(psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri) 15076 { 15077 p4PMagicMaskImfileRow *_object; 15078 15079 _object = psAlloc(sizeof(p4PMagicMaskImfileRow)); 15080 psMemSetDeallocator(_object, (psFreeFunc)p4PMagicMaskImfileRowFree); 15081 15082 _object->p4_id = p4_id; 15083 _object->exp_tag = psStringCopy(exp_tag); 15084 _object->p3_version = p3_version; 15085 _object->class_id = psStringCopy(class_id); 15086 _object->uri = psStringCopy(uri); 15087 15088 return _object; 15089 } 15090 15091 static void p4PMagicMaskImfileRowFree(p4PMagicMaskImfileRow *object) 15092 { 15093 psFree(object->exp_tag); 15094 psFree(object->class_id); 15095 psFree(object->uri); 15096 } 15097 15098 bool p4PMagicMaskImfileCreateTable(psDB *dbh) 15099 { 15100 psMetadata *md = psMetadataAlloc(); 15101 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 15102 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15103 psFree(md); 15104 return false; 15105 } 15106 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 15107 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15108 psFree(md); 15109 return false; 15110 } 15111 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 15112 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15113 psFree(md); 15114 return false; 15115 } 15116 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 15117 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 15118 psFree(md); 15119 return false; 15120 } 15121 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 15122 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15123 psFree(md); 15124 return false; 15125 } 15126 15127 bool status = psDBCreateTable(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, md); 15128 15129 psFree(md); 15130 15131 return status; 15132 } 15133 15134 bool p4PMagicMaskImfileDropTable(psDB *dbh) 15135 { 15136 return psDBDropTable(dbh, P4PMAGICMASKIMFILE_TABLE_NAME); 15137 } 15138 15139 bool p4PMagicMaskImfileInsert(psDB * dbh, psS32 p4_id, const char *exp_tag, psS32 p3_version, const char *class_id, const char *uri) 15140 { 15141 psMetadata *md = psMetadataAlloc(); 15142 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 15143 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15144 psFree(md); 15145 return false; 15146 } 15147 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 15148 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15149 psFree(md); 15150 return false; 15151 } 15152 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 15153 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15154 psFree(md); 15155 return false; 15156 } 15157 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 15158 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 15159 psFree(md); 15160 return false; 15161 } 15162 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 15163 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15164 psFree(md); 15165 return false; 15166 } 15167 15168 bool status = psDBInsertOneRow(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, md); 15169 psFree(md); 15170 15171 return status; 15172 } 15173 15174 long long p4PMagicMaskImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15175 { 15176 long long deleted = 0; 15177 15178 long long count = psDBDeleteRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, where, limit); 15179 if (count < 0) { 15180 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PMagicMaskImfile"); 15181 return count; 15182 15183 deleted += count; 15184 } 15185 15186 return deleted; 15187 } 15188 bool p4PMagicMaskImfileInsertObject(psDB *dbh, p4PMagicMaskImfileRow *object) 15189 { 15190 return p4PMagicMaskImfileInsert(dbh, object->p4_id, object->exp_tag, object->p3_version, object->class_id, object->uri); 15191 } 15192 15193 bool p4PMagicMaskImfileInsertObjects(psDB *dbh, psArray *objects) 15194 { 15195 for (long i = 0; i < psArrayLength(objects); i++) { 15196 if (!p4PMagicMaskImfileInsertObject(dbh, objects->data[i])) { 15197 return false; 15198 } 15199 } 15200 15201 return true; 15202 } 15203 15204 bool p4PMagicMaskImfileInsertFits(psDB *dbh, const psFits *fits) 15205 { 15206 psArray *rowSet; 15207 15208 // move to (the first?) extension named P4PMAGICMASKIMFILE_TABLE_NAME 15209 if (!psFitsMoveExtName(fits, P4PMAGICMASKIMFILE_TABLE_NAME)) { 15210 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4PMAGICMASKIMFILE_TABLE_NAME); 15211 return false; 15212 } 15213 15214 // check HDU type 15215 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15216 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15217 return false; 15218 } 15219 15220 // read fits table 15221 rowSet = psFitsReadTable(fits); 15222 if (!rowSet) { 15223 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15224 psFree(rowSet); 15225 return false; 15226 } 15227 15228 if (!psDBInsertRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, rowSet)) { 15229 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15230 psFree(rowSet); 15231 return false; 15232 } 15233 15234 psFree(rowSet); 15235 15236 return true; 15237 } 15238 15239 bool p4PMagicMaskImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15240 { 15241 psArray *rowSet; 15242 15243 rowSet = psDBSelectRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, where, limit); 15244 if (!rowSet) { 15245 return false; 15246 } 15247 15248 // output to fits 15249 if (!psFitsWriteTable(fits, NULL, rowSet, P4PMAGICMASKIMFILE_TABLE_NAME)) { 15250 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15251 psFree(rowSet); 15252 return false; 15253 } 15254 15255 psFree(rowSet); 15256 15257 return true; 15258 } 15259 15260 psMetadata *p4PMagicMaskImfileMetadataFromObject(const p4PMagicMaskImfileRow *object) 15261 { 15262 psMetadata *md = psMetadataAlloc(); 15263 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 15264 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15265 psFree(md); 15266 return false; 15267 } 15268 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 15269 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15270 psFree(md); 15271 return false; 15272 } 15273 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 15274 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15275 psFree(md); 15276 return false; 15277 } 15278 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 15279 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 15280 psFree(md); 15281 return false; 15282 } 15283 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 15284 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15285 psFree(md); 15286 return false; 15287 } 15288 15289 15290 return md; 15291 } 15292 15293 p4PMagicMaskImfileRow *p4PMagicMaskImfileObjectFromMetadata(psMetadata *md) 15294 { 15295 15296 bool status = false; 15297 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 15298 if (!status) { 15299 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 15300 return false; 15301 } 15302 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 15303 if (!status) { 15304 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 15305 return false; 15306 } 15307 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 15308 if (!status) { 15309 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 15310 return false; 15311 } 15312 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 15313 if (!status) { 15314 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 15315 return false; 15316 } 15317 char* uri = psMetadataLookupPtr(&status, md, "uri"); 15318 if (!status) { 15319 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 15320 return false; 15321 } 15322 15323 return p4PMagicMaskImfileRowAlloc(p4_id, exp_tag, p3_version, class_id, uri); 15324 } 15325 psArray *p4PMagicMaskImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15326 { 15327 psArray *rowSet; 15328 psArray *returnSet; 15329 psU64 i; 15330 15331 rowSet = psDBSelectRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, where, limit); 15332 if (!rowSet) { 15333 return NULL; 15334 } 15335 15336 // convert psMetadata rows to row objects 15337 15338 returnSet = psArrayAllocEmpty(rowSet->n); 15339 15340 for (i = 0; i < rowSet->n; i++) { 15341 p4PMagicMaskImfileRow *object = p4PMagicMaskImfileObjectFromMetadata(rowSet->data[i]); 15342 psArrayAdd(returnSet, 0, object); 15343 psFree(object); 15344 } 15345 15346 psFree(rowSet); 15347 15348 return returnSet; 15349 } 15350 bool p4PMagicMaskImfileDeleteObject(psDB *dbh, const p4PMagicMaskImfileRow *object) 15351 { 15352 psMetadata *where = p4PMagicMaskImfileMetadataFromObject(object); 15353 long long count = psDBDeleteRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, where, 0); 15354 psFree(where) 15355 if (count < 0) { 15356 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PMagicMaskImfile"); 15357 return false; 15358 } 15359 if (count > 1) { 15360 // XXX should this be a psAbort() instead? It is possible that 15361 // having an object match multiple rows was by design. 15362 psError(PS_ERR_UNKNOWN, true, "p4PMagicMaskImfileRow object matched more then one row. Check your database schema"); 15363 return false; 15364 } 15365 15366 return true; 15367 } 15368 long long p4PMagicMaskImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15369 { 15370 long long deleted = 0; 15371 15372 for (long long i = 0; i < objects->n; i++) { 15373 p4PMagicMaskImfileRow *object = objects->data[i]; 15374 psMetadata *where = p4PMagicMaskImfileMetadataFromObject(object); 15375 long long count = psDBDeleteRows(dbh, P4PMAGICMASKIMFILE_TABLE_NAME, where, limit); 15376 psFree(where) 15377 if (count < 0) { 15378 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4PMagicMaskImfile"); 15379 return count; 15380 } 15381 15382 deleted += count; 15383 } 15384 15385 return deleted; 15386 } 15387 bool p4PMagicMaskImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15388 { 15389 PS_ASSERT_PTR_NON_NULL(objects, false); 15390 15391 psMetadata *output = psMetadataAlloc(); 15392 for (long i = 0; i < psArrayLength(objects); i++) { 15393 psMetadata *md = p4PMagicMaskImfileMetadataFromObject(objects->data[i]); 15394 if (!psMetadataAddMetadata( 15395 output, 15396 PS_LIST_TAIL, 15397 P4PMAGICMASKIMFILE_TABLE_NAME, 15398 PS_META_DUPLICATE_OK, 15399 NULL, 15400 md 15401 )) { 15402 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15403 psFree(md); 15404 psFree(output); 15405 return false; 15406 } 15407 psFree(md); 15408 } 15409 15410 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15411 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15412 psFree(output); 15413 } 15414 psFree(output); 15415 15416 return true; 15417 } -
trunk/ippdb/src/ippdb.h
r10449 r10681 6597 6597 bool mdcf ///< format as mdconfig or simple 6598 6598 ); 6599 /** p4RunRow data structure 6600 * 6601 * Structure for representing a single row of p4Run table data. 6602 */ 6603 6604 typedef struct { 6605 psS32 p4_id; 6606 char *survey_mode; 6607 char *state; 6608 char *filter; 6609 char *skycell_id; 6610 char *tess_id; 6611 psF64 ra; 6612 psF64 decl; 6613 char *input_ss; 6614 char *output_ss; 6615 } p4RunRow; 6616 6617 /** Creates a new p4RunRow object 6618 * 6619 * @return A new p4RunRow object or NULL on failure. 6620 */ 6621 6622 p4RunRow *p4RunRowAlloc( 6623 psS32 p4_id, 6624 const char *survey_mode, 6625 const char *state, 6626 const char *filter, 6627 const char *skycell_id, 6628 const char *tess_id, 6629 psF64 ra, 6630 psF64 decl, 6631 const char *input_ss, 6632 const char *output_ss 6633 ); 6634 6635 /** Creates a new p4Run table 6636 * 6637 * @return true on success 6638 */ 6639 6640 bool p4RunCreateTable( 6641 psDB *dbh ///< Database handle 6642 ); 6643 6644 /** Deletes a p4Run table 6645 * 6646 * @return true on success 6647 */ 6648 6649 bool p4RunDropTable( 6650 psDB *dbh ///< Database handle 6651 ); 6652 6653 /** Insert a single row into a table 6654 * 6655 * This function constructs and inserts a single row based on it's parameters. 6656 * 6657 * @return true on success 6658 */ 6659 6660 bool p4RunInsert( 6661 psDB *dbh, ///< Database handle 6662 psS32 p4_id, 6663 const char *survey_mode, 6664 const char *state, 6665 const char *filter, 6666 const char *skycell_id, 6667 const char *tess_id, 6668 psF64 ra, 6669 psF64 decl, 6670 const char *input_ss, 6671 const char *output_ss 6672 ); 6673 6674 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6675 * 6676 * @return A The number of rows removed or a negative value on error 6677 */ 6678 6679 long long p4RunDelete( 6680 psDB *dbh, ///< Database handle 6681 const psMetadata *where, ///< Row match criteria 6682 unsigned long long limit ///< Maximum number of elements to delete 6683 ); 6684 6685 /** Insert a single p4RunRow object into a table 6686 * 6687 * This function constructs and inserts a single row based on it's parameters. 6688 * 6689 * @return true on success 6690 */ 6691 6692 bool p4RunInsertObject( 6693 psDB *dbh, ///< Database handle 6694 p4RunRow *object ///< p4RunRow object 6695 ); 6696 6697 /** Insert an array of p4RunRow object into a table 6698 * 6699 * This function constructs and inserts multiple rows based on it's parameters. 6700 * 6701 * @return true on success 6702 */ 6703 6704 bool p4RunInsertObjects( 6705 psDB *dbh, ///< Database handle 6706 psArray *objects ///< array of p4RunRow objects 6707 ); 6708 6709 /** Insert data from a binary FITS table p4RunRow into the database 6710 * 6711 * This function expects a psFits object with a FITS table as the first 6712 * extension. The table must have at least one row of data in it, that is of 6713 * the appropriate format (number of columns and their type). All other 6714 * extensions are ignored. 6715 * 6716 * @return true on success 6717 */ 6718 6719 bool p4RunInsertFits( 6720 psDB *dbh, ///< Database handle 6721 const psFits *fits ///< psFits object 6722 ); 6723 6724 /** Selects up to limit from the database and returns them in a binary FITS table 6725 * 6726 * This function assumes an empty psFits object and will create a FITS table 6727 * as the first extension. 6728 * 6729 * See psDBSelectRows() for documentation on the format of where. 6730 * 6731 * @return true on success 6732 */ 6733 6734 bool p4RunSelectRowsFits( 6735 psDB *dbh, ///< Database handle 6736 psFits *fits, ///< psFits object 6737 const psMetadata *where, ///< Row match criteria 6738 unsigned long long limit ///< Maximum number of elements to return 6739 ); 6740 6741 /** Convert a p4RunRow into an equivalent psMetadata 6742 * 6743 * @return A psMetadata pointer or NULL on error 6744 */ 6745 6746 psMetadata *p4RunMetadataFromObject( 6747 const p4RunRow *object ///< fooRow to convert into a psMetadata 6748 ); 6749 6750 /** Convert a psMetadata into an equivalent fooRow 6751 * 6752 * @return A p4RunRow pointer or NULL on error 6753 */ 6754 6755 p4RunRow *p4RunObjectFromMetadata( 6756 psMetadata *md ///< psMetadata to convert into a fooRow 6757 ); 6758 /** Selects up to limit rows from the database and returns as p4RunRow objects in a psArray 6759 * 6760 * See psDBSelectRows() for documentation on the format of where. 6761 * 6762 * @return A psArray pointer or NULL on error 6763 */ 6764 6765 psArray *p4RunSelectRowObjects( 6766 psDB *dbh, ///< Database handle 6767 const psMetadata *where, ///< Row match criteria 6768 unsigned long long limit ///< Maximum number of elements to return 6769 ); 6770 /** Deletes a row from the database coresponding to an p4Run 6771 * 6772 * Note that a 'where' search psMetadata is constructed from each object and 6773 * used to find rows to delete. 6774 * 6775 * @return A The number of rows removed or a negative value on error 6776 */ 6777 6778 bool p4RunDeleteObject( 6779 psDB *dbh, ///< Database handle 6780 const p4RunRow *object ///< Object to delete 6781 ); 6782 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6783 * 6784 * Note that a 'where' search psMetadata is constructed from each object and 6785 * used to find rows to delete. 6786 * 6787 * @return A The number of rows removed or a negative value on error 6788 */ 6789 6790 long long p4RunDeleteRowObjects( 6791 psDB *dbh, ///< Database handle 6792 const psArray *objects, ///< Array of objects to delete 6793 unsigned long long limit ///< Maximum number of elements to delete 6794 ); 6795 /** Formats and prints an array of p4RunRow objects 6796 * 6797 * When mdcf is set the formated output is in psMetadataConfig 6798 * format, otherwise it is in a simple tabular format. 6799 * 6800 * @return true on success 6801 */ 6802 6803 bool p4RunPrintObjects( 6804 FILE *stream, ///< a stream 6805 psArray *objects, ///< An array of p4RunRow objects 6806 bool mdcf ///< format as mdconfig or simple 6807 ); 6808 /** p4InputImfileRow data structure 6809 * 6810 * Structure for representing a single row of p4InputImfile table data. 6811 */ 6812 6813 typedef struct { 6814 psS32 p4_id; 6815 char *exp_tag; 6816 psS32 p3_version; 6817 char *class_id; 6818 } p4InputImfileRow; 6819 6820 /** Creates a new p4InputImfileRow object 6821 * 6822 * @return A new p4InputImfileRow object or NULL on failure. 6823 */ 6824 6825 p4InputImfileRow *p4InputImfileRowAlloc( 6826 psS32 p4_id, 6827 const char *exp_tag, 6828 psS32 p3_version, 6829 const char *class_id 6830 ); 6831 6832 /** Creates a new p4InputImfile table 6833 * 6834 * @return true on success 6835 */ 6836 6837 bool p4InputImfileCreateTable( 6838 psDB *dbh ///< Database handle 6839 ); 6840 6841 /** Deletes a p4InputImfile table 6842 * 6843 * @return true on success 6844 */ 6845 6846 bool p4InputImfileDropTable( 6847 psDB *dbh ///< Database handle 6848 ); 6849 6850 /** Insert a single row into a table 6851 * 6852 * This function constructs and inserts a single row based on it's parameters. 6853 * 6854 * @return true on success 6855 */ 6856 6857 bool p4InputImfileInsert( 6858 psDB *dbh, ///< Database handle 6859 psS32 p4_id, 6860 const char *exp_tag, 6861 psS32 p3_version, 6862 const char *class_id 6863 ); 6864 6865 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6866 * 6867 * @return A The number of rows removed or a negative value on error 6868 */ 6869 6870 long long p4InputImfileDelete( 6871 psDB *dbh, ///< Database handle 6872 const psMetadata *where, ///< Row match criteria 6873 unsigned long long limit ///< Maximum number of elements to delete 6874 ); 6875 6876 /** Insert a single p4InputImfileRow object into a table 6877 * 6878 * This function constructs and inserts a single row based on it's parameters. 6879 * 6880 * @return true on success 6881 */ 6882 6883 bool p4InputImfileInsertObject( 6884 psDB *dbh, ///< Database handle 6885 p4InputImfileRow *object ///< p4InputImfileRow object 6886 ); 6887 6888 /** Insert an array of p4InputImfileRow object into a table 6889 * 6890 * This function constructs and inserts multiple rows based on it's parameters. 6891 * 6892 * @return true on success 6893 */ 6894 6895 bool p4InputImfileInsertObjects( 6896 psDB *dbh, ///< Database handle 6897 psArray *objects ///< array of p4InputImfileRow objects 6898 ); 6899 6900 /** Insert data from a binary FITS table p4InputImfileRow into the database 6901 * 6902 * This function expects a psFits object with a FITS table as the first 6903 * extension. The table must have at least one row of data in it, that is of 6904 * the appropriate format (number of columns and their type). All other 6905 * extensions are ignored. 6906 * 6907 * @return true on success 6908 */ 6909 6910 bool p4InputImfileInsertFits( 6911 psDB *dbh, ///< Database handle 6912 const psFits *fits ///< psFits object 6913 ); 6914 6915 /** Selects up to limit from the database and returns them in a binary FITS table 6916 * 6917 * This function assumes an empty psFits object and will create a FITS table 6918 * as the first extension. 6919 * 6920 * See psDBSelectRows() for documentation on the format of where. 6921 * 6922 * @return true on success 6923 */ 6924 6925 bool p4InputImfileSelectRowsFits( 6926 psDB *dbh, ///< Database handle 6927 psFits *fits, ///< psFits object 6928 const psMetadata *where, ///< Row match criteria 6929 unsigned long long limit ///< Maximum number of elements to return 6930 ); 6931 6932 /** Convert a p4InputImfileRow into an equivalent psMetadata 6933 * 6934 * @return A psMetadata pointer or NULL on error 6935 */ 6936 6937 psMetadata *p4InputImfileMetadataFromObject( 6938 const p4InputImfileRow *object ///< fooRow to convert into a psMetadata 6939 ); 6940 6941 /** Convert a psMetadata into an equivalent fooRow 6942 * 6943 * @return A p4InputImfileRow pointer or NULL on error 6944 */ 6945 6946 p4InputImfileRow *p4InputImfileObjectFromMetadata( 6947 psMetadata *md ///< psMetadata to convert into a fooRow 6948 ); 6949 /** Selects up to limit rows from the database and returns as p4InputImfileRow objects in a psArray 6950 * 6951 * See psDBSelectRows() for documentation on the format of where. 6952 * 6953 * @return A psArray pointer or NULL on error 6954 */ 6955 6956 psArray *p4InputImfileSelectRowObjects( 6957 psDB *dbh, ///< Database handle 6958 const psMetadata *where, ///< Row match criteria 6959 unsigned long long limit ///< Maximum number of elements to return 6960 ); 6961 /** Deletes a row from the database coresponding to an p4InputImfile 6962 * 6963 * Note that a 'where' search psMetadata is constructed from each object and 6964 * used to find rows to delete. 6965 * 6966 * @return A The number of rows removed or a negative value on error 6967 */ 6968 6969 bool p4InputImfileDeleteObject( 6970 psDB *dbh, ///< Database handle 6971 const p4InputImfileRow *object ///< Object to delete 6972 ); 6973 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6974 * 6975 * Note that a 'where' search psMetadata is constructed from each object and 6976 * used to find rows to delete. 6977 * 6978 * @return A The number of rows removed or a negative value on error 6979 */ 6980 6981 long long p4InputImfileDeleteRowObjects( 6982 psDB *dbh, ///< Database handle 6983 const psArray *objects, ///< Array of objects to delete 6984 unsigned long long limit ///< Maximum number of elements to delete 6985 ); 6986 /** Formats and prints an array of p4InputImfileRow objects 6987 * 6988 * When mdcf is set the formated output is in psMetadataConfig 6989 * format, otherwise it is in a simple tabular format. 6990 * 6991 * @return true on success 6992 */ 6993 6994 bool p4InputImfilePrintObjects( 6995 FILE *stream, ///< a stream 6996 psArray *objects, ///< An array of p4InputImfileRow objects 6997 bool mdcf ///< format as mdconfig or simple 6998 ); 6999 /** p4PWarpedImfileRow data structure 7000 * 7001 * Structure for representing a single row of p4PWarpedImfile table data. 7002 */ 7003 7004 typedef struct { 7005 psS32 p4_id; 7006 char *exp_tag; 7007 psS32 p3_version; 7008 char *class_id; 7009 char *uri; 7010 char *b1_uri; 7011 char *b2_uri; 7012 } p4PWarpedImfileRow; 7013 7014 /** Creates a new p4PWarpedImfileRow object 7015 * 7016 * @return A new p4PWarpedImfileRow object or NULL on failure. 7017 */ 7018 7019 p4PWarpedImfileRow *p4PWarpedImfileRowAlloc( 7020 psS32 p4_id, 7021 const char *exp_tag, 7022 psS32 p3_version, 7023 const char *class_id, 7024 const char *uri, 7025 const char *b1_uri, 7026 const char *b2_uri 7027 ); 7028 7029 /** Creates a new p4PWarpedImfile table 7030 * 7031 * @return true on success 7032 */ 7033 7034 bool p4PWarpedImfileCreateTable( 7035 psDB *dbh ///< Database handle 7036 ); 7037 7038 /** Deletes a p4PWarpedImfile table 7039 * 7040 * @return true on success 7041 */ 7042 7043 bool p4PWarpedImfileDropTable( 7044 psDB *dbh ///< Database handle 7045 ); 7046 7047 /** Insert a single row into a table 7048 * 7049 * This function constructs and inserts a single row based on it's parameters. 7050 * 7051 * @return true on success 7052 */ 7053 7054 bool p4PWarpedImfileInsert( 7055 psDB *dbh, ///< Database handle 7056 psS32 p4_id, 7057 const char *exp_tag, 7058 psS32 p3_version, 7059 const char *class_id, 7060 const char *uri, 7061 const char *b1_uri, 7062 const char *b2_uri 7063 ); 7064 7065 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7066 * 7067 * @return A The number of rows removed or a negative value on error 7068 */ 7069 7070 long long p4PWarpedImfileDelete( 7071 psDB *dbh, ///< Database handle 7072 const psMetadata *where, ///< Row match criteria 7073 unsigned long long limit ///< Maximum number of elements to delete 7074 ); 7075 7076 /** Insert a single p4PWarpedImfileRow object into a table 7077 * 7078 * This function constructs and inserts a single row based on it's parameters. 7079 * 7080 * @return true on success 7081 */ 7082 7083 bool p4PWarpedImfileInsertObject( 7084 psDB *dbh, ///< Database handle 7085 p4PWarpedImfileRow *object ///< p4PWarpedImfileRow object 7086 ); 7087 7088 /** Insert an array of p4PWarpedImfileRow object into a table 7089 * 7090 * This function constructs and inserts multiple rows based on it's parameters. 7091 * 7092 * @return true on success 7093 */ 7094 7095 bool p4PWarpedImfileInsertObjects( 7096 psDB *dbh, ///< Database handle 7097 psArray *objects ///< array of p4PWarpedImfileRow objects 7098 ); 7099 7100 /** Insert data from a binary FITS table p4PWarpedImfileRow into the database 7101 * 7102 * This function expects a psFits object with a FITS table as the first 7103 * extension. The table must have at least one row of data in it, that is of 7104 * the appropriate format (number of columns and their type). All other 7105 * extensions are ignored. 7106 * 7107 * @return true on success 7108 */ 7109 7110 bool p4PWarpedImfileInsertFits( 7111 psDB *dbh, ///< Database handle 7112 const psFits *fits ///< psFits object 7113 ); 7114 7115 /** Selects up to limit from the database and returns them in a binary FITS table 7116 * 7117 * This function assumes an empty psFits object and will create a FITS table 7118 * as the first extension. 7119 * 7120 * See psDBSelectRows() for documentation on the format of where. 7121 * 7122 * @return true on success 7123 */ 7124 7125 bool p4PWarpedImfileSelectRowsFits( 7126 psDB *dbh, ///< Database handle 7127 psFits *fits, ///< psFits object 7128 const psMetadata *where, ///< Row match criteria 7129 unsigned long long limit ///< Maximum number of elements to return 7130 ); 7131 7132 /** Convert a p4PWarpedImfileRow into an equivalent psMetadata 7133 * 7134 * @return A psMetadata pointer or NULL on error 7135 */ 7136 7137 psMetadata *p4PWarpedImfileMetadataFromObject( 7138 const p4PWarpedImfileRow *object ///< fooRow to convert into a psMetadata 7139 ); 7140 7141 /** Convert a psMetadata into an equivalent fooRow 7142 * 7143 * @return A p4PWarpedImfileRow pointer or NULL on error 7144 */ 7145 7146 p4PWarpedImfileRow *p4PWarpedImfileObjectFromMetadata( 7147 psMetadata *md ///< psMetadata to convert into a fooRow 7148 ); 7149 /** Selects up to limit rows from the database and returns as p4PWarpedImfileRow objects in a psArray 7150 * 7151 * See psDBSelectRows() for documentation on the format of where. 7152 * 7153 * @return A psArray pointer or NULL on error 7154 */ 7155 7156 psArray *p4PWarpedImfileSelectRowObjects( 7157 psDB *dbh, ///< Database handle 7158 const psMetadata *where, ///< Row match criteria 7159 unsigned long long limit ///< Maximum number of elements to return 7160 ); 7161 /** Deletes a row from the database coresponding to an p4PWarpedImfile 7162 * 7163 * Note that a 'where' search psMetadata is constructed from each object and 7164 * used to find rows to delete. 7165 * 7166 * @return A The number of rows removed or a negative value on error 7167 */ 7168 7169 bool p4PWarpedImfileDeleteObject( 7170 psDB *dbh, ///< Database handle 7171 const p4PWarpedImfileRow *object ///< Object to delete 7172 ); 7173 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7174 * 7175 * Note that a 'where' search psMetadata is constructed from each object and 7176 * used to find rows to delete. 7177 * 7178 * @return A The number of rows removed or a negative value on error 7179 */ 7180 7181 long long p4PWarpedImfileDeleteRowObjects( 7182 psDB *dbh, ///< Database handle 7183 const psArray *objects, ///< Array of objects to delete 7184 unsigned long long limit ///< Maximum number of elements to delete 7185 ); 7186 /** Formats and prints an array of p4PWarpedImfileRow objects 7187 * 7188 * When mdcf is set the formated output is in psMetadataConfig 7189 * format, otherwise it is in a simple tabular format. 7190 * 7191 * @return true on success 7192 */ 7193 7194 bool p4PWarpedImfilePrintObjects( 7195 FILE *stream, ///< a stream 7196 psArray *objects, ///< An array of p4PWarpedImfileRow objects 7197 bool mdcf ///< format as mdconfig or simple 7198 ); 7199 /** p4PStackedImfileRow data structure 7200 * 7201 * Structure for representing a single row of p4PStackedImfile table data. 7202 */ 7203 7204 typedef struct { 7205 psS32 p4_id; 7206 char *class_id; 7207 char *uri; 7208 char *b1_uri; 7209 char *b2_uri; 7210 } p4PStackedImfileRow; 7211 7212 /** Creates a new p4PStackedImfileRow object 7213 * 7214 * @return A new p4PStackedImfileRow object or NULL on failure. 7215 */ 7216 7217 p4PStackedImfileRow *p4PStackedImfileRowAlloc( 7218 psS32 p4_id, 7219 const char *class_id, 7220 const char *uri, 7221 const char *b1_uri, 7222 const char *b2_uri 7223 ); 7224 7225 /** Creates a new p4PStackedImfile table 7226 * 7227 * @return true on success 7228 */ 7229 7230 bool p4PStackedImfileCreateTable( 7231 psDB *dbh ///< Database handle 7232 ); 7233 7234 /** Deletes a p4PStackedImfile table 7235 * 7236 * @return true on success 7237 */ 7238 7239 bool p4PStackedImfileDropTable( 7240 psDB *dbh ///< Database handle 7241 ); 7242 7243 /** Insert a single row into a table 7244 * 7245 * This function constructs and inserts a single row based on it's parameters. 7246 * 7247 * @return true on success 7248 */ 7249 7250 bool p4PStackedImfileInsert( 7251 psDB *dbh, ///< Database handle 7252 psS32 p4_id, 7253 const char *class_id, 7254 const char *uri, 7255 const char *b1_uri, 7256 const char *b2_uri 7257 ); 7258 7259 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7260 * 7261 * @return A The number of rows removed or a negative value on error 7262 */ 7263 7264 long long p4PStackedImfileDelete( 7265 psDB *dbh, ///< Database handle 7266 const psMetadata *where, ///< Row match criteria 7267 unsigned long long limit ///< Maximum number of elements to delete 7268 ); 7269 7270 /** Insert a single p4PStackedImfileRow object into a table 7271 * 7272 * This function constructs and inserts a single row based on it's parameters. 7273 * 7274 * @return true on success 7275 */ 7276 7277 bool p4PStackedImfileInsertObject( 7278 psDB *dbh, ///< Database handle 7279 p4PStackedImfileRow *object ///< p4PStackedImfileRow object 7280 ); 7281 7282 /** Insert an array of p4PStackedImfileRow object into a table 7283 * 7284 * This function constructs and inserts multiple rows based on it's parameters. 7285 * 7286 * @return true on success 7287 */ 7288 7289 bool p4PStackedImfileInsertObjects( 7290 psDB *dbh, ///< Database handle 7291 psArray *objects ///< array of p4PStackedImfileRow objects 7292 ); 7293 7294 /** Insert data from a binary FITS table p4PStackedImfileRow into the database 7295 * 7296 * This function expects a psFits object with a FITS table as the first 7297 * extension. The table must have at least one row of data in it, that is of 7298 * the appropriate format (number of columns and their type). All other 7299 * extensions are ignored. 7300 * 7301 * @return true on success 7302 */ 7303 7304 bool p4PStackedImfileInsertFits( 7305 psDB *dbh, ///< Database handle 7306 const psFits *fits ///< psFits object 7307 ); 7308 7309 /** Selects up to limit from the database and returns them in a binary FITS table 7310 * 7311 * This function assumes an empty psFits object and will create a FITS table 7312 * as the first extension. 7313 * 7314 * See psDBSelectRows() for documentation on the format of where. 7315 * 7316 * @return true on success 7317 */ 7318 7319 bool p4PStackedImfileSelectRowsFits( 7320 psDB *dbh, ///< Database handle 7321 psFits *fits, ///< psFits object 7322 const psMetadata *where, ///< Row match criteria 7323 unsigned long long limit ///< Maximum number of elements to return 7324 ); 7325 7326 /** Convert a p4PStackedImfileRow into an equivalent psMetadata 7327 * 7328 * @return A psMetadata pointer or NULL on error 7329 */ 7330 7331 psMetadata *p4PStackedImfileMetadataFromObject( 7332 const p4PStackedImfileRow *object ///< fooRow to convert into a psMetadata 7333 ); 7334 7335 /** Convert a psMetadata into an equivalent fooRow 7336 * 7337 * @return A p4PStackedImfileRow pointer or NULL on error 7338 */ 7339 7340 p4PStackedImfileRow *p4PStackedImfileObjectFromMetadata( 7341 psMetadata *md ///< psMetadata to convert into a fooRow 7342 ); 7343 /** Selects up to limit rows from the database and returns as p4PStackedImfileRow objects in a psArray 7344 * 7345 * See psDBSelectRows() for documentation on the format of where. 7346 * 7347 * @return A psArray pointer or NULL on error 7348 */ 7349 7350 psArray *p4PStackedImfileSelectRowObjects( 7351 psDB *dbh, ///< Database handle 7352 const psMetadata *where, ///< Row match criteria 7353 unsigned long long limit ///< Maximum number of elements to return 7354 ); 7355 /** Deletes a row from the database coresponding to an p4PStackedImfile 7356 * 7357 * Note that a 'where' search psMetadata is constructed from each object and 7358 * used to find rows to delete. 7359 * 7360 * @return A The number of rows removed or a negative value on error 7361 */ 7362 7363 bool p4PStackedImfileDeleteObject( 7364 psDB *dbh, ///< Database handle 7365 const p4PStackedImfileRow *object ///< Object to delete 7366 ); 7367 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7368 * 7369 * Note that a 'where' search psMetadata is constructed from each object and 7370 * used to find rows to delete. 7371 * 7372 * @return A The number of rows removed or a negative value on error 7373 */ 7374 7375 long long p4PStackedImfileDeleteRowObjects( 7376 psDB *dbh, ///< Database handle 7377 const psArray *objects, ///< Array of objects to delete 7378 unsigned long long limit ///< Maximum number of elements to delete 7379 ); 7380 /** Formats and prints an array of p4PStackedImfileRow objects 7381 * 7382 * When mdcf is set the formated output is in psMetadataConfig 7383 * format, otherwise it is in a simple tabular format. 7384 * 7385 * @return true on success 7386 */ 7387 7388 bool p4PStackedImfilePrintObjects( 7389 FILE *stream, ///< a stream 7390 psArray *objects, ///< An array of p4PStackedImfileRow objects 7391 bool mdcf ///< format as mdconfig or simple 7392 ); 7393 /** p4PDiffImfileRow data structure 7394 * 7395 * Structure for representing a single row of p4PDiffImfile table data. 7396 */ 7397 7398 typedef struct { 7399 psS32 p4_id; 7400 char *exp_tag; 7401 psS32 p3_version; 7402 char *class_id; 7403 char *uri; 7404 char *b1_uri; 7405 char *b2_uri; 7406 } p4PDiffImfileRow; 7407 7408 /** Creates a new p4PDiffImfileRow object 7409 * 7410 * @return A new p4PDiffImfileRow object or NULL on failure. 7411 */ 7412 7413 p4PDiffImfileRow *p4PDiffImfileRowAlloc( 7414 psS32 p4_id, 7415 const char *exp_tag, 7416 psS32 p3_version, 7417 const char *class_id, 7418 const char *uri, 7419 const char *b1_uri, 7420 const char *b2_uri 7421 ); 7422 7423 /** Creates a new p4PDiffImfile table 7424 * 7425 * @return true on success 7426 */ 7427 7428 bool p4PDiffImfileCreateTable( 7429 psDB *dbh ///< Database handle 7430 ); 7431 7432 /** Deletes a p4PDiffImfile table 7433 * 7434 * @return true on success 7435 */ 7436 7437 bool p4PDiffImfileDropTable( 7438 psDB *dbh ///< Database handle 7439 ); 7440 7441 /** Insert a single row into a table 7442 * 7443 * This function constructs and inserts a single row based on it's parameters. 7444 * 7445 * @return true on success 7446 */ 7447 7448 bool p4PDiffImfileInsert( 7449 psDB *dbh, ///< Database handle 7450 psS32 p4_id, 7451 const char *exp_tag, 7452 psS32 p3_version, 7453 const char *class_id, 7454 const char *uri, 7455 const char *b1_uri, 7456 const char *b2_uri 7457 ); 7458 7459 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7460 * 7461 * @return A The number of rows removed or a negative value on error 7462 */ 7463 7464 long long p4PDiffImfileDelete( 7465 psDB *dbh, ///< Database handle 7466 const psMetadata *where, ///< Row match criteria 7467 unsigned long long limit ///< Maximum number of elements to delete 7468 ); 7469 7470 /** Insert a single p4PDiffImfileRow object into a table 7471 * 7472 * This function constructs and inserts a single row based on it's parameters. 7473 * 7474 * @return true on success 7475 */ 7476 7477 bool p4PDiffImfileInsertObject( 7478 psDB *dbh, ///< Database handle 7479 p4PDiffImfileRow *object ///< p4PDiffImfileRow object 7480 ); 7481 7482 /** Insert an array of p4PDiffImfileRow object into a table 7483 * 7484 * This function constructs and inserts multiple rows based on it's parameters. 7485 * 7486 * @return true on success 7487 */ 7488 7489 bool p4PDiffImfileInsertObjects( 7490 psDB *dbh, ///< Database handle 7491 psArray *objects ///< array of p4PDiffImfileRow objects 7492 ); 7493 7494 /** Insert data from a binary FITS table p4PDiffImfileRow into the database 7495 * 7496 * This function expects a psFits object with a FITS table as the first 7497 * extension. The table must have at least one row of data in it, that is of 7498 * the appropriate format (number of columns and their type). All other 7499 * extensions are ignored. 7500 * 7501 * @return true on success 7502 */ 7503 7504 bool p4PDiffImfileInsertFits( 7505 psDB *dbh, ///< Database handle 7506 const psFits *fits ///< psFits object 7507 ); 7508 7509 /** Selects up to limit from the database and returns them in a binary FITS table 7510 * 7511 * This function assumes an empty psFits object and will create a FITS table 7512 * as the first extension. 7513 * 7514 * See psDBSelectRows() for documentation on the format of where. 7515 * 7516 * @return true on success 7517 */ 7518 7519 bool p4PDiffImfileSelectRowsFits( 7520 psDB *dbh, ///< Database handle 7521 psFits *fits, ///< psFits object 7522 const psMetadata *where, ///< Row match criteria 7523 unsigned long long limit ///< Maximum number of elements to return 7524 ); 7525 7526 /** Convert a p4PDiffImfileRow into an equivalent psMetadata 7527 * 7528 * @return A psMetadata pointer or NULL on error 7529 */ 7530 7531 psMetadata *p4PDiffImfileMetadataFromObject( 7532 const p4PDiffImfileRow *object ///< fooRow to convert into a psMetadata 7533 ); 7534 7535 /** Convert a psMetadata into an equivalent fooRow 7536 * 7537 * @return A p4PDiffImfileRow pointer or NULL on error 7538 */ 7539 7540 p4PDiffImfileRow *p4PDiffImfileObjectFromMetadata( 7541 psMetadata *md ///< psMetadata to convert into a fooRow 7542 ); 7543 /** Selects up to limit rows from the database and returns as p4PDiffImfileRow objects in a psArray 7544 * 7545 * See psDBSelectRows() for documentation on the format of where. 7546 * 7547 * @return A psArray pointer or NULL on error 7548 */ 7549 7550 psArray *p4PDiffImfileSelectRowObjects( 7551 psDB *dbh, ///< Database handle 7552 const psMetadata *where, ///< Row match criteria 7553 unsigned long long limit ///< Maximum number of elements to return 7554 ); 7555 /** Deletes a row from the database coresponding to an p4PDiffImfile 7556 * 7557 * Note that a 'where' search psMetadata is constructed from each object and 7558 * used to find rows to delete. 7559 * 7560 * @return A The number of rows removed or a negative value on error 7561 */ 7562 7563 bool p4PDiffImfileDeleteObject( 7564 psDB *dbh, ///< Database handle 7565 const p4PDiffImfileRow *object ///< Object to delete 7566 ); 7567 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7568 * 7569 * Note that a 'where' search psMetadata is constructed from each object and 7570 * used to find rows to delete. 7571 * 7572 * @return A The number of rows removed or a negative value on error 7573 */ 7574 7575 long long p4PDiffImfileDeleteRowObjects( 7576 psDB *dbh, ///< Database handle 7577 const psArray *objects, ///< Array of objects to delete 7578 unsigned long long limit ///< Maximum number of elements to delete 7579 ); 7580 /** Formats and prints an array of p4PDiffImfileRow objects 7581 * 7582 * When mdcf is set the formated output is in psMetadataConfig 7583 * format, otherwise it is in a simple tabular format. 7584 * 7585 * @return true on success 7586 */ 7587 7588 bool p4PDiffImfilePrintObjects( 7589 FILE *stream, ///< a stream 7590 psArray *objects, ///< An array of p4PDiffImfileRow objects 7591 bool mdcf ///< format as mdconfig or simple 7592 ); 7593 /** p4PMagicMaskImfileRow data structure 7594 * 7595 * Structure for representing a single row of p4PMagicMaskImfile table data. 7596 */ 7597 7598 typedef struct { 7599 psS32 p4_id; 7600 char *exp_tag; 7601 psS32 p3_version; 7602 char *class_id; 7603 char *uri; 7604 } p4PMagicMaskImfileRow; 7605 7606 /** Creates a new p4PMagicMaskImfileRow object 7607 * 7608 * @return A new p4PMagicMaskImfileRow object or NULL on failure. 7609 */ 7610 7611 p4PMagicMaskImfileRow *p4PMagicMaskImfileRowAlloc( 7612 psS32 p4_id, 7613 const char *exp_tag, 7614 psS32 p3_version, 7615 const char *class_id, 7616 const char *uri 7617 ); 7618 7619 /** Creates a new p4PMagicMaskImfile table 7620 * 7621 * @return true on success 7622 */ 7623 7624 bool p4PMagicMaskImfileCreateTable( 7625 psDB *dbh ///< Database handle 7626 ); 7627 7628 /** Deletes a p4PMagicMaskImfile table 7629 * 7630 * @return true on success 7631 */ 7632 7633 bool p4PMagicMaskImfileDropTable( 7634 psDB *dbh ///< Database handle 7635 ); 7636 7637 /** Insert a single row into a table 7638 * 7639 * This function constructs and inserts a single row based on it's parameters. 7640 * 7641 * @return true on success 7642 */ 7643 7644 bool p4PMagicMaskImfileInsert( 7645 psDB *dbh, ///< Database handle 7646 psS32 p4_id, 7647 const char *exp_tag, 7648 psS32 p3_version, 7649 const char *class_id, 7650 const char *uri 7651 ); 7652 7653 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7654 * 7655 * @return A The number of rows removed or a negative value on error 7656 */ 7657 7658 long long p4PMagicMaskImfileDelete( 7659 psDB *dbh, ///< Database handle 7660 const psMetadata *where, ///< Row match criteria 7661 unsigned long long limit ///< Maximum number of elements to delete 7662 ); 7663 7664 /** Insert a single p4PMagicMaskImfileRow object into a table 7665 * 7666 * This function constructs and inserts a single row based on it's parameters. 7667 * 7668 * @return true on success 7669 */ 7670 7671 bool p4PMagicMaskImfileInsertObject( 7672 psDB *dbh, ///< Database handle 7673 p4PMagicMaskImfileRow *object ///< p4PMagicMaskImfileRow object 7674 ); 7675 7676 /** Insert an array of p4PMagicMaskImfileRow object into a table 7677 * 7678 * This function constructs and inserts multiple rows based on it's parameters. 7679 * 7680 * @return true on success 7681 */ 7682 7683 bool p4PMagicMaskImfileInsertObjects( 7684 psDB *dbh, ///< Database handle 7685 psArray *objects ///< array of p4PMagicMaskImfileRow objects 7686 ); 7687 7688 /** Insert data from a binary FITS table p4PMagicMaskImfileRow into the database 7689 * 7690 * This function expects a psFits object with a FITS table as the first 7691 * extension. The table must have at least one row of data in it, that is of 7692 * the appropriate format (number of columns and their type). All other 7693 * extensions are ignored. 7694 * 7695 * @return true on success 7696 */ 7697 7698 bool p4PMagicMaskImfileInsertFits( 7699 psDB *dbh, ///< Database handle 7700 const psFits *fits ///< psFits object 7701 ); 7702 7703 /** Selects up to limit from the database and returns them in a binary FITS table 7704 * 7705 * This function assumes an empty psFits object and will create a FITS table 7706 * as the first extension. 7707 * 7708 * See psDBSelectRows() for documentation on the format of where. 7709 * 7710 * @return true on success 7711 */ 7712 7713 bool p4PMagicMaskImfileSelectRowsFits( 7714 psDB *dbh, ///< Database handle 7715 psFits *fits, ///< psFits object 7716 const psMetadata *where, ///< Row match criteria 7717 unsigned long long limit ///< Maximum number of elements to return 7718 ); 7719 7720 /** Convert a p4PMagicMaskImfileRow into an equivalent psMetadata 7721 * 7722 * @return A psMetadata pointer or NULL on error 7723 */ 7724 7725 psMetadata *p4PMagicMaskImfileMetadataFromObject( 7726 const p4PMagicMaskImfileRow *object ///< fooRow to convert into a psMetadata 7727 ); 7728 7729 /** Convert a psMetadata into an equivalent fooRow 7730 * 7731 * @return A p4PMagicMaskImfileRow pointer or NULL on error 7732 */ 7733 7734 p4PMagicMaskImfileRow *p4PMagicMaskImfileObjectFromMetadata( 7735 psMetadata *md ///< psMetadata to convert into a fooRow 7736 ); 7737 /** Selects up to limit rows from the database and returns as p4PMagicMaskImfileRow objects in a psArray 7738 * 7739 * See psDBSelectRows() for documentation on the format of where. 7740 * 7741 * @return A psArray pointer or NULL on error 7742 */ 7743 7744 psArray *p4PMagicMaskImfileSelectRowObjects( 7745 psDB *dbh, ///< Database handle 7746 const psMetadata *where, ///< Row match criteria 7747 unsigned long long limit ///< Maximum number of elements to return 7748 ); 7749 /** Deletes a row from the database coresponding to an p4PMagicMaskImfile 7750 * 7751 * Note that a 'where' search psMetadata is constructed from each object and 7752 * used to find rows to delete. 7753 * 7754 * @return A The number of rows removed or a negative value on error 7755 */ 7756 7757 bool p4PMagicMaskImfileDeleteObject( 7758 psDB *dbh, ///< Database handle 7759 const p4PMagicMaskImfileRow *object ///< Object to delete 7760 ); 7761 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7762 * 7763 * Note that a 'where' search psMetadata is constructed from each object and 7764 * used to find rows to delete. 7765 * 7766 * @return A The number of rows removed or a negative value on error 7767 */ 7768 7769 long long p4PMagicMaskImfileDeleteRowObjects( 7770 psDB *dbh, ///< Database handle 7771 const psArray *objects, ///< Array of objects to delete 7772 unsigned long long limit ///< Maximum number of elements to delete 7773 ); 7774 /** Formats and prints an array of p4PMagicMaskImfileRow objects 7775 * 7776 * When mdcf is set the formated output is in psMetadataConfig 7777 * format, otherwise it is in a simple tabular format. 7778 * 7779 * @return true on success 7780 */ 7781 7782 bool p4PMagicMaskImfilePrintObjects( 7783 FILE *stream, ///< a stream 7784 psArray *objects, ///< An array of p4PMagicMaskImfileRow objects 7785 bool mdcf ///< format as mdconfig or simple 7786 ); 6599 7787 6600 7788 /// @} … … 6604 7792 #endif 6605 7793 6606 #endif // DETRUNSUMMARY_DB_H7794 #endif // P4PMAGICMASKIMFILE_DB_H -
trunk/ippdb/tests/alloc.c
r10328 r10681 1407 1407 } 1408 1408 1409 { 1410 p4RunRow *object; 1411 1412 object = p4RunRowAlloc(-32, "a string", "a string", "a string", "a string", "a string", 64.64, 64.64, "a string", "a string" ); 1413 1414 if (!object) { 1415 exit(EXIT_FAILURE); 1416 } 1417 1418 if (!object->p4_id == -32) { 1419 psFree(object); 1420 exit(EXIT_FAILURE); 1421 } 1422 if (strncmp(object->survey_mode, "a string", MAX_STRING_LENGTH)) { 1423 psFree(object); 1424 exit(EXIT_FAILURE); 1425 } 1426 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1427 psFree(object); 1428 exit(EXIT_FAILURE); 1429 } 1430 if (strncmp(object->filter, "a string", MAX_STRING_LENGTH)) { 1431 psFree(object); 1432 exit(EXIT_FAILURE); 1433 } 1434 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1435 psFree(object); 1436 exit(EXIT_FAILURE); 1437 } 1438 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1439 psFree(object); 1440 exit(EXIT_FAILURE); 1441 } 1442 if (!object->ra == 64.64) { 1443 psFree(object); 1444 exit(EXIT_FAILURE); 1445 } 1446 if (!object->decl == 64.64) { 1447 psFree(object); 1448 exit(EXIT_FAILURE); 1449 } 1450 if (strncmp(object->input_ss, "a string", MAX_STRING_LENGTH)) { 1451 psFree(object); 1452 exit(EXIT_FAILURE); 1453 } 1454 if (strncmp(object->output_ss, "a string", MAX_STRING_LENGTH)) { 1455 psFree(object); 1456 exit(EXIT_FAILURE); 1457 } 1458 1459 psFree(object); 1460 } 1461 1462 { 1463 p4InputImfileRow *object; 1464 1465 object = p4InputImfileRowAlloc(-32, "a string", -32, "a string" ); 1466 1467 if (!object) { 1468 exit(EXIT_FAILURE); 1469 } 1470 1471 if (!object->p4_id == -32) { 1472 psFree(object); 1473 exit(EXIT_FAILURE); 1474 } 1475 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1476 psFree(object); 1477 exit(EXIT_FAILURE); 1478 } 1479 if (!object->p3_version == -32) { 1480 psFree(object); 1481 exit(EXIT_FAILURE); 1482 } 1483 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1484 psFree(object); 1485 exit(EXIT_FAILURE); 1486 } 1487 1488 psFree(object); 1489 } 1490 1491 { 1492 p4PWarpedImfileRow *object; 1493 1494 object = p4PWarpedImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string" ); 1495 1496 if (!object) { 1497 exit(EXIT_FAILURE); 1498 } 1499 1500 if (!object->p4_id == -32) { 1501 psFree(object); 1502 exit(EXIT_FAILURE); 1503 } 1504 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1505 psFree(object); 1506 exit(EXIT_FAILURE); 1507 } 1508 if (!object->p3_version == -32) { 1509 psFree(object); 1510 exit(EXIT_FAILURE); 1511 } 1512 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1513 psFree(object); 1514 exit(EXIT_FAILURE); 1515 } 1516 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1517 psFree(object); 1518 exit(EXIT_FAILURE); 1519 } 1520 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 1521 psFree(object); 1522 exit(EXIT_FAILURE); 1523 } 1524 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 1525 psFree(object); 1526 exit(EXIT_FAILURE); 1527 } 1528 1529 psFree(object); 1530 } 1531 1532 { 1533 p4PStackedImfileRow *object; 1534 1535 object = p4PStackedImfileRowAlloc(-32, "a string", "a string", "a string", "a string" ); 1536 1537 if (!object) { 1538 exit(EXIT_FAILURE); 1539 } 1540 1541 if (!object->p4_id == -32) { 1542 psFree(object); 1543 exit(EXIT_FAILURE); 1544 } 1545 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1546 psFree(object); 1547 exit(EXIT_FAILURE); 1548 } 1549 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1550 psFree(object); 1551 exit(EXIT_FAILURE); 1552 } 1553 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 1554 psFree(object); 1555 exit(EXIT_FAILURE); 1556 } 1557 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 1558 psFree(object); 1559 exit(EXIT_FAILURE); 1560 } 1561 1562 psFree(object); 1563 } 1564 1565 { 1566 p4PDiffImfileRow *object; 1567 1568 object = p4PDiffImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string" ); 1569 1570 if (!object) { 1571 exit(EXIT_FAILURE); 1572 } 1573 1574 if (!object->p4_id == -32) { 1575 psFree(object); 1576 exit(EXIT_FAILURE); 1577 } 1578 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1579 psFree(object); 1580 exit(EXIT_FAILURE); 1581 } 1582 if (!object->p3_version == -32) { 1583 psFree(object); 1584 exit(EXIT_FAILURE); 1585 } 1586 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1587 psFree(object); 1588 exit(EXIT_FAILURE); 1589 } 1590 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1591 psFree(object); 1592 exit(EXIT_FAILURE); 1593 } 1594 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 1595 psFree(object); 1596 exit(EXIT_FAILURE); 1597 } 1598 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 1599 psFree(object); 1600 exit(EXIT_FAILURE); 1601 } 1602 1603 psFree(object); 1604 } 1605 1606 { 1607 p4PMagicMaskImfileRow *object; 1608 1609 object = p4PMagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string" ); 1610 1611 if (!object) { 1612 exit(EXIT_FAILURE); 1613 } 1614 1615 if (!object->p4_id == -32) { 1616 psFree(object); 1617 exit(EXIT_FAILURE); 1618 } 1619 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1620 psFree(object); 1621 exit(EXIT_FAILURE); 1622 } 1623 if (!object->p3_version == -32) { 1624 psFree(object); 1625 exit(EXIT_FAILURE); 1626 } 1627 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1628 psFree(object); 1629 exit(EXIT_FAILURE); 1630 } 1631 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1632 psFree(object); 1633 exit(EXIT_FAILURE); 1634 } 1635 1636 psFree(object); 1637 } 1638 1409 1639 exit(EXIT_SUCCESS); 1410 1640 } -
trunk/ippdb/tests/createtable.c
r10238 r10681 485 485 } 486 486 487 { 488 psDB *dbh; 489 490 dbh = psDBInit("localhost", "test", NULL, "test"); 491 if (!dbh) { 492 exit(EXIT_FAILURE); 493 } 494 495 if(!p4RunCreateTable(dbh)) { 496 exit(EXIT_FAILURE); 497 } 498 499 psDBCleanup(dbh); 500 } 501 502 { 503 psDB *dbh; 504 505 dbh = psDBInit("localhost", "test", NULL, "test"); 506 if (!dbh) { 507 exit(EXIT_FAILURE); 508 } 509 510 if(!p4InputImfileCreateTable(dbh)) { 511 exit(EXIT_FAILURE); 512 } 513 514 psDBCleanup(dbh); 515 } 516 517 { 518 psDB *dbh; 519 520 dbh = psDBInit("localhost", "test", NULL, "test"); 521 if (!dbh) { 522 exit(EXIT_FAILURE); 523 } 524 525 if(!p4PWarpedImfileCreateTable(dbh)) { 526 exit(EXIT_FAILURE); 527 } 528 529 psDBCleanup(dbh); 530 } 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if(!p4PStackedImfileCreateTable(dbh)) { 541 exit(EXIT_FAILURE); 542 } 543 544 psDBCleanup(dbh); 545 } 546 547 { 548 psDB *dbh; 549 550 dbh = psDBInit("localhost", "test", NULL, "test"); 551 if (!dbh) { 552 exit(EXIT_FAILURE); 553 } 554 555 if(!p4PDiffImfileCreateTable(dbh)) { 556 exit(EXIT_FAILURE); 557 } 558 559 psDBCleanup(dbh); 560 } 561 562 { 563 psDB *dbh; 564 565 dbh = psDBInit("localhost", "test", NULL, "test"); 566 if (!dbh) { 567 exit(EXIT_FAILURE); 568 } 569 570 if(!p4PMagicMaskImfileCreateTable(dbh)) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 487 577 exit(EXIT_SUCCESS); 488 578 } -
trunk/ippdb/tests/dbcleanup.c
r10238 r10681 43 43 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detResidExp"); 44 44 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRunSummary"); 45 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Run"); 46 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputImfile"); 47 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PWarpedImfile"); 48 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PStackedImfile"); 49 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PDiffImfile"); 50 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PMagicMaskImfile"); 45 51 46 52 psDBCleanup(dbh); -
trunk/ippdb/tests/dbsetup.c
r10238 r10681 109 109 detRunSummaryCreateTable(dbh); 110 110 111 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Run"); 112 p4RunCreateTable(dbh); 113 114 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4InputImfile"); 115 p4InputImfileCreateTable(dbh); 116 117 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PWarpedImfile"); 118 p4PWarpedImfileCreateTable(dbh); 119 120 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PStackedImfile"); 121 p4PStackedImfileCreateTable(dbh); 122 123 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PDiffImfile"); 124 p4PDiffImfileCreateTable(dbh); 125 126 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4PMagicMaskImfile"); 127 p4PMagicMaskImfileCreateTable(dbh); 128 111 129 psDBCleanup(dbh); 112 130 -
trunk/ippdb/tests/droptable.c
r10238 r10681 485 485 } 486 486 487 { 488 psDB *dbh; 489 490 dbh = psDBInit("localhost", "test", NULL, "test"); 491 if (!dbh) { 492 exit(EXIT_FAILURE); 493 } 494 495 if (!p4RunDropTable(dbh)) { 496 exit(EXIT_FAILURE); 497 } 498 499 psDBCleanup(dbh); 500 } 501 502 { 503 psDB *dbh; 504 505 dbh = psDBInit("localhost", "test", NULL, "test"); 506 if (!dbh) { 507 exit(EXIT_FAILURE); 508 } 509 510 if (!p4InputImfileDropTable(dbh)) { 511 exit(EXIT_FAILURE); 512 } 513 514 psDBCleanup(dbh); 515 } 516 517 { 518 psDB *dbh; 519 520 dbh = psDBInit("localhost", "test", NULL, "test"); 521 if (!dbh) { 522 exit(EXIT_FAILURE); 523 } 524 525 if (!p4PWarpedImfileDropTable(dbh)) { 526 exit(EXIT_FAILURE); 527 } 528 529 psDBCleanup(dbh); 530 } 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if (!p4PStackedImfileDropTable(dbh)) { 541 exit(EXIT_FAILURE); 542 } 543 544 psDBCleanup(dbh); 545 } 546 547 { 548 psDB *dbh; 549 550 dbh = psDBInit("localhost", "test", NULL, "test"); 551 if (!dbh) { 552 exit(EXIT_FAILURE); 553 } 554 555 if (!p4PDiffImfileDropTable(dbh)) { 556 exit(EXIT_FAILURE); 557 } 558 559 psDBCleanup(dbh); 560 } 561 562 { 563 psDB *dbh; 564 565 dbh = psDBInit("localhost", "test", NULL, "test"); 566 if (!dbh) { 567 exit(EXIT_FAILURE); 568 } 569 570 if (!p4PMagicMaskImfileDropTable(dbh)) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 487 577 exit(EXIT_SUCCESS); 488 578 } -
trunk/ippdb/tests/insert.c
r10328 r10681 485 485 } 486 486 487 { 488 psDB *dbh; 489 490 dbh = psDBInit("localhost", "test", NULL, "test"); 491 if (!dbh) { 492 exit(EXIT_FAILURE); 493 } 494 495 if (!p4RunInsert(dbh, -32, "a string", "a string", "a string", "a string", "a string", 64.64, 64.64, "a string", "a string")) { 496 exit(EXIT_FAILURE); 497 } 498 499 psDBCleanup(dbh); 500 } 501 502 { 503 psDB *dbh; 504 505 dbh = psDBInit("localhost", "test", NULL, "test"); 506 if (!dbh) { 507 exit(EXIT_FAILURE); 508 } 509 510 if (!p4InputImfileInsert(dbh, -32, "a string", -32, "a string")) { 511 exit(EXIT_FAILURE); 512 } 513 514 psDBCleanup(dbh); 515 } 516 517 { 518 psDB *dbh; 519 520 dbh = psDBInit("localhost", "test", NULL, "test"); 521 if (!dbh) { 522 exit(EXIT_FAILURE); 523 } 524 525 if (!p4PWarpedImfileInsert(dbh, -32, "a string", -32, "a string", "a string", "a string", "a string")) { 526 exit(EXIT_FAILURE); 527 } 528 529 psDBCleanup(dbh); 530 } 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if (!p4PStackedImfileInsert(dbh, -32, "a string", "a string", "a string", "a string")) { 541 exit(EXIT_FAILURE); 542 } 543 544 psDBCleanup(dbh); 545 } 546 547 { 548 psDB *dbh; 549 550 dbh = psDBInit("localhost", "test", NULL, "test"); 551 if (!dbh) { 552 exit(EXIT_FAILURE); 553 } 554 555 if (!p4PDiffImfileInsert(dbh, -32, "a string", -32, "a string", "a string", "a string", "a string")) { 556 exit(EXIT_FAILURE); 557 } 558 559 psDBCleanup(dbh); 560 } 561 562 { 563 psDB *dbh; 564 565 dbh = psDBInit("localhost", "test", NULL, "test"); 566 if (!dbh) { 567 exit(EXIT_FAILURE); 568 } 569 570 if (!p4PMagicMaskImfileInsert(dbh, -32, "a string", -32, "a string", "a string")) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 487 577 exit(EXIT_SUCCESS); 488 578 } -
trunk/ippdb/tests/insertfits.c
r10238 r10681 841 841 } 842 842 843 { 844 psDB *dbh; 845 psFits *fits; 846 847 dbh = psDBInit("localhost", "test", NULL, "test"); 848 if (!dbh) { 849 exit(EXIT_FAILURE); 850 } 851 852 // open a temp 853 fits = psFitsOpen(TMP_FILENAME, "r"); 854 if (!fits) { 855 exit(EXIT_FAILURE); 856 } 857 858 if (!p4RunInsertFits(dbh, fits)) { 859 exit(EXIT_FAILURE); 860 } 861 862 if (!psFitsClose(fits)) { 863 exit(EXIT_FAILURE); 864 } 865 866 psDBCleanup(dbh); 867 } 868 869 { 870 psDB *dbh; 871 psFits *fits; 872 873 dbh = psDBInit("localhost", "test", NULL, "test"); 874 if (!dbh) { 875 exit(EXIT_FAILURE); 876 } 877 878 // open a temp 879 fits = psFitsOpen(TMP_FILENAME, "r"); 880 if (!fits) { 881 exit(EXIT_FAILURE); 882 } 883 884 if (!p4InputImfileInsertFits(dbh, fits)) { 885 exit(EXIT_FAILURE); 886 } 887 888 if (!psFitsClose(fits)) { 889 exit(EXIT_FAILURE); 890 } 891 892 psDBCleanup(dbh); 893 } 894 895 { 896 psDB *dbh; 897 psFits *fits; 898 899 dbh = psDBInit("localhost", "test", NULL, "test"); 900 if (!dbh) { 901 exit(EXIT_FAILURE); 902 } 903 904 // open a temp 905 fits = psFitsOpen(TMP_FILENAME, "r"); 906 if (!fits) { 907 exit(EXIT_FAILURE); 908 } 909 910 if (!p4PWarpedImfileInsertFits(dbh, fits)) { 911 exit(EXIT_FAILURE); 912 } 913 914 if (!psFitsClose(fits)) { 915 exit(EXIT_FAILURE); 916 } 917 918 psDBCleanup(dbh); 919 } 920 921 { 922 psDB *dbh; 923 psFits *fits; 924 925 dbh = psDBInit("localhost", "test", NULL, "test"); 926 if (!dbh) { 927 exit(EXIT_FAILURE); 928 } 929 930 // open a temp 931 fits = psFitsOpen(TMP_FILENAME, "r"); 932 if (!fits) { 933 exit(EXIT_FAILURE); 934 } 935 936 if (!p4PStackedImfileInsertFits(dbh, fits)) { 937 exit(EXIT_FAILURE); 938 } 939 940 if (!psFitsClose(fits)) { 941 exit(EXIT_FAILURE); 942 } 943 944 psDBCleanup(dbh); 945 } 946 947 { 948 psDB *dbh; 949 psFits *fits; 950 951 dbh = psDBInit("localhost", "test", NULL, "test"); 952 if (!dbh) { 953 exit(EXIT_FAILURE); 954 } 955 956 // open a temp 957 fits = psFitsOpen(TMP_FILENAME, "r"); 958 if (!fits) { 959 exit(EXIT_FAILURE); 960 } 961 962 if (!p4PDiffImfileInsertFits(dbh, fits)) { 963 exit(EXIT_FAILURE); 964 } 965 966 if (!psFitsClose(fits)) { 967 exit(EXIT_FAILURE); 968 } 969 970 psDBCleanup(dbh); 971 } 972 973 { 974 psDB *dbh; 975 psFits *fits; 976 977 dbh = psDBInit("localhost", "test", NULL, "test"); 978 if (!dbh) { 979 exit(EXIT_FAILURE); 980 } 981 982 // open a temp 983 fits = psFitsOpen(TMP_FILENAME, "r"); 984 if (!fits) { 985 exit(EXIT_FAILURE); 986 } 987 988 if (!p4PMagicMaskImfileInsertFits(dbh, fits)) { 989 exit(EXIT_FAILURE); 990 } 991 992 if (!psFitsClose(fits)) { 993 exit(EXIT_FAILURE); 994 } 995 996 psDBCleanup(dbh); 997 } 998 843 999 exit(EXIT_SUCCESS); 844 1000 } -
trunk/ippdb/tests/insertobject.c
r10328 r10681 709 709 } 710 710 711 { 712 psDB *dbh; 713 p4RunRow *object; 714 715 dbh = psDBInit("localhost", "test", NULL, "test"); 716 if (!dbh) { 717 exit(EXIT_FAILURE); 718 } 719 720 object = p4RunRowAlloc(-32, "a string", "a string", "a string", "a string", "a string", 64.64, 64.64, "a string", "a string"); 721 if (!object) { 722 exit(EXIT_FAILURE); 723 } 724 725 if (!p4RunInsertObject(dbh, object)) { 726 exit(EXIT_FAILURE); 727 } 728 729 psFree(object); 730 psDBCleanup(dbh); 731 } 732 733 { 734 psDB *dbh; 735 p4InputImfileRow *object; 736 737 dbh = psDBInit("localhost", "test", NULL, "test"); 738 if (!dbh) { 739 exit(EXIT_FAILURE); 740 } 741 742 object = p4InputImfileRowAlloc(-32, "a string", -32, "a string"); 743 if (!object) { 744 exit(EXIT_FAILURE); 745 } 746 747 if (!p4InputImfileInsertObject(dbh, object)) { 748 exit(EXIT_FAILURE); 749 } 750 751 psFree(object); 752 psDBCleanup(dbh); 753 } 754 755 { 756 psDB *dbh; 757 p4PWarpedImfileRow *object; 758 759 dbh = psDBInit("localhost", "test", NULL, "test"); 760 if (!dbh) { 761 exit(EXIT_FAILURE); 762 } 763 764 object = p4PWarpedImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string"); 765 if (!object) { 766 exit(EXIT_FAILURE); 767 } 768 769 if (!p4PWarpedImfileInsertObject(dbh, object)) { 770 exit(EXIT_FAILURE); 771 } 772 773 psFree(object); 774 psDBCleanup(dbh); 775 } 776 777 { 778 psDB *dbh; 779 p4PStackedImfileRow *object; 780 781 dbh = psDBInit("localhost", "test", NULL, "test"); 782 if (!dbh) { 783 exit(EXIT_FAILURE); 784 } 785 786 object = p4PStackedImfileRowAlloc(-32, "a string", "a string", "a string", "a string"); 787 if (!object) { 788 exit(EXIT_FAILURE); 789 } 790 791 if (!p4PStackedImfileInsertObject(dbh, object)) { 792 exit(EXIT_FAILURE); 793 } 794 795 psFree(object); 796 psDBCleanup(dbh); 797 } 798 799 { 800 psDB *dbh; 801 p4PDiffImfileRow *object; 802 803 dbh = psDBInit("localhost", "test", NULL, "test"); 804 if (!dbh) { 805 exit(EXIT_FAILURE); 806 } 807 808 object = p4PDiffImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string"); 809 if (!object) { 810 exit(EXIT_FAILURE); 811 } 812 813 if (!p4PDiffImfileInsertObject(dbh, object)) { 814 exit(EXIT_FAILURE); 815 } 816 817 psFree(object); 818 psDBCleanup(dbh); 819 } 820 821 { 822 psDB *dbh; 823 p4PMagicMaskImfileRow *object; 824 825 dbh = psDBInit("localhost", "test", NULL, "test"); 826 if (!dbh) { 827 exit(EXIT_FAILURE); 828 } 829 830 object = p4PMagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string"); 831 if (!object) { 832 exit(EXIT_FAILURE); 833 } 834 835 if (!p4PMagicMaskImfileInsertObject(dbh, object)) { 836 exit(EXIT_FAILURE); 837 } 838 839 psFree(object); 840 psDBCleanup(dbh); 841 } 842 711 843 exit(EXIT_SUCCESS); 712 844 } -
trunk/ippdb/tests/metadatafromobject.c
r10328 r10681 1663 1663 } 1664 1664 1665 { 1666 psMetadata *md; 1667 p4RunRow *object; 1668 bool status; 1669 1670 object = p4RunRowAlloc(-32, "a string", "a string", "a string", "a string", "a string", 64.64, 64.64, "a string", "a string"); 1671 if (!object) { 1672 exit(EXIT_FAILURE); 1673 } 1674 1675 md = p4RunMetadataFromObject(object); 1676 if (!md) { 1677 exit(EXIT_FAILURE); 1678 } 1679 1680 psFree(object); 1681 1682 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1683 psFree(md); 1684 exit(EXIT_FAILURE); 1685 } 1686 if (strncmp(psMetadataLookupPtr(&status, md, "survey_mode"), "a string", MAX_STRING_LENGTH)) { 1687 psFree(md); 1688 exit(EXIT_FAILURE); 1689 } 1690 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 1691 psFree(md); 1692 exit(EXIT_FAILURE); 1693 } 1694 if (strncmp(psMetadataLookupPtr(&status, md, "filter"), "a string", MAX_STRING_LENGTH)) { 1695 psFree(md); 1696 exit(EXIT_FAILURE); 1697 } 1698 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1699 psFree(md); 1700 exit(EXIT_FAILURE); 1701 } 1702 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1703 psFree(md); 1704 exit(EXIT_FAILURE); 1705 } 1706 if (!psMetadataLookupF64(&status, md, "ra") == 64.64) { 1707 psFree(md); 1708 exit(EXIT_FAILURE); 1709 } 1710 if (!psMetadataLookupF64(&status, md, "decl") == 64.64) { 1711 psFree(md); 1712 exit(EXIT_FAILURE); 1713 } 1714 if (strncmp(psMetadataLookupPtr(&status, md, "input_ss"), "a string", MAX_STRING_LENGTH)) { 1715 psFree(md); 1716 exit(EXIT_FAILURE); 1717 } 1718 if (strncmp(psMetadataLookupPtr(&status, md, "output_ss"), "a string", MAX_STRING_LENGTH)) { 1719 psFree(md); 1720 exit(EXIT_FAILURE); 1721 } 1722 1723 psFree(md); 1724 } 1725 1726 { 1727 psMetadata *md; 1728 p4InputImfileRow *object; 1729 bool status; 1730 1731 object = p4InputImfileRowAlloc(-32, "a string", -32, "a string"); 1732 if (!object) { 1733 exit(EXIT_FAILURE); 1734 } 1735 1736 md = p4InputImfileMetadataFromObject(object); 1737 if (!md) { 1738 exit(EXIT_FAILURE); 1739 } 1740 1741 psFree(object); 1742 1743 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1744 psFree(md); 1745 exit(EXIT_FAILURE); 1746 } 1747 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1748 psFree(md); 1749 exit(EXIT_FAILURE); 1750 } 1751 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1752 psFree(md); 1753 exit(EXIT_FAILURE); 1754 } 1755 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1756 psFree(md); 1757 exit(EXIT_FAILURE); 1758 } 1759 1760 psFree(md); 1761 } 1762 1763 { 1764 psMetadata *md; 1765 p4PWarpedImfileRow *object; 1766 bool status; 1767 1768 object = p4PWarpedImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string"); 1769 if (!object) { 1770 exit(EXIT_FAILURE); 1771 } 1772 1773 md = p4PWarpedImfileMetadataFromObject(object); 1774 if (!md) { 1775 exit(EXIT_FAILURE); 1776 } 1777 1778 psFree(object); 1779 1780 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1781 psFree(md); 1782 exit(EXIT_FAILURE); 1783 } 1784 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1785 psFree(md); 1786 exit(EXIT_FAILURE); 1787 } 1788 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1789 psFree(md); 1790 exit(EXIT_FAILURE); 1791 } 1792 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1793 psFree(md); 1794 exit(EXIT_FAILURE); 1795 } 1796 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1797 psFree(md); 1798 exit(EXIT_FAILURE); 1799 } 1800 if (strncmp(psMetadataLookupPtr(&status, md, "b1_uri"), "a string", MAX_STRING_LENGTH)) { 1801 psFree(md); 1802 exit(EXIT_FAILURE); 1803 } 1804 if (strncmp(psMetadataLookupPtr(&status, md, "b2_uri"), "a string", MAX_STRING_LENGTH)) { 1805 psFree(md); 1806 exit(EXIT_FAILURE); 1807 } 1808 1809 psFree(md); 1810 } 1811 1812 { 1813 psMetadata *md; 1814 p4PStackedImfileRow *object; 1815 bool status; 1816 1817 object = p4PStackedImfileRowAlloc(-32, "a string", "a string", "a string", "a string"); 1818 if (!object) { 1819 exit(EXIT_FAILURE); 1820 } 1821 1822 md = p4PStackedImfileMetadataFromObject(object); 1823 if (!md) { 1824 exit(EXIT_FAILURE); 1825 } 1826 1827 psFree(object); 1828 1829 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1830 psFree(md); 1831 exit(EXIT_FAILURE); 1832 } 1833 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1834 psFree(md); 1835 exit(EXIT_FAILURE); 1836 } 1837 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1838 psFree(md); 1839 exit(EXIT_FAILURE); 1840 } 1841 if (strncmp(psMetadataLookupPtr(&status, md, "b1_uri"), "a string", MAX_STRING_LENGTH)) { 1842 psFree(md); 1843 exit(EXIT_FAILURE); 1844 } 1845 if (strncmp(psMetadataLookupPtr(&status, md, "b2_uri"), "a string", MAX_STRING_LENGTH)) { 1846 psFree(md); 1847 exit(EXIT_FAILURE); 1848 } 1849 1850 psFree(md); 1851 } 1852 1853 { 1854 psMetadata *md; 1855 p4PDiffImfileRow *object; 1856 bool status; 1857 1858 object = p4PDiffImfileRowAlloc(-32, "a string", -32, "a string", "a string", "a string", "a string"); 1859 if (!object) { 1860 exit(EXIT_FAILURE); 1861 } 1862 1863 md = p4PDiffImfileMetadataFromObject(object); 1864 if (!md) { 1865 exit(EXIT_FAILURE); 1866 } 1867 1868 psFree(object); 1869 1870 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1871 psFree(md); 1872 exit(EXIT_FAILURE); 1873 } 1874 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1875 psFree(md); 1876 exit(EXIT_FAILURE); 1877 } 1878 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1879 psFree(md); 1880 exit(EXIT_FAILURE); 1881 } 1882 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1883 psFree(md); 1884 exit(EXIT_FAILURE); 1885 } 1886 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1887 psFree(md); 1888 exit(EXIT_FAILURE); 1889 } 1890 if (strncmp(psMetadataLookupPtr(&status, md, "b1_uri"), "a string", MAX_STRING_LENGTH)) { 1891 psFree(md); 1892 exit(EXIT_FAILURE); 1893 } 1894 if (strncmp(psMetadataLookupPtr(&status, md, "b2_uri"), "a string", MAX_STRING_LENGTH)) { 1895 psFree(md); 1896 exit(EXIT_FAILURE); 1897 } 1898 1899 psFree(md); 1900 } 1901 1902 { 1903 psMetadata *md; 1904 p4PMagicMaskImfileRow *object; 1905 bool status; 1906 1907 object = p4PMagicMaskImfileRowAlloc(-32, "a string", -32, "a string", "a string"); 1908 if (!object) { 1909 exit(EXIT_FAILURE); 1910 } 1911 1912 md = p4PMagicMaskImfileMetadataFromObject(object); 1913 if (!md) { 1914 exit(EXIT_FAILURE); 1915 } 1916 1917 psFree(object); 1918 1919 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1920 psFree(md); 1921 exit(EXIT_FAILURE); 1922 } 1923 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1924 psFree(md); 1925 exit(EXIT_FAILURE); 1926 } 1927 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1928 psFree(md); 1929 exit(EXIT_FAILURE); 1930 } 1931 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1932 psFree(md); 1933 exit(EXIT_FAILURE); 1934 } 1935 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1936 psFree(md); 1937 exit(EXIT_FAILURE); 1938 } 1939 1940 psFree(md); 1941 } 1942 1665 1943 exit(EXIT_SUCCESS); 1666 1944 } -
trunk/ippdb/tests/objectfrommetadata.c
r10328 r10681 2550 2550 } 2551 2551 2552 { 2553 psMetadata *md; 2554 p4RunRow *object; 2555 2556 md = psMetadataAlloc(); 2557 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2558 psFree(md); 2559 exit(EXIT_FAILURE); 2560 } 2561 if (!psMetadataAddStr(md, PS_LIST_TAIL, "survey_mode", 0, NULL, "a string")) { 2562 psFree(md); 2563 exit(EXIT_FAILURE); 2564 } 2565 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 2566 psFree(md); 2567 exit(EXIT_FAILURE); 2568 } 2569 if (!psMetadataAddStr(md, PS_LIST_TAIL, "filter", 0, NULL, "a string")) { 2570 psFree(md); 2571 exit(EXIT_FAILURE); 2572 } 2573 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 2574 psFree(md); 2575 exit(EXIT_FAILURE); 2576 } 2577 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 2578 psFree(md); 2579 exit(EXIT_FAILURE); 2580 } 2581 if (!psMetadataAddF64(md, PS_LIST_TAIL, "ra", 0, NULL, 64.64)) { 2582 psFree(md); 2583 exit(EXIT_FAILURE); 2584 } 2585 if (!psMetadataAddF64(md, PS_LIST_TAIL, "decl", 0, NULL, 64.64)) { 2586 psFree(md); 2587 exit(EXIT_FAILURE); 2588 } 2589 if (!psMetadataAddStr(md, PS_LIST_TAIL, "input_ss", 0, NULL, "a string")) { 2590 psFree(md); 2591 exit(EXIT_FAILURE); 2592 } 2593 if (!psMetadataAddStr(md, PS_LIST_TAIL, "output_ss", 0, NULL, "a string")) { 2594 psFree(md); 2595 exit(EXIT_FAILURE); 2596 } 2597 2598 object = p4RunObjectFromMetadata(md); 2599 if (!object) { 2600 psFree(md); 2601 exit(EXIT_FAILURE); 2602 } 2603 2604 psFree(md); 2605 2606 if (!object->p4_id == -32) { 2607 psFree(object); 2608 exit(EXIT_FAILURE); 2609 } 2610 if (strncmp(object->survey_mode, "a string", MAX_STRING_LENGTH)) { 2611 psFree(object); 2612 exit(EXIT_FAILURE); 2613 } 2614 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 2615 psFree(object); 2616 exit(EXIT_FAILURE); 2617 } 2618 if (strncmp(object->filter, "a string", MAX_STRING_LENGTH)) { 2619 psFree(object); 2620 exit(EXIT_FAILURE); 2621 } 2622 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 2623 psFree(object); 2624 exit(EXIT_FAILURE); 2625 } 2626 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 2627 psFree(object); 2628 exit(EXIT_FAILURE); 2629 } 2630 if (!object->ra == 64.64) { 2631 psFree(object); 2632 exit(EXIT_FAILURE); 2633 } 2634 if (!object->decl == 64.64) { 2635 psFree(object); 2636 exit(EXIT_FAILURE); 2637 } 2638 if (strncmp(object->input_ss, "a string", MAX_STRING_LENGTH)) { 2639 psFree(object); 2640 exit(EXIT_FAILURE); 2641 } 2642 if (strncmp(object->output_ss, "a string", MAX_STRING_LENGTH)) { 2643 psFree(object); 2644 exit(EXIT_FAILURE); 2645 } 2646 2647 psFree(object); 2648 } 2649 2650 { 2651 psMetadata *md; 2652 p4InputImfileRow *object; 2653 2654 md = psMetadataAlloc(); 2655 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2656 psFree(md); 2657 exit(EXIT_FAILURE); 2658 } 2659 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 2660 psFree(md); 2661 exit(EXIT_FAILURE); 2662 } 2663 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 2664 psFree(md); 2665 exit(EXIT_FAILURE); 2666 } 2667 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 2668 psFree(md); 2669 exit(EXIT_FAILURE); 2670 } 2671 2672 object = p4InputImfileObjectFromMetadata(md); 2673 if (!object) { 2674 psFree(md); 2675 exit(EXIT_FAILURE); 2676 } 2677 2678 psFree(md); 2679 2680 if (!object->p4_id == -32) { 2681 psFree(object); 2682 exit(EXIT_FAILURE); 2683 } 2684 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 2685 psFree(object); 2686 exit(EXIT_FAILURE); 2687 } 2688 if (!object->p3_version == -32) { 2689 psFree(object); 2690 exit(EXIT_FAILURE); 2691 } 2692 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 2693 psFree(object); 2694 exit(EXIT_FAILURE); 2695 } 2696 2697 psFree(object); 2698 } 2699 2700 { 2701 psMetadata *md; 2702 p4PWarpedImfileRow *object; 2703 2704 md = psMetadataAlloc(); 2705 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2706 psFree(md); 2707 exit(EXIT_FAILURE); 2708 } 2709 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 2710 psFree(md); 2711 exit(EXIT_FAILURE); 2712 } 2713 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 2714 psFree(md); 2715 exit(EXIT_FAILURE); 2716 } 2717 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 2718 psFree(md); 2719 exit(EXIT_FAILURE); 2720 } 2721 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2722 psFree(md); 2723 exit(EXIT_FAILURE); 2724 } 2725 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "a string")) { 2726 psFree(md); 2727 exit(EXIT_FAILURE); 2728 } 2729 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "a string")) { 2730 psFree(md); 2731 exit(EXIT_FAILURE); 2732 } 2733 2734 object = p4PWarpedImfileObjectFromMetadata(md); 2735 if (!object) { 2736 psFree(md); 2737 exit(EXIT_FAILURE); 2738 } 2739 2740 psFree(md); 2741 2742 if (!object->p4_id == -32) { 2743 psFree(object); 2744 exit(EXIT_FAILURE); 2745 } 2746 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 2747 psFree(object); 2748 exit(EXIT_FAILURE); 2749 } 2750 if (!object->p3_version == -32) { 2751 psFree(object); 2752 exit(EXIT_FAILURE); 2753 } 2754 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 2755 psFree(object); 2756 exit(EXIT_FAILURE); 2757 } 2758 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2759 psFree(object); 2760 exit(EXIT_FAILURE); 2761 } 2762 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 2763 psFree(object); 2764 exit(EXIT_FAILURE); 2765 } 2766 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 2767 psFree(object); 2768 exit(EXIT_FAILURE); 2769 } 2770 2771 psFree(object); 2772 } 2773 2774 { 2775 psMetadata *md; 2776 p4PStackedImfileRow *object; 2777 2778 md = psMetadataAlloc(); 2779 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2780 psFree(md); 2781 exit(EXIT_FAILURE); 2782 } 2783 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 2784 psFree(md); 2785 exit(EXIT_FAILURE); 2786 } 2787 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2788 psFree(md); 2789 exit(EXIT_FAILURE); 2790 } 2791 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "a string")) { 2792 psFree(md); 2793 exit(EXIT_FAILURE); 2794 } 2795 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "a string")) { 2796 psFree(md); 2797 exit(EXIT_FAILURE); 2798 } 2799 2800 object = p4PStackedImfileObjectFromMetadata(md); 2801 if (!object) { 2802 psFree(md); 2803 exit(EXIT_FAILURE); 2804 } 2805 2806 psFree(md); 2807 2808 if (!object->p4_id == -32) { 2809 psFree(object); 2810 exit(EXIT_FAILURE); 2811 } 2812 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 2813 psFree(object); 2814 exit(EXIT_FAILURE); 2815 } 2816 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2817 psFree(object); 2818 exit(EXIT_FAILURE); 2819 } 2820 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 2821 psFree(object); 2822 exit(EXIT_FAILURE); 2823 } 2824 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 2825 psFree(object); 2826 exit(EXIT_FAILURE); 2827 } 2828 2829 psFree(object); 2830 } 2831 2832 { 2833 psMetadata *md; 2834 p4PDiffImfileRow *object; 2835 2836 md = psMetadataAlloc(); 2837 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2838 psFree(md); 2839 exit(EXIT_FAILURE); 2840 } 2841 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 2842 psFree(md); 2843 exit(EXIT_FAILURE); 2844 } 2845 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 2846 psFree(md); 2847 exit(EXIT_FAILURE); 2848 } 2849 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 2850 psFree(md); 2851 exit(EXIT_FAILURE); 2852 } 2853 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2854 psFree(md); 2855 exit(EXIT_FAILURE); 2856 } 2857 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "a string")) { 2858 psFree(md); 2859 exit(EXIT_FAILURE); 2860 } 2861 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "a string")) { 2862 psFree(md); 2863 exit(EXIT_FAILURE); 2864 } 2865 2866 object = p4PDiffImfileObjectFromMetadata(md); 2867 if (!object) { 2868 psFree(md); 2869 exit(EXIT_FAILURE); 2870 } 2871 2872 psFree(md); 2873 2874 if (!object->p4_id == -32) { 2875 psFree(object); 2876 exit(EXIT_FAILURE); 2877 } 2878 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 2879 psFree(object); 2880 exit(EXIT_FAILURE); 2881 } 2882 if (!object->p3_version == -32) { 2883 psFree(object); 2884 exit(EXIT_FAILURE); 2885 } 2886 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 2887 psFree(object); 2888 exit(EXIT_FAILURE); 2889 } 2890 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2891 psFree(object); 2892 exit(EXIT_FAILURE); 2893 } 2894 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 2895 psFree(object); 2896 exit(EXIT_FAILURE); 2897 } 2898 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 2899 psFree(object); 2900 exit(EXIT_FAILURE); 2901 } 2902 2903 psFree(object); 2904 } 2905 2906 { 2907 psMetadata *md; 2908 p4PMagicMaskImfileRow *object; 2909 2910 md = psMetadataAlloc(); 2911 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2912 psFree(md); 2913 exit(EXIT_FAILURE); 2914 } 2915 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 2916 psFree(md); 2917 exit(EXIT_FAILURE); 2918 } 2919 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 2920 psFree(md); 2921 exit(EXIT_FAILURE); 2922 } 2923 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 2924 psFree(md); 2925 exit(EXIT_FAILURE); 2926 } 2927 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2928 psFree(md); 2929 exit(EXIT_FAILURE); 2930 } 2931 2932 object = p4PMagicMaskImfileObjectFromMetadata(md); 2933 if (!object) { 2934 psFree(md); 2935 exit(EXIT_FAILURE); 2936 } 2937 2938 psFree(md); 2939 2940 if (!object->p4_id == -32) { 2941 psFree(object); 2942 exit(EXIT_FAILURE); 2943 } 2944 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 2945 psFree(object); 2946 exit(EXIT_FAILURE); 2947 } 2948 if (!object->p3_version == -32) { 2949 psFree(object); 2950 exit(EXIT_FAILURE); 2951 } 2952 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 2953 psFree(object); 2954 exit(EXIT_FAILURE); 2955 } 2956 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2957 psFree(object); 2958 exit(EXIT_FAILURE); 2959 } 2960 2961 psFree(object); 2962 } 2963 2552 2964 exit(EXIT_SUCCESS); 2553 2965 } -
trunk/ippdb/tests/selectrowsfits.c
r10238 r10681 711 711 } 712 712 713 { 714 psDB *dbh; 715 psFits *fits; 716 717 dbh = psDBInit("localhost", "test", NULL, "test"); 718 if (!dbh) { 719 exit(EXIT_FAILURE); 720 } 721 722 fits = psFitsOpen(TMP_FILENAME, "w"); 723 if (!fits) { 724 exit(EXIT_FAILURE); 725 } 726 727 if (!p4RunSelectRowsFits(dbh, fits, NULL, 1)) { 728 exit(EXIT_FAILURE); 729 } 730 731 psFree(fits); 732 psDBCleanup(dbh); 733 } 734 735 { 736 psDB *dbh; 737 psFits *fits; 738 739 dbh = psDBInit("localhost", "test", NULL, "test"); 740 if (!dbh) { 741 exit(EXIT_FAILURE); 742 } 743 744 fits = psFitsOpen(TMP_FILENAME, "w"); 745 if (!fits) { 746 exit(EXIT_FAILURE); 747 } 748 749 if (!p4InputImfileSelectRowsFits(dbh, fits, NULL, 1)) { 750 exit(EXIT_FAILURE); 751 } 752 753 psFree(fits); 754 psDBCleanup(dbh); 755 } 756 757 { 758 psDB *dbh; 759 psFits *fits; 760 761 dbh = psDBInit("localhost", "test", NULL, "test"); 762 if (!dbh) { 763 exit(EXIT_FAILURE); 764 } 765 766 fits = psFitsOpen(TMP_FILENAME, "w"); 767 if (!fits) { 768 exit(EXIT_FAILURE); 769 } 770 771 if (!p4PWarpedImfileSelectRowsFits(dbh, fits, NULL, 1)) { 772 exit(EXIT_FAILURE); 773 } 774 775 psFree(fits); 776 psDBCleanup(dbh); 777 } 778 779 { 780 psDB *dbh; 781 psFits *fits; 782 783 dbh = psDBInit("localhost", "test", NULL, "test"); 784 if (!dbh) { 785 exit(EXIT_FAILURE); 786 } 787 788 fits = psFitsOpen(TMP_FILENAME, "w"); 789 if (!fits) { 790 exit(EXIT_FAILURE); 791 } 792 793 if (!p4PStackedImfileSelectRowsFits(dbh, fits, NULL, 1)) { 794 exit(EXIT_FAILURE); 795 } 796 797 psFree(fits); 798 psDBCleanup(dbh); 799 } 800 801 { 802 psDB *dbh; 803 psFits *fits; 804 805 dbh = psDBInit("localhost", "test", NULL, "test"); 806 if (!dbh) { 807 exit(EXIT_FAILURE); 808 } 809 810 fits = psFitsOpen(TMP_FILENAME, "w"); 811 if (!fits) { 812 exit(EXIT_FAILURE); 813 } 814 815 if (!p4PDiffImfileSelectRowsFits(dbh, fits, NULL, 1)) { 816 exit(EXIT_FAILURE); 817 } 818 819 psFree(fits); 820 psDBCleanup(dbh); 821 } 822 823 { 824 psDB *dbh; 825 psFits *fits; 826 827 dbh = psDBInit("localhost", "test", NULL, "test"); 828 if (!dbh) { 829 exit(EXIT_FAILURE); 830 } 831 832 fits = psFitsOpen(TMP_FILENAME, "w"); 833 if (!fits) { 834 exit(EXIT_FAILURE); 835 } 836 837 if (!p4PMagicMaskImfileSelectRowsFits(dbh, fits, NULL, 1)) { 838 exit(EXIT_FAILURE); 839 } 840 841 psFree(fits); 842 psDBCleanup(dbh); 843 } 844 713 845 exit(EXIT_SUCCESS); 714 846 }
Note:
See TracChangeset
for help on using the changeset viewer.
