Changeset 11809
- Timestamp:
- Feb 14, 2007, 4:02:28 PM (19 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
r11780 r11809 44 44 $(top_builddir)/docs/man/man3/p4InputExpRow.3 \ 45 45 $(top_builddir)/docs/man/man3/p4SkyCellMapRow.3 \ 46 $(top_builddir)/docs/man/man3/p4ScfileRow.3 46 $(top_builddir)/docs/man/man3/p4ScfileRow.3 \ 47 $(top_builddir)/docs/man/man3/p5RunRow.3 \ 48 $(top_builddir)/docs/man/man3/p5InputScfileRow.3 \ 49 $(top_builddir)/docs/man/man3/p5DiffScfileRow.3 47 50 48 51 49 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/rawExpRow.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/p4InputExpRow.3 docs/man/man3/p4SkyCellMapRow.3 docs/man/man3/p4ScfileRow.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/rawExpRow.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/p4InputExpRow.3 docs/man/man3/p4SkyCellMapRow.3 docs/man/man3/p4ScfileRow.3 docs/man/man3/p5RunRow.3 docs/man/man3/p5InputScfileRow.3 docs/man/man3/p5DiffScfileRow.3: 50 53 $(DOXYGEN) 51 54 -
trunk/ippdb/configure.ac
r11780 r11809 7 7 AC_PREREQ(2.59) 8 8 9 AC_INIT([ippdb], [1.1. 5], [pan-starrs.ifa.hawaii.edu])9 AC_INIT([ippdb], [1.1.6], [pan-starrs.ifa.hawaii.edu]) 10 10 AC_CONFIG_SRCDIR([ippdb.pc.in]) 11 11 -
trunk/ippdb/src/ippdb.c
r11780 r11809 66 66 #define P4SKYCELLMAP_TABLE_NAME "p4SkyCellMap" 67 67 #define P4SCFILE_TABLE_NAME "p4Scfile" 68 #define P5RUN_TABLE_NAME "p5Run" 69 #define P5INPUTSCFILE_TABLE_NAME "p5InputScfile" 70 #define P5DIFFSCFILE_TABLE_NAME "p5DiffScfile" 68 71 #define MAX_STRING_LENGTH 1024 69 72 … … 14960 14963 return true; 14961 14964 } 14965 static void p5RunRowFree(p5RunRow *object); 14966 14967 p5RunRow *p5RunRowAlloc(psS32 p5_id, const char *state, const char *workdir, psTime* registered) 14968 { 14969 p5RunRow *_object; 14970 14971 _object = psAlloc(sizeof(p5RunRow)); 14972 psMemSetDeallocator(_object, (psFreeFunc)p5RunRowFree); 14973 14974 _object->p5_id = p5_id; 14975 _object->state = psStringCopy(state); 14976 _object->workdir = psStringCopy(workdir); 14977 _object->registered = psTimeCopy(registered); 14978 14979 return _object; 14980 } 14981 14982 static void p5RunRowFree(p5RunRow *object) 14983 { 14984 psFree(object->state); 14985 psFree(object->workdir); 14986 psFree(object->registered); 14987 } 14988 14989 bool p5RunCreateTable(psDB *dbh) 14990 { 14991 psMetadata *md = psMetadataAlloc(); 14992 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) { 14993 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 14994 psFree(md); 14995 return false; 14996 } 14997 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 14998 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 14999 psFree(md); 15000 return false; 15001 } 15002 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 15003 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15004 psFree(md); 15005 return false; 15006 } 15007 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) { 15008 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 15009 psFree(md); 15010 return false; 15011 } 15012 15013 bool status = psDBCreateTable(dbh, P5RUN_TABLE_NAME, md); 15014 15015 psFree(md); 15016 15017 return status; 15018 } 15019 15020 bool p5RunDropTable(psDB *dbh) 15021 { 15022 return psDBDropTable(dbh, P5RUN_TABLE_NAME); 15023 } 15024 15025 bool p5RunInsert(psDB * dbh, psS32 p5_id, const char *state, const char *workdir, psTime* registered) 15026 { 15027 psMetadata *md = psMetadataAlloc(); 15028 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, p5_id)) { 15029 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15030 psFree(md); 15031 return false; 15032 } 15033 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 15034 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 15035 psFree(md); 15036 return false; 15037 } 15038 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 15039 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15040 psFree(md); 15041 return false; 15042 } 15043 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 15044 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 15045 psFree(md); 15046 return false; 15047 } 15048 15049 bool status = psDBInsertOneRow(dbh, P5RUN_TABLE_NAME, md); 15050 psFree(md); 15051 15052 return status; 15053 } 15054 15055 long long p5RunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15056 { 15057 long long deleted = 0; 15058 15059 long long count = psDBDeleteRows(dbh, P5RUN_TABLE_NAME, where, limit); 15060 if (count < 0) { 15061 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5Run"); 15062 return count; 15063 15064 deleted += count; 15065 } 15066 15067 return deleted; 15068 } 15069 bool p5RunInsertObject(psDB *dbh, p5RunRow *object) 15070 { 15071 return p5RunInsert(dbh, object->p5_id, object->state, object->workdir, object->registered); 15072 } 15073 15074 bool p5RunInsertObjects(psDB *dbh, psArray *objects) 15075 { 15076 for (long i = 0; i < psArrayLength(objects); i++) { 15077 if (!p5RunInsertObject(dbh, objects->data[i])) { 15078 return false; 15079 } 15080 } 15081 15082 return true; 15083 } 15084 15085 bool p5RunInsertFits(psDB *dbh, const psFits *fits) 15086 { 15087 psArray *rowSet; 15088 15089 // move to (the first?) extension named P5RUN_TABLE_NAME 15090 if (!psFitsMoveExtName(fits, P5RUN_TABLE_NAME)) { 15091 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5RUN_TABLE_NAME); 15092 return false; 15093 } 15094 15095 // check HDU type 15096 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15097 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15098 return false; 15099 } 15100 15101 // read fits table 15102 rowSet = psFitsReadTable(fits); 15103 if (!rowSet) { 15104 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15105 psFree(rowSet); 15106 return false; 15107 } 15108 15109 if (!psDBInsertRows(dbh, P5RUN_TABLE_NAME, rowSet)) { 15110 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15111 psFree(rowSet); 15112 return false; 15113 } 15114 15115 psFree(rowSet); 15116 15117 return true; 15118 } 15119 15120 bool p5RunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15121 { 15122 psArray *rowSet; 15123 15124 rowSet = psDBSelectRows(dbh, P5RUN_TABLE_NAME, where, limit); 15125 if (!rowSet) { 15126 return false; 15127 } 15128 15129 // output to fits 15130 if (!psFitsWriteTable(fits, NULL, rowSet, P5RUN_TABLE_NAME)) { 15131 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15132 psFree(rowSet); 15133 return false; 15134 } 15135 15136 psFree(rowSet); 15137 15138 return true; 15139 } 15140 15141 psMetadata *p5RunMetadataFromObject(const p5RunRow *object) 15142 { 15143 psMetadata *md = psMetadataAlloc(); 15144 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, object->p5_id)) { 15145 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15146 psFree(md); 15147 return false; 15148 } 15149 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 15150 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 15151 psFree(md); 15152 return false; 15153 } 15154 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 15155 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15156 psFree(md); 15157 return false; 15158 } 15159 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) { 15160 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 15161 psFree(md); 15162 return false; 15163 } 15164 15165 15166 return md; 15167 } 15168 15169 p5RunRow *p5RunObjectFromMetadata(psMetadata *md) 15170 { 15171 15172 bool status = false; 15173 psS32 p5_id = psMetadataLookupS32(&status, md, "p5_id"); 15174 if (!status) { 15175 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p5_id"); 15176 return false; 15177 } 15178 char* state = psMetadataLookupPtr(&status, md, "state"); 15179 if (!status) { 15180 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 15181 return false; 15182 } 15183 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 15184 if (!status) { 15185 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 15186 return false; 15187 } 15188 psTime* registered = psMetadataLookupPtr(&status, md, "registered"); 15189 if (!status) { 15190 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered"); 15191 return false; 15192 } 15193 15194 return p5RunRowAlloc(p5_id, state, workdir, registered); 15195 } 15196 psArray *p5RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15197 { 15198 psArray *rowSet; 15199 psArray *returnSet; 15200 psU64 i; 15201 15202 rowSet = psDBSelectRows(dbh, P5RUN_TABLE_NAME, where, limit); 15203 if (!rowSet) { 15204 return NULL; 15205 } 15206 15207 // convert psMetadata rows to row objects 15208 15209 returnSet = psArrayAllocEmpty(rowSet->n); 15210 15211 for (i = 0; i < rowSet->n; i++) { 15212 p5RunRow *object = p5RunObjectFromMetadata(rowSet->data[i]); 15213 psArrayAdd(returnSet, 0, object); 15214 psFree(object); 15215 } 15216 15217 psFree(rowSet); 15218 15219 return returnSet; 15220 } 15221 bool p5RunDeleteObject(psDB *dbh, const p5RunRow *object) 15222 { 15223 psMetadata *where = p5RunMetadataFromObject(object); 15224 long long count = psDBDeleteRows(dbh, P5RUN_TABLE_NAME, where, 0); 15225 psFree(where); 15226 if (count < 0) { 15227 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5Run"); 15228 return false; 15229 } 15230 if (count > 1) { 15231 // XXX should this be a psAbort() instead? It is possible that 15232 // having an object match multiple rows was by design. 15233 psError(PS_ERR_UNKNOWN, true, "p5RunRow object matched more then one row. Check your database schema"); 15234 return false; 15235 } 15236 15237 return true; 15238 } 15239 long long p5RunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15240 { 15241 long long deleted = 0; 15242 15243 for (long long i = 0; i < objects->n; i++) { 15244 p5RunRow *object = objects->data[i]; 15245 psMetadata *where = p5RunMetadataFromObject(object); 15246 long long count = psDBDeleteRows(dbh, P5RUN_TABLE_NAME, where, limit); 15247 psFree(where); 15248 if (count < 0) { 15249 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5Run"); 15250 return count; 15251 } 15252 15253 deleted += count; 15254 } 15255 15256 return deleted; 15257 } 15258 bool p5RunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 15259 { 15260 PS_ASSERT_PTR_NON_NULL(objects, false); 15261 15262 psMetadata *output = psMetadataAlloc(); 15263 for (long i = 0; i < psArrayLength(objects); i++) { 15264 psMetadata *md = p5RunMetadataFromObject(objects->data[i]); 15265 if (!psMetadataAddMetadata( 15266 output, 15267 PS_LIST_TAIL, 15268 P5RUN_TABLE_NAME, 15269 PS_META_DUPLICATE_OK, 15270 NULL, 15271 md 15272 )) { 15273 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15274 psFree(md); 15275 psFree(output); 15276 return false; 15277 } 15278 psFree(md); 15279 } 15280 15281 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15282 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15283 psFree(output); 15284 } 15285 psFree(output); 15286 15287 return true; 15288 } 15289 bool p5RunPrintObject(FILE *stream, p5RunRow *object, bool mdcf) 15290 { 15291 PS_ASSERT_PTR_NON_NULL(object, false); 15292 15293 psMetadata *md = p5RunMetadataFromObject(object); 15294 15295 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 15296 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15297 psFree(md); 15298 } 15299 15300 psFree(md); 15301 15302 return true; 15303 } 15304 static void p5InputScfileRowFree(p5InputScfileRow *object); 15305 15306 p5InputScfileRow *p5InputScfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind, bool template) 15307 { 15308 p5InputScfileRow *_object; 15309 15310 _object = psAlloc(sizeof(p5InputScfileRow)); 15311 psMemSetDeallocator(_object, (psFreeFunc)p5InputScfileRowFree); 15312 15313 _object->p5_id = p5_id; 15314 _object->p4_id = p4_id; 15315 _object->skycell_id = psStringCopy(skycell_id); 15316 _object->tess_id = psStringCopy(tess_id); 15317 _object->exp_tag = psStringCopy(exp_tag); 15318 _object->p3_version = p3_version; 15319 _object->kind = psStringCopy(kind); 15320 _object->template = template; 15321 15322 return _object; 15323 } 15324 15325 static void p5InputScfileRowFree(p5InputScfileRow *object) 15326 { 15327 psFree(object->skycell_id); 15328 psFree(object->tess_id); 15329 psFree(object->exp_tag); 15330 psFree(object->kind); 15331 } 15332 15333 bool p5InputScfileCreateTable(psDB *dbh) 15334 { 15335 psMetadata *md = psMetadataAlloc(); 15336 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, "Primary Key", 0)) { 15337 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15338 psFree(md); 15339 return false; 15340 } 15341 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) { 15342 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15343 psFree(md); 15344 return false; 15345 } 15346 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 15347 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15348 psFree(md); 15349 return false; 15350 } 15351 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 15352 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15353 psFree(md); 15354 return false; 15355 } 15356 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 15357 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15358 psFree(md); 15359 return false; 15360 } 15361 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 15362 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15363 psFree(md); 15364 return false; 15365 } 15366 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) { 15367 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 15368 psFree(md); 15369 return false; 15370 } 15371 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, 0)) { 15372 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 15373 psFree(md); 15374 return false; 15375 } 15376 15377 bool status = psDBCreateTable(dbh, P5INPUTSCFILE_TABLE_NAME, md); 15378 15379 psFree(md); 15380 15381 return status; 15382 } 15383 15384 bool p5InputScfileDropTable(psDB *dbh) 15385 { 15386 return psDBDropTable(dbh, P5INPUTSCFILE_TABLE_NAME); 15387 } 15388 15389 bool p5InputScfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind, bool template) 15390 { 15391 psMetadata *md = psMetadataAlloc(); 15392 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, p5_id)) { 15393 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15394 psFree(md); 15395 return false; 15396 } 15397 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) { 15398 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15399 psFree(md); 15400 return false; 15401 } 15402 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 15403 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15404 psFree(md); 15405 return false; 15406 } 15407 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 15408 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15409 psFree(md); 15410 return false; 15411 } 15412 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 15413 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15414 psFree(md); 15415 return false; 15416 } 15417 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 15418 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15419 psFree(md); 15420 return false; 15421 } 15422 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) { 15423 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 15424 psFree(md); 15425 return false; 15426 } 15427 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, template)) { 15428 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 15429 psFree(md); 15430 return false; 15431 } 15432 15433 bool status = psDBInsertOneRow(dbh, P5INPUTSCFILE_TABLE_NAME, md); 15434 psFree(md); 15435 15436 return status; 15437 } 15438 15439 long long p5InputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15440 { 15441 long long deleted = 0; 15442 15443 long long count = psDBDeleteRows(dbh, P5INPUTSCFILE_TABLE_NAME, where, limit); 15444 if (count < 0) { 15445 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputScfile"); 15446 return count; 15447 15448 deleted += count; 15449 } 15450 15451 return deleted; 15452 } 15453 bool p5InputScfileInsertObject(psDB *dbh, p5InputScfileRow *object) 15454 { 15455 return p5InputScfileInsert(dbh, object->p5_id, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind, object->template); 15456 } 15457 15458 bool p5InputScfileInsertObjects(psDB *dbh, psArray *objects) 15459 { 15460 for (long i = 0; i < psArrayLength(objects); i++) { 15461 if (!p5InputScfileInsertObject(dbh, objects->data[i])) { 15462 return false; 15463 } 15464 } 15465 15466 return true; 15467 } 15468 15469 bool p5InputScfileInsertFits(psDB *dbh, const psFits *fits) 15470 { 15471 psArray *rowSet; 15472 15473 // move to (the first?) extension named P5INPUTSCFILE_TABLE_NAME 15474 if (!psFitsMoveExtName(fits, P5INPUTSCFILE_TABLE_NAME)) { 15475 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5INPUTSCFILE_TABLE_NAME); 15476 return false; 15477 } 15478 15479 // check HDU type 15480 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15481 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15482 return false; 15483 } 15484 15485 // read fits table 15486 rowSet = psFitsReadTable(fits); 15487 if (!rowSet) { 15488 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15489 psFree(rowSet); 15490 return false; 15491 } 15492 15493 if (!psDBInsertRows(dbh, P5INPUTSCFILE_TABLE_NAME, rowSet)) { 15494 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15495 psFree(rowSet); 15496 return false; 15497 } 15498 15499 psFree(rowSet); 15500 15501 return true; 15502 } 15503 15504 bool p5InputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15505 { 15506 psArray *rowSet; 15507 15508 rowSet = psDBSelectRows(dbh, P5INPUTSCFILE_TABLE_NAME, where, limit); 15509 if (!rowSet) { 15510 return false; 15511 } 15512 15513 // output to fits 15514 if (!psFitsWriteTable(fits, NULL, rowSet, P5INPUTSCFILE_TABLE_NAME)) { 15515 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15516 psFree(rowSet); 15517 return false; 15518 } 15519 15520 psFree(rowSet); 15521 15522 return true; 15523 } 15524 15525 psMetadata *p5InputScfileMetadataFromObject(const p5InputScfileRow *object) 15526 { 15527 psMetadata *md = psMetadataAlloc(); 15528 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, object->p5_id)) { 15529 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15530 psFree(md); 15531 return false; 15532 } 15533 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) { 15534 psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id"); 15535 psFree(md); 15536 return false; 15537 } 15538 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 15539 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15540 psFree(md); 15541 return false; 15542 } 15543 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 15544 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15545 psFree(md); 15546 return false; 15547 } 15548 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 15549 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15550 psFree(md); 15551 return false; 15552 } 15553 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 15554 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15555 psFree(md); 15556 return false; 15557 } 15558 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) { 15559 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 15560 psFree(md); 15561 return false; 15562 } 15563 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, object->template)) { 15564 psError(PS_ERR_UNKNOWN, false, "failed to add item template"); 15565 psFree(md); 15566 return false; 15567 } 15568 15569 15570 return md; 15571 } 15572 15573 p5InputScfileRow *p5InputScfileObjectFromMetadata(psMetadata *md) 15574 { 15575 15576 bool status = false; 15577 psS32 p5_id = psMetadataLookupS32(&status, md, "p5_id"); 15578 if (!status) { 15579 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p5_id"); 15580 return false; 15581 } 15582 psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id"); 15583 if (!status) { 15584 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id"); 15585 return false; 15586 } 15587 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 15588 if (!status) { 15589 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 15590 return false; 15591 } 15592 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 15593 if (!status) { 15594 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 15595 return false; 15596 } 15597 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 15598 if (!status) { 15599 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 15600 return false; 15601 } 15602 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 15603 if (!status) { 15604 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 15605 return false; 15606 } 15607 char* kind = psMetadataLookupPtr(&status, md, "kind"); 15608 if (!status) { 15609 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind"); 15610 return false; 15611 } 15612 bool template = psMetadataLookupBool(&status, md, "template"); 15613 if (!status) { 15614 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item template"); 15615 return false; 15616 } 15617 15618 return p5InputScfileRowAlloc(p5_id, p4_id, skycell_id, tess_id, exp_tag, p3_version, kind, template); 15619 } 15620 psArray *p5InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15621 { 15622 psArray *rowSet; 15623 psArray *returnSet; 15624 psU64 i; 15625 15626 rowSet = psDBSelectRows(dbh, P5INPUTSCFILE_TABLE_NAME, where, limit); 15627 if (!rowSet) { 15628 return NULL; 15629 } 15630 15631 // convert psMetadata rows to row objects 15632 15633 returnSet = psArrayAllocEmpty(rowSet->n); 15634 15635 for (i = 0; i < rowSet->n; i++) { 15636 p5InputScfileRow *object = p5InputScfileObjectFromMetadata(rowSet->data[i]); 15637 psArrayAdd(returnSet, 0, object); 15638 psFree(object); 15639 } 15640 15641 psFree(rowSet); 15642 15643 return returnSet; 15644 } 15645 bool p5InputScfileDeleteObject(psDB *dbh, const p5InputScfileRow *object) 15646 { 15647 psMetadata *where = p5InputScfileMetadataFromObject(object); 15648 long long count = psDBDeleteRows(dbh, P5INPUTSCFILE_TABLE_NAME, where, 0); 15649 psFree(where); 15650 if (count < 0) { 15651 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputScfile"); 15652 return false; 15653 } 15654 if (count > 1) { 15655 // XXX should this be a psAbort() instead? It is possible that 15656 // having an object match multiple rows was by design. 15657 psError(PS_ERR_UNKNOWN, true, "p5InputScfileRow object matched more then one row. Check your database schema"); 15658 return false; 15659 } 15660 15661 return true; 15662 } 15663 long long p5InputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15664 { 15665 long long deleted = 0; 15666 15667 for (long long i = 0; i < objects->n; i++) { 15668 p5InputScfileRow *object = objects->data[i]; 15669 psMetadata *where = p5InputScfileMetadataFromObject(object); 15670 long long count = psDBDeleteRows(dbh, P5INPUTSCFILE_TABLE_NAME, where, limit); 15671 psFree(where); 15672 if (count < 0) { 15673 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputScfile"); 15674 return count; 15675 } 15676 15677 deleted += count; 15678 } 15679 15680 return deleted; 15681 } 15682 bool p5InputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15683 { 15684 PS_ASSERT_PTR_NON_NULL(objects, false); 15685 15686 psMetadata *output = psMetadataAlloc(); 15687 for (long i = 0; i < psArrayLength(objects); i++) { 15688 psMetadata *md = p5InputScfileMetadataFromObject(objects->data[i]); 15689 if (!psMetadataAddMetadata( 15690 output, 15691 PS_LIST_TAIL, 15692 P5INPUTSCFILE_TABLE_NAME, 15693 PS_META_DUPLICATE_OK, 15694 NULL, 15695 md 15696 )) { 15697 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15698 psFree(md); 15699 psFree(output); 15700 return false; 15701 } 15702 psFree(md); 15703 } 15704 15705 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15706 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15707 psFree(output); 15708 } 15709 psFree(output); 15710 15711 return true; 15712 } 15713 bool p5InputScfilePrintObject(FILE *stream, p5InputScfileRow *object, bool mdcf) 15714 { 15715 PS_ASSERT_PTR_NON_NULL(object, false); 15716 15717 psMetadata *md = p5InputScfileMetadataFromObject(object); 15718 15719 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 15720 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15721 psFree(md); 15722 } 15723 15724 psFree(md); 15725 15726 return true; 15727 } 15728 static void p5DiffScfileRowFree(p5DiffScfileRow *object); 15729 15730 p5DiffScfileRow *p5DiffScfileRowAlloc(psS32 p5_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 15731 { 15732 p5DiffScfileRow *_object; 15733 15734 _object = psAlloc(sizeof(p5DiffScfileRow)); 15735 psMemSetDeallocator(_object, (psFreeFunc)p5DiffScfileRowFree); 15736 15737 _object->p5_id = p5_id; 15738 _object->skycell_id = psStringCopy(skycell_id); 15739 _object->tess_id = psStringCopy(tess_id); 15740 _object->uri = psStringCopy(uri); 15741 _object->bg = bg; 15742 _object->bg_mean_stdev = bg_mean_stdev; 15743 15744 return _object; 15745 } 15746 15747 static void p5DiffScfileRowFree(p5DiffScfileRow *object) 15748 { 15749 psFree(object->skycell_id); 15750 psFree(object->tess_id); 15751 psFree(object->uri); 15752 } 15753 15754 bool p5DiffScfileCreateTable(psDB *dbh) 15755 { 15756 psMetadata *md = psMetadataAlloc(); 15757 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, "Primary Key", 0)) { 15758 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15759 psFree(md); 15760 return false; 15761 } 15762 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 15763 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15764 psFree(md); 15765 return false; 15766 } 15767 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 15768 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15769 psFree(md); 15770 return false; 15771 } 15772 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 15773 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15774 psFree(md); 15775 return false; 15776 } 15777 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 15778 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15779 psFree(md); 15780 return false; 15781 } 15782 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) { 15783 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15784 psFree(md); 15785 return false; 15786 } 15787 15788 bool status = psDBCreateTable(dbh, P5DIFFSCFILE_TABLE_NAME, md); 15789 15790 psFree(md); 15791 15792 return status; 15793 } 15794 15795 bool p5DiffScfileDropTable(psDB *dbh) 15796 { 15797 return psDBDropTable(dbh, P5DIFFSCFILE_TABLE_NAME); 15798 } 15799 15800 bool p5DiffScfileInsert(psDB * dbh, psS32 p5_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 15801 { 15802 psMetadata *md = psMetadataAlloc(); 15803 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, p5_id)) { 15804 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15805 psFree(md); 15806 return false; 15807 } 15808 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 15809 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15810 psFree(md); 15811 return false; 15812 } 15813 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 15814 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15815 psFree(md); 15816 return false; 15817 } 15818 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 15819 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15820 psFree(md); 15821 return false; 15822 } 15823 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 15824 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15825 psFree(md); 15826 return false; 15827 } 15828 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) { 15829 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15830 psFree(md); 15831 return false; 15832 } 15833 15834 bool status = psDBInsertOneRow(dbh, P5DIFFSCFILE_TABLE_NAME, md); 15835 psFree(md); 15836 15837 return status; 15838 } 15839 15840 long long p5DiffScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15841 { 15842 long long deleted = 0; 15843 15844 long long count = psDBDeleteRows(dbh, P5DIFFSCFILE_TABLE_NAME, where, limit); 15845 if (count < 0) { 15846 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffScfile"); 15847 return count; 15848 15849 deleted += count; 15850 } 15851 15852 return deleted; 15853 } 15854 bool p5DiffScfileInsertObject(psDB *dbh, p5DiffScfileRow *object) 15855 { 15856 return p5DiffScfileInsert(dbh, object->p5_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_mean_stdev); 15857 } 15858 15859 bool p5DiffScfileInsertObjects(psDB *dbh, psArray *objects) 15860 { 15861 for (long i = 0; i < psArrayLength(objects); i++) { 15862 if (!p5DiffScfileInsertObject(dbh, objects->data[i])) { 15863 return false; 15864 } 15865 } 15866 15867 return true; 15868 } 15869 15870 bool p5DiffScfileInsertFits(psDB *dbh, const psFits *fits) 15871 { 15872 psArray *rowSet; 15873 15874 // move to (the first?) extension named P5DIFFSCFILE_TABLE_NAME 15875 if (!psFitsMoveExtName(fits, P5DIFFSCFILE_TABLE_NAME)) { 15876 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5DIFFSCFILE_TABLE_NAME); 15877 return false; 15878 } 15879 15880 // check HDU type 15881 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15882 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15883 return false; 15884 } 15885 15886 // read fits table 15887 rowSet = psFitsReadTable(fits); 15888 if (!rowSet) { 15889 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15890 psFree(rowSet); 15891 return false; 15892 } 15893 15894 if (!psDBInsertRows(dbh, P5DIFFSCFILE_TABLE_NAME, rowSet)) { 15895 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15896 psFree(rowSet); 15897 return false; 15898 } 15899 15900 psFree(rowSet); 15901 15902 return true; 15903 } 15904 15905 bool p5DiffScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15906 { 15907 psArray *rowSet; 15908 15909 rowSet = psDBSelectRows(dbh, P5DIFFSCFILE_TABLE_NAME, where, limit); 15910 if (!rowSet) { 15911 return false; 15912 } 15913 15914 // output to fits 15915 if (!psFitsWriteTable(fits, NULL, rowSet, P5DIFFSCFILE_TABLE_NAME)) { 15916 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15917 psFree(rowSet); 15918 return false; 15919 } 15920 15921 psFree(rowSet); 15922 15923 return true; 15924 } 15925 15926 psMetadata *p5DiffScfileMetadataFromObject(const p5DiffScfileRow *object) 15927 { 15928 psMetadata *md = psMetadataAlloc(); 15929 if (!psMetadataAdd(md, PS_LIST_TAIL, "p5_id", PS_DATA_S32, NULL, object->p5_id)) { 15930 psError(PS_ERR_UNKNOWN, false, "failed to add item p5_id"); 15931 psFree(md); 15932 return false; 15933 } 15934 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 15935 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15936 psFree(md); 15937 return false; 15938 } 15939 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 15940 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15941 psFree(md); 15942 return false; 15943 } 15944 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 15945 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15946 psFree(md); 15947 return false; 15948 } 15949 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 15950 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15951 psFree(md); 15952 return false; 15953 } 15954 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) { 15955 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15956 psFree(md); 15957 return false; 15958 } 15959 15960 15961 return md; 15962 } 15963 15964 p5DiffScfileRow *p5DiffScfileObjectFromMetadata(psMetadata *md) 15965 { 15966 15967 bool status = false; 15968 psS32 p5_id = psMetadataLookupS32(&status, md, "p5_id"); 15969 if (!status) { 15970 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p5_id"); 15971 return false; 15972 } 15973 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 15974 if (!status) { 15975 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 15976 return false; 15977 } 15978 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 15979 if (!status) { 15980 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 15981 return false; 15982 } 15983 char* uri = psMetadataLookupPtr(&status, md, "uri"); 15984 if (!status) { 15985 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 15986 return false; 15987 } 15988 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 15989 if (!status) { 15990 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 15991 return false; 15992 } 15993 psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev"); 15994 if (!status) { 15995 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev"); 15996 return false; 15997 } 15998 15999 return p5DiffScfileRowAlloc(p5_id, skycell_id, tess_id, uri, bg, bg_mean_stdev); 16000 } 16001 psArray *p5DiffScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 16002 { 16003 psArray *rowSet; 16004 psArray *returnSet; 16005 psU64 i; 16006 16007 rowSet = psDBSelectRows(dbh, P5DIFFSCFILE_TABLE_NAME, where, limit); 16008 if (!rowSet) { 16009 return NULL; 16010 } 16011 16012 // convert psMetadata rows to row objects 16013 16014 returnSet = psArrayAllocEmpty(rowSet->n); 16015 16016 for (i = 0; i < rowSet->n; i++) { 16017 p5DiffScfileRow *object = p5DiffScfileObjectFromMetadata(rowSet->data[i]); 16018 psArrayAdd(returnSet, 0, object); 16019 psFree(object); 16020 } 16021 16022 psFree(rowSet); 16023 16024 return returnSet; 16025 } 16026 bool p5DiffScfileDeleteObject(psDB *dbh, const p5DiffScfileRow *object) 16027 { 16028 psMetadata *where = p5DiffScfileMetadataFromObject(object); 16029 long long count = psDBDeleteRows(dbh, P5DIFFSCFILE_TABLE_NAME, where, 0); 16030 psFree(where); 16031 if (count < 0) { 16032 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffScfile"); 16033 return false; 16034 } 16035 if (count > 1) { 16036 // XXX should this be a psAbort() instead? It is possible that 16037 // having an object match multiple rows was by design. 16038 psError(PS_ERR_UNKNOWN, true, "p5DiffScfileRow object matched more then one row. Check your database schema"); 16039 return false; 16040 } 16041 16042 return true; 16043 } 16044 long long p5DiffScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 16045 { 16046 long long deleted = 0; 16047 16048 for (long long i = 0; i < objects->n; i++) { 16049 p5DiffScfileRow *object = objects->data[i]; 16050 psMetadata *where = p5DiffScfileMetadataFromObject(object); 16051 long long count = psDBDeleteRows(dbh, P5DIFFSCFILE_TABLE_NAME, where, limit); 16052 psFree(where); 16053 if (count < 0) { 16054 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffScfile"); 16055 return count; 16056 } 16057 16058 deleted += count; 16059 } 16060 16061 return deleted; 16062 } 16063 bool p5DiffScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 16064 { 16065 PS_ASSERT_PTR_NON_NULL(objects, false); 16066 16067 psMetadata *output = psMetadataAlloc(); 16068 for (long i = 0; i < psArrayLength(objects); i++) { 16069 psMetadata *md = p5DiffScfileMetadataFromObject(objects->data[i]); 16070 if (!psMetadataAddMetadata( 16071 output, 16072 PS_LIST_TAIL, 16073 P5DIFFSCFILE_TABLE_NAME, 16074 PS_META_DUPLICATE_OK, 16075 NULL, 16076 md 16077 )) { 16078 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 16079 psFree(md); 16080 psFree(output); 16081 return false; 16082 } 16083 psFree(md); 16084 } 16085 16086 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 16087 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 16088 psFree(output); 16089 } 16090 psFree(output); 16091 16092 return true; 16093 } 16094 bool p5DiffScfilePrintObject(FILE *stream, p5DiffScfileRow *object, bool mdcf) 16095 { 16096 PS_ASSERT_PTR_NON_NULL(object, false); 16097 16098 psMetadata *md = p5DiffScfileMetadataFromObject(object); 16099 16100 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 16101 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 16102 psFree(md); 16103 } 16104 16105 psFree(md); 16106 16107 return true; 16108 } -
trunk/ippdb/src/ippdb.h
r11780 r11809 7667 7667 bool mdcf ///< format as mdconfig or simple 7668 7668 ); 7669 /** p5RunRow data structure 7670 * 7671 * Structure for representing a single row of p5Run table data. 7672 */ 7673 7674 typedef struct { 7675 psS32 p5_id; 7676 char *state; 7677 char *workdir; 7678 psTime* registered; 7679 } p5RunRow; 7680 7681 /** Creates a new p5RunRow object 7682 * 7683 * @return A new p5RunRow object or NULL on failure. 7684 */ 7685 7686 p5RunRow *p5RunRowAlloc( 7687 psS32 p5_id, 7688 const char *state, 7689 const char *workdir, 7690 psTime* registered 7691 ); 7692 7693 /** Creates a new p5Run table 7694 * 7695 * @return true on success 7696 */ 7697 7698 bool p5RunCreateTable( 7699 psDB *dbh ///< Database handle 7700 ); 7701 7702 /** Deletes a p5Run table 7703 * 7704 * @return true on success 7705 */ 7706 7707 bool p5RunDropTable( 7708 psDB *dbh ///< Database handle 7709 ); 7710 7711 /** Insert a single row into a table 7712 * 7713 * This function constructs and inserts a single row based on it's parameters. 7714 * 7715 * @return true on success 7716 */ 7717 7718 bool p5RunInsert( 7719 psDB *dbh, ///< Database handle 7720 psS32 p5_id, 7721 const char *state, 7722 const char *workdir, 7723 psTime* registered 7724 ); 7725 7726 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7727 * 7728 * @return A The number of rows removed or a negative value on error 7729 */ 7730 7731 long long p5RunDelete( 7732 psDB *dbh, ///< Database handle 7733 const psMetadata *where, ///< Row match criteria 7734 unsigned long long limit ///< Maximum number of elements to delete 7735 ); 7736 7737 /** Insert a single p5RunRow object into a table 7738 * 7739 * This function constructs and inserts a single row based on it's parameters. 7740 * 7741 * @return true on success 7742 */ 7743 7744 bool p5RunInsertObject( 7745 psDB *dbh, ///< Database handle 7746 p5RunRow *object ///< p5RunRow object 7747 ); 7748 7749 /** Insert an array of p5RunRow object into a table 7750 * 7751 * This function constructs and inserts multiple rows based on it's parameters. 7752 * 7753 * @return true on success 7754 */ 7755 7756 bool p5RunInsertObjects( 7757 psDB *dbh, ///< Database handle 7758 psArray *objects ///< array of p5RunRow objects 7759 ); 7760 7761 /** Insert data from a binary FITS table p5RunRow into the database 7762 * 7763 * This function expects a psFits object with a FITS table as the first 7764 * extension. The table must have at least one row of data in it, that is of 7765 * the appropriate format (number of columns and their type). All other 7766 * extensions are ignored. 7767 * 7768 * @return true on success 7769 */ 7770 7771 bool p5RunInsertFits( 7772 psDB *dbh, ///< Database handle 7773 const psFits *fits ///< psFits object 7774 ); 7775 7776 /** Selects up to limit from the database and returns them in a binary FITS table 7777 * 7778 * This function assumes an empty psFits object and will create a FITS table 7779 * as the first extension. 7780 * 7781 * See psDBSelectRows() for documentation on the format of where. 7782 * 7783 * @return true on success 7784 */ 7785 7786 bool p5RunSelectRowsFits( 7787 psDB *dbh, ///< Database handle 7788 psFits *fits, ///< psFits object 7789 const psMetadata *where, ///< Row match criteria 7790 unsigned long long limit ///< Maximum number of elements to return 7791 ); 7792 7793 /** Convert a p5RunRow into an equivalent psMetadata 7794 * 7795 * @return A psMetadata pointer or NULL on error 7796 */ 7797 7798 psMetadata *p5RunMetadataFromObject( 7799 const p5RunRow *object ///< fooRow to convert into a psMetadata 7800 ); 7801 7802 /** Convert a psMetadata into an equivalent fooRow 7803 * 7804 * @return A p5RunRow pointer or NULL on error 7805 */ 7806 7807 p5RunRow *p5RunObjectFromMetadata( 7808 psMetadata *md ///< psMetadata to convert into a fooRow 7809 ); 7810 /** Selects up to limit rows from the database and returns as p5RunRow objects in a psArray 7811 * 7812 * See psDBSelectRows() for documentation on the format of where. 7813 * 7814 * @return A psArray pointer or NULL on error 7815 */ 7816 7817 psArray *p5RunSelectRowObjects( 7818 psDB *dbh, ///< Database handle 7819 const psMetadata *where, ///< Row match criteria 7820 unsigned long long limit ///< Maximum number of elements to return 7821 ); 7822 /** Deletes a row from the database coresponding to an p5Run 7823 * 7824 * Note that a 'where' search psMetadata is constructed from each object and 7825 * used to find rows to delete. 7826 * 7827 * @return A The number of rows removed or a negative value on error 7828 */ 7829 7830 bool p5RunDeleteObject( 7831 psDB *dbh, ///< Database handle 7832 const p5RunRow *object ///< Object to delete 7833 ); 7834 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7835 * 7836 * Note that a 'where' search psMetadata is constructed from each object and 7837 * used to find rows to delete. 7838 * 7839 * @return A The number of rows removed or a negative value on error 7840 */ 7841 7842 long long p5RunDeleteRowObjects( 7843 psDB *dbh, ///< Database handle 7844 const psArray *objects, ///< Array of objects to delete 7845 unsigned long long limit ///< Maximum number of elements to delete 7846 ); 7847 /** Formats and prints an array of p5RunRow objects 7848 * 7849 * When mdcf is set the formated output is in psMetadataConfig 7850 * format, otherwise it is in a simple tabular format. 7851 * 7852 * @return true on success 7853 */ 7854 7855 bool p5RunPrintObjects( 7856 FILE *stream, ///< a stream 7857 psArray *objects, ///< An array of p5RunRow objects 7858 bool mdcf ///< format as mdconfig or simple 7859 ); 7860 /** Formats and prints an p5RunRow object 7861 * 7862 * When mdcf is set the formated output is in psMetadataConfig 7863 * format, otherwise it is in a simple tabular format. 7864 * 7865 * @return true on success 7866 */ 7867 7868 bool p5RunPrintObject( 7869 FILE *stream, ///< a stream 7870 p5RunRow *object, ///< an p5RunRow object 7871 bool mdcf ///< format as mdconfig or simple 7872 ); 7873 /** p5InputScfileRow data structure 7874 * 7875 * Structure for representing a single row of p5InputScfile table data. 7876 */ 7877 7878 typedef struct { 7879 psS32 p5_id; 7880 psS32 p4_id; 7881 char *skycell_id; 7882 char *tess_id; 7883 char *exp_tag; 7884 psS32 p3_version; 7885 char *kind; 7886 bool template; 7887 } p5InputScfileRow; 7888 7889 /** Creates a new p5InputScfileRow object 7890 * 7891 * @return A new p5InputScfileRow object or NULL on failure. 7892 */ 7893 7894 p5InputScfileRow *p5InputScfileRowAlloc( 7895 psS32 p5_id, 7896 psS32 p4_id, 7897 const char *skycell_id, 7898 const char *tess_id, 7899 const char *exp_tag, 7900 psS32 p3_version, 7901 const char *kind, 7902 bool template 7903 ); 7904 7905 /** Creates a new p5InputScfile table 7906 * 7907 * @return true on success 7908 */ 7909 7910 bool p5InputScfileCreateTable( 7911 psDB *dbh ///< Database handle 7912 ); 7913 7914 /** Deletes a p5InputScfile table 7915 * 7916 * @return true on success 7917 */ 7918 7919 bool p5InputScfileDropTable( 7920 psDB *dbh ///< Database handle 7921 ); 7922 7923 /** Insert a single row into a table 7924 * 7925 * This function constructs and inserts a single row based on it's parameters. 7926 * 7927 * @return true on success 7928 */ 7929 7930 bool p5InputScfileInsert( 7931 psDB *dbh, ///< Database handle 7932 psS32 p5_id, 7933 psS32 p4_id, 7934 const char *skycell_id, 7935 const char *tess_id, 7936 const char *exp_tag, 7937 psS32 p3_version, 7938 const char *kind, 7939 bool template 7940 ); 7941 7942 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7943 * 7944 * @return A The number of rows removed or a negative value on error 7945 */ 7946 7947 long long p5InputScfileDelete( 7948 psDB *dbh, ///< Database handle 7949 const psMetadata *where, ///< Row match criteria 7950 unsigned long long limit ///< Maximum number of elements to delete 7951 ); 7952 7953 /** Insert a single p5InputScfileRow object into a table 7954 * 7955 * This function constructs and inserts a single row based on it's parameters. 7956 * 7957 * @return true on success 7958 */ 7959 7960 bool p5InputScfileInsertObject( 7961 psDB *dbh, ///< Database handle 7962 p5InputScfileRow *object ///< p5InputScfileRow object 7963 ); 7964 7965 /** Insert an array of p5InputScfileRow object into a table 7966 * 7967 * This function constructs and inserts multiple rows based on it's parameters. 7968 * 7969 * @return true on success 7970 */ 7971 7972 bool p5InputScfileInsertObjects( 7973 psDB *dbh, ///< Database handle 7974 psArray *objects ///< array of p5InputScfileRow objects 7975 ); 7976 7977 /** Insert data from a binary FITS table p5InputScfileRow into the database 7978 * 7979 * This function expects a psFits object with a FITS table as the first 7980 * extension. The table must have at least one row of data in it, that is of 7981 * the appropriate format (number of columns and their type). All other 7982 * extensions are ignored. 7983 * 7984 * @return true on success 7985 */ 7986 7987 bool p5InputScfileInsertFits( 7988 psDB *dbh, ///< Database handle 7989 const psFits *fits ///< psFits object 7990 ); 7991 7992 /** Selects up to limit from the database and returns them in a binary FITS table 7993 * 7994 * This function assumes an empty psFits object and will create a FITS table 7995 * as the first extension. 7996 * 7997 * See psDBSelectRows() for documentation on the format of where. 7998 * 7999 * @return true on success 8000 */ 8001 8002 bool p5InputScfileSelectRowsFits( 8003 psDB *dbh, ///< Database handle 8004 psFits *fits, ///< psFits object 8005 const psMetadata *where, ///< Row match criteria 8006 unsigned long long limit ///< Maximum number of elements to return 8007 ); 8008 8009 /** Convert a p5InputScfileRow into an equivalent psMetadata 8010 * 8011 * @return A psMetadata pointer or NULL on error 8012 */ 8013 8014 psMetadata *p5InputScfileMetadataFromObject( 8015 const p5InputScfileRow *object ///< fooRow to convert into a psMetadata 8016 ); 8017 8018 /** Convert a psMetadata into an equivalent fooRow 8019 * 8020 * @return A p5InputScfileRow pointer or NULL on error 8021 */ 8022 8023 p5InputScfileRow *p5InputScfileObjectFromMetadata( 8024 psMetadata *md ///< psMetadata to convert into a fooRow 8025 ); 8026 /** Selects up to limit rows from the database and returns as p5InputScfileRow objects in a psArray 8027 * 8028 * See psDBSelectRows() for documentation on the format of where. 8029 * 8030 * @return A psArray pointer or NULL on error 8031 */ 8032 8033 psArray *p5InputScfileSelectRowObjects( 8034 psDB *dbh, ///< Database handle 8035 const psMetadata *where, ///< Row match criteria 8036 unsigned long long limit ///< Maximum number of elements to return 8037 ); 8038 /** Deletes a row from the database coresponding to an p5InputScfile 8039 * 8040 * Note that a 'where' search psMetadata is constructed from each object and 8041 * used to find rows to delete. 8042 * 8043 * @return A The number of rows removed or a negative value on error 8044 */ 8045 8046 bool p5InputScfileDeleteObject( 8047 psDB *dbh, ///< Database handle 8048 const p5InputScfileRow *object ///< Object to delete 8049 ); 8050 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8051 * 8052 * Note that a 'where' search psMetadata is constructed from each object and 8053 * used to find rows to delete. 8054 * 8055 * @return A The number of rows removed or a negative value on error 8056 */ 8057 8058 long long p5InputScfileDeleteRowObjects( 8059 psDB *dbh, ///< Database handle 8060 const psArray *objects, ///< Array of objects to delete 8061 unsigned long long limit ///< Maximum number of elements to delete 8062 ); 8063 /** Formats and prints an array of p5InputScfileRow objects 8064 * 8065 * When mdcf is set the formated output is in psMetadataConfig 8066 * format, otherwise it is in a simple tabular format. 8067 * 8068 * @return true on success 8069 */ 8070 8071 bool p5InputScfilePrintObjects( 8072 FILE *stream, ///< a stream 8073 psArray *objects, ///< An array of p5InputScfileRow objects 8074 bool mdcf ///< format as mdconfig or simple 8075 ); 8076 /** Formats and prints an p5InputScfileRow object 8077 * 8078 * When mdcf is set the formated output is in psMetadataConfig 8079 * format, otherwise it is in a simple tabular format. 8080 * 8081 * @return true on success 8082 */ 8083 8084 bool p5InputScfilePrintObject( 8085 FILE *stream, ///< a stream 8086 p5InputScfileRow *object, ///< an p5InputScfileRow object 8087 bool mdcf ///< format as mdconfig or simple 8088 ); 8089 /** p5DiffScfileRow data structure 8090 * 8091 * Structure for representing a single row of p5DiffScfile table data. 8092 */ 8093 8094 typedef struct { 8095 psS32 p5_id; 8096 char *skycell_id; 8097 char *tess_id; 8098 char *uri; 8099 psF64 bg; 8100 psF64 bg_mean_stdev; 8101 } p5DiffScfileRow; 8102 8103 /** Creates a new p5DiffScfileRow object 8104 * 8105 * @return A new p5DiffScfileRow object or NULL on failure. 8106 */ 8107 8108 p5DiffScfileRow *p5DiffScfileRowAlloc( 8109 psS32 p5_id, 8110 const char *skycell_id, 8111 const char *tess_id, 8112 const char *uri, 8113 psF64 bg, 8114 psF64 bg_mean_stdev 8115 ); 8116 8117 /** Creates a new p5DiffScfile table 8118 * 8119 * @return true on success 8120 */ 8121 8122 bool p5DiffScfileCreateTable( 8123 psDB *dbh ///< Database handle 8124 ); 8125 8126 /** Deletes a p5DiffScfile table 8127 * 8128 * @return true on success 8129 */ 8130 8131 bool p5DiffScfileDropTable( 8132 psDB *dbh ///< Database handle 8133 ); 8134 8135 /** Insert a single row into a table 8136 * 8137 * This function constructs and inserts a single row based on it's parameters. 8138 * 8139 * @return true on success 8140 */ 8141 8142 bool p5DiffScfileInsert( 8143 psDB *dbh, ///< Database handle 8144 psS32 p5_id, 8145 const char *skycell_id, 8146 const char *tess_id, 8147 const char *uri, 8148 psF64 bg, 8149 psF64 bg_mean_stdev 8150 ); 8151 8152 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8153 * 8154 * @return A The number of rows removed or a negative value on error 8155 */ 8156 8157 long long p5DiffScfileDelete( 8158 psDB *dbh, ///< Database handle 8159 const psMetadata *where, ///< Row match criteria 8160 unsigned long long limit ///< Maximum number of elements to delete 8161 ); 8162 8163 /** Insert a single p5DiffScfileRow object into a table 8164 * 8165 * This function constructs and inserts a single row based on it's parameters. 8166 * 8167 * @return true on success 8168 */ 8169 8170 bool p5DiffScfileInsertObject( 8171 psDB *dbh, ///< Database handle 8172 p5DiffScfileRow *object ///< p5DiffScfileRow object 8173 ); 8174 8175 /** Insert an array of p5DiffScfileRow object into a table 8176 * 8177 * This function constructs and inserts multiple rows based on it's parameters. 8178 * 8179 * @return true on success 8180 */ 8181 8182 bool p5DiffScfileInsertObjects( 8183 psDB *dbh, ///< Database handle 8184 psArray *objects ///< array of p5DiffScfileRow objects 8185 ); 8186 8187 /** Insert data from a binary FITS table p5DiffScfileRow into the database 8188 * 8189 * This function expects a psFits object with a FITS table as the first 8190 * extension. The table must have at least one row of data in it, that is of 8191 * the appropriate format (number of columns and their type). All other 8192 * extensions are ignored. 8193 * 8194 * @return true on success 8195 */ 8196 8197 bool p5DiffScfileInsertFits( 8198 psDB *dbh, ///< Database handle 8199 const psFits *fits ///< psFits object 8200 ); 8201 8202 /** Selects up to limit from the database and returns them in a binary FITS table 8203 * 8204 * This function assumes an empty psFits object and will create a FITS table 8205 * as the first extension. 8206 * 8207 * See psDBSelectRows() for documentation on the format of where. 8208 * 8209 * @return true on success 8210 */ 8211 8212 bool p5DiffScfileSelectRowsFits( 8213 psDB *dbh, ///< Database handle 8214 psFits *fits, ///< psFits object 8215 const psMetadata *where, ///< Row match criteria 8216 unsigned long long limit ///< Maximum number of elements to return 8217 ); 8218 8219 /** Convert a p5DiffScfileRow into an equivalent psMetadata 8220 * 8221 * @return A psMetadata pointer or NULL on error 8222 */ 8223 8224 psMetadata *p5DiffScfileMetadataFromObject( 8225 const p5DiffScfileRow *object ///< fooRow to convert into a psMetadata 8226 ); 8227 8228 /** Convert a psMetadata into an equivalent fooRow 8229 * 8230 * @return A p5DiffScfileRow pointer or NULL on error 8231 */ 8232 8233 p5DiffScfileRow *p5DiffScfileObjectFromMetadata( 8234 psMetadata *md ///< psMetadata to convert into a fooRow 8235 ); 8236 /** Selects up to limit rows from the database and returns as p5DiffScfileRow objects in a psArray 8237 * 8238 * See psDBSelectRows() for documentation on the format of where. 8239 * 8240 * @return A psArray pointer or NULL on error 8241 */ 8242 8243 psArray *p5DiffScfileSelectRowObjects( 8244 psDB *dbh, ///< Database handle 8245 const psMetadata *where, ///< Row match criteria 8246 unsigned long long limit ///< Maximum number of elements to return 8247 ); 8248 /** Deletes a row from the database coresponding to an p5DiffScfile 8249 * 8250 * Note that a 'where' search psMetadata is constructed from each object and 8251 * used to find rows to delete. 8252 * 8253 * @return A The number of rows removed or a negative value on error 8254 */ 8255 8256 bool p5DiffScfileDeleteObject( 8257 psDB *dbh, ///< Database handle 8258 const p5DiffScfileRow *object ///< Object to delete 8259 ); 8260 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8261 * 8262 * Note that a 'where' search psMetadata is constructed from each object and 8263 * used to find rows to delete. 8264 * 8265 * @return A The number of rows removed or a negative value on error 8266 */ 8267 8268 long long p5DiffScfileDeleteRowObjects( 8269 psDB *dbh, ///< Database handle 8270 const psArray *objects, ///< Array of objects to delete 8271 unsigned long long limit ///< Maximum number of elements to delete 8272 ); 8273 /** Formats and prints an array of p5DiffScfileRow objects 8274 * 8275 * When mdcf is set the formated output is in psMetadataConfig 8276 * format, otherwise it is in a simple tabular format. 8277 * 8278 * @return true on success 8279 */ 8280 8281 bool p5DiffScfilePrintObjects( 8282 FILE *stream, ///< a stream 8283 psArray *objects, ///< An array of p5DiffScfileRow objects 8284 bool mdcf ///< format as mdconfig or simple 8285 ); 8286 /** Formats and prints an p5DiffScfileRow object 8287 * 8288 * When mdcf is set the formated output is in psMetadataConfig 8289 * format, otherwise it is in a simple tabular format. 8290 * 8291 * @return true on success 8292 */ 8293 8294 bool p5DiffScfilePrintObject( 8295 FILE *stream, ///< a stream 8296 p5DiffScfileRow *object, ///< an p5DiffScfileRow object 8297 bool mdcf ///< format as mdconfig or simple 8298 ); 7669 8299 7670 8300 /// @} … … 7674 8304 #endif 7675 8305 7676 #endif // P 4SCFILE_DB_H8306 #endif // P5DIFFSCFILE_DB_H -
trunk/ippdb/tests/alloc.c
r11780 r11809 1550 1550 } 1551 1551 1552 { 1553 p5RunRow *object; 1554 1555 object = p5RunRowAlloc(-32, "a string", "a string", "0001-01-01T00:00:00Z" ); 1556 1557 if (!object) { 1558 exit(EXIT_FAILURE); 1559 } 1560 1561 if (!object->p5_id == -32) { 1562 psFree(object); 1563 exit(EXIT_FAILURE); 1564 } 1565 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 1566 psFree(object); 1567 exit(EXIT_FAILURE); 1568 } 1569 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 1570 psFree(object); 1571 exit(EXIT_FAILURE); 1572 } 1573 psFree(object); 1574 exit(EXIT_FAILURE); 1575 } 1576 1577 psFree(object); 1578 } 1579 1580 { 1581 p5InputScfileRow *object; 1582 1583 object = p5InputScfileRowAlloc(-32, -32, "a string", "a string", "a string", -32, "a string", true ); 1584 1585 if (!object) { 1586 exit(EXIT_FAILURE); 1587 } 1588 1589 if (!object->p5_id == -32) { 1590 psFree(object); 1591 exit(EXIT_FAILURE); 1592 } 1593 if (!object->p4_id == -32) { 1594 psFree(object); 1595 exit(EXIT_FAILURE); 1596 } 1597 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1598 psFree(object); 1599 exit(EXIT_FAILURE); 1600 } 1601 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1602 psFree(object); 1603 exit(EXIT_FAILURE); 1604 } 1605 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1606 psFree(object); 1607 exit(EXIT_FAILURE); 1608 } 1609 if (!object->p3_version == -32) { 1610 psFree(object); 1611 exit(EXIT_FAILURE); 1612 } 1613 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) { 1614 psFree(object); 1615 exit(EXIT_FAILURE); 1616 } 1617 if (!object->template == true) { 1618 psFree(object); 1619 exit(EXIT_FAILURE); 1620 } 1621 1622 psFree(object); 1623 } 1624 1625 { 1626 p5DiffScfileRow *object; 1627 1628 object = p5DiffScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64 ); 1629 1630 if (!object) { 1631 exit(EXIT_FAILURE); 1632 } 1633 1634 if (!object->p5_id == -32) { 1635 psFree(object); 1636 exit(EXIT_FAILURE); 1637 } 1638 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 1639 psFree(object); 1640 exit(EXIT_FAILURE); 1641 } 1642 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 1643 psFree(object); 1644 exit(EXIT_FAILURE); 1645 } 1646 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1647 psFree(object); 1648 exit(EXIT_FAILURE); 1649 } 1650 if (!object->bg == 64.64) { 1651 psFree(object); 1652 exit(EXIT_FAILURE); 1653 } 1654 if (!object->bg_mean_stdev == 64.64) { 1655 psFree(object); 1656 exit(EXIT_FAILURE); 1657 } 1658 1659 psFree(object); 1660 } 1661 1552 1662 exit(EXIT_SUCCESS); 1553 1663 } -
trunk/ippdb/tests/createtable.c
r11780 r11809 530 530 } 531 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if(!p5RunCreateTable(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(!p5InputScfileCreateTable(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(!p5DiffScfileCreateTable(dbh)) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 532 577 exit(EXIT_SUCCESS); 533 578 } -
trunk/ippdb/tests/dbcleanup.c
r11780 r11809 46 46 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4SkyCellMap"); 47 47 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p4Scfile"); 48 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5Run"); 49 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5InputScfile"); 50 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5DiffScfile"); 48 51 49 52 psDBCleanup(dbh); -
trunk/ippdb/tests/dbsetup.c
r11780 r11809 118 118 p4ScfileCreateTable(dbh); 119 119 120 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5Run"); 121 p5RunCreateTable(dbh); 122 123 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5InputScfile"); 124 p5InputScfileCreateTable(dbh); 125 126 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5DiffScfile"); 127 p5DiffScfileCreateTable(dbh); 128 120 129 psDBCleanup(dbh); 121 130 -
trunk/ippdb/tests/droptable.c
r11780 r11809 530 530 } 531 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if (!p5RunDropTable(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 (!p5InputScfileDropTable(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 (!p5DiffScfileDropTable(dbh)) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 532 577 exit(EXIT_SUCCESS); 533 578 } -
trunk/ippdb/tests/insert.c
r11780 r11809 530 530 } 531 531 532 { 533 psDB *dbh; 534 535 dbh = psDBInit("localhost", "test", NULL, "test"); 536 if (!dbh) { 537 exit(EXIT_FAILURE); 538 } 539 540 if (!p5RunInsert(dbh, -32, "a string", "a string", "0001-01-01T00:00:00Z")) { 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 (!p5InputScfileInsert(dbh, -32, -32, "a string", "a string", "a string", -32, "a string", true)) { 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 (!p5DiffScfileInsert(dbh, -32, "a string", "a string", "a string", 64.64, 64.64)) { 571 exit(EXIT_FAILURE); 572 } 573 574 psDBCleanup(dbh); 575 } 576 532 577 exit(EXIT_SUCCESS); 533 578 } -
trunk/ippdb/tests/insertfits.c
r11780 r11809 919 919 } 920 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 (!p5RunInsertFits(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 (!p5InputScfileInsertFits(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 (!p5DiffScfileInsertFits(dbh, fits)) { 989 exit(EXIT_FAILURE); 990 } 991 992 if (!psFitsClose(fits)) { 993 exit(EXIT_FAILURE); 994 } 995 996 psDBCleanup(dbh); 997 } 998 921 999 exit(EXIT_SUCCESS); 922 1000 } -
trunk/ippdb/tests/insertobject.c
r11780 r11809 775 775 } 776 776 777 { 778 psDB *dbh; 779 p5RunRow *object; 780 781 dbh = psDBInit("localhost", "test", NULL, "test"); 782 if (!dbh) { 783 exit(EXIT_FAILURE); 784 } 785 786 object = p5RunRowAlloc(-32, "a string", "a string", "0001-01-01T00:00:00Z"); 787 if (!object) { 788 exit(EXIT_FAILURE); 789 } 790 791 if (!p5RunInsertObject(dbh, object)) { 792 exit(EXIT_FAILURE); 793 } 794 795 psFree(object); 796 psDBCleanup(dbh); 797 } 798 799 { 800 psDB *dbh; 801 p5InputScfileRow *object; 802 803 dbh = psDBInit("localhost", "test", NULL, "test"); 804 if (!dbh) { 805 exit(EXIT_FAILURE); 806 } 807 808 object = p5InputScfileRowAlloc(-32, -32, "a string", "a string", "a string", -32, "a string", true); 809 if (!object) { 810 exit(EXIT_FAILURE); 811 } 812 813 if (!p5InputScfileInsertObject(dbh, object)) { 814 exit(EXIT_FAILURE); 815 } 816 817 psFree(object); 818 psDBCleanup(dbh); 819 } 820 821 { 822 psDB *dbh; 823 p5DiffScfileRow *object; 824 825 dbh = psDBInit("localhost", "test", NULL, "test"); 826 if (!dbh) { 827 exit(EXIT_FAILURE); 828 } 829 830 object = p5DiffScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64); 831 if (!object) { 832 exit(EXIT_FAILURE); 833 } 834 835 if (!p5DiffScfileInsertObject(dbh, object)) { 836 exit(EXIT_FAILURE); 837 } 838 839 psFree(object); 840 psDBCleanup(dbh); 841 } 842 777 843 exit(EXIT_SUCCESS); 778 844 } -
trunk/ippdb/tests/metadatafromobject.c
r11780 r11809 1816 1816 } 1817 1817 1818 { 1819 psMetadata *md; 1820 p5RunRow *object; 1821 bool status; 1822 1823 object = p5RunRowAlloc(-32, "a string", "a string", "0001-01-01T00:00:00Z"); 1824 if (!object) { 1825 exit(EXIT_FAILURE); 1826 } 1827 1828 md = p5RunMetadataFromObject(object); 1829 if (!md) { 1830 exit(EXIT_FAILURE); 1831 } 1832 1833 psFree(object); 1834 1835 if (!psMetadataLookupS32(&status, md, "p5_id") == -32) { 1836 psFree(md); 1837 exit(EXIT_FAILURE); 1838 } 1839 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 1840 psFree(md); 1841 exit(EXIT_FAILURE); 1842 } 1843 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) { 1844 psFree(md); 1845 exit(EXIT_FAILURE); 1846 } 1847 psFree(md); 1848 exit(EXIT_FAILURE); 1849 } 1850 1851 psFree(md); 1852 } 1853 1854 { 1855 psMetadata *md; 1856 p5InputScfileRow *object; 1857 bool status; 1858 1859 object = p5InputScfileRowAlloc(-32, -32, "a string", "a string", "a string", -32, "a string", true); 1860 if (!object) { 1861 exit(EXIT_FAILURE); 1862 } 1863 1864 md = p5InputScfileMetadataFromObject(object); 1865 if (!md) { 1866 exit(EXIT_FAILURE); 1867 } 1868 1869 psFree(object); 1870 1871 if (!psMetadataLookupS32(&status, md, "p5_id") == -32) { 1872 psFree(md); 1873 exit(EXIT_FAILURE); 1874 } 1875 if (!psMetadataLookupS32(&status, md, "p4_id") == -32) { 1876 psFree(md); 1877 exit(EXIT_FAILURE); 1878 } 1879 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1880 psFree(md); 1881 exit(EXIT_FAILURE); 1882 } 1883 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1884 psFree(md); 1885 exit(EXIT_FAILURE); 1886 } 1887 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1888 psFree(md); 1889 exit(EXIT_FAILURE); 1890 } 1891 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1892 psFree(md); 1893 exit(EXIT_FAILURE); 1894 } 1895 if (strncmp(psMetadataLookupPtr(&status, md, "kind"), "a string", MAX_STRING_LENGTH)) { 1896 psFree(md); 1897 exit(EXIT_FAILURE); 1898 } 1899 if (!psMetadataLookupBool(&status, md, "template") == true) { 1900 psFree(md); 1901 exit(EXIT_FAILURE); 1902 } 1903 1904 psFree(md); 1905 } 1906 1907 { 1908 psMetadata *md; 1909 p5DiffScfileRow *object; 1910 bool status; 1911 1912 object = p5DiffScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64); 1913 if (!object) { 1914 exit(EXIT_FAILURE); 1915 } 1916 1917 md = p5DiffScfileMetadataFromObject(object); 1918 if (!md) { 1919 exit(EXIT_FAILURE); 1920 } 1921 1922 psFree(object); 1923 1924 if (!psMetadataLookupS32(&status, md, "p5_id") == -32) { 1925 psFree(md); 1926 exit(EXIT_FAILURE); 1927 } 1928 if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) { 1929 psFree(md); 1930 exit(EXIT_FAILURE); 1931 } 1932 if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) { 1933 psFree(md); 1934 exit(EXIT_FAILURE); 1935 } 1936 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1937 psFree(md); 1938 exit(EXIT_FAILURE); 1939 } 1940 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) { 1941 psFree(md); 1942 exit(EXIT_FAILURE); 1943 } 1944 if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) { 1945 psFree(md); 1946 exit(EXIT_FAILURE); 1947 } 1948 1949 psFree(md); 1950 } 1951 1818 1952 exit(EXIT_SUCCESS); 1819 1953 } -
trunk/ippdb/tests/objectfrommetadata.c
r11780 r11809 2784 2784 } 2785 2785 2786 { 2787 psMetadata *md; 2788 p5RunRow *object; 2789 2790 md = psMetadataAlloc(); 2791 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p5_id", 0, NULL, -32)) { 2792 psFree(md); 2793 exit(EXIT_FAILURE); 2794 } 2795 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 2796 psFree(md); 2797 exit(EXIT_FAILURE); 2798 } 2799 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) { 2800 psFree(md); 2801 exit(EXIT_FAILURE); 2802 } 2803 psFree(md); 2804 exit(EXIT_FAILURE); 2805 } 2806 2807 object = p5RunObjectFromMetadata(md); 2808 if (!object) { 2809 psFree(md); 2810 exit(EXIT_FAILURE); 2811 } 2812 2813 psFree(md); 2814 2815 if (!object->p5_id == -32) { 2816 psFree(object); 2817 exit(EXIT_FAILURE); 2818 } 2819 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 2820 psFree(object); 2821 exit(EXIT_FAILURE); 2822 } 2823 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 2824 psFree(object); 2825 exit(EXIT_FAILURE); 2826 } 2827 psFree(object); 2828 exit(EXIT_FAILURE); 2829 } 2830 2831 psFree(object); 2832 } 2833 2834 { 2835 psMetadata *md; 2836 p5InputScfileRow *object; 2837 2838 md = psMetadataAlloc(); 2839 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p5_id", 0, NULL, -32)) { 2840 psFree(md); 2841 exit(EXIT_FAILURE); 2842 } 2843 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) { 2844 psFree(md); 2845 exit(EXIT_FAILURE); 2846 } 2847 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 2848 psFree(md); 2849 exit(EXIT_FAILURE); 2850 } 2851 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 2852 psFree(md); 2853 exit(EXIT_FAILURE); 2854 } 2855 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 2856 psFree(md); 2857 exit(EXIT_FAILURE); 2858 } 2859 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 2860 psFree(md); 2861 exit(EXIT_FAILURE); 2862 } 2863 if (!psMetadataAddStr(md, PS_LIST_TAIL, "kind", 0, NULL, "a string")) { 2864 psFree(md); 2865 exit(EXIT_FAILURE); 2866 } 2867 if (!psMetadataAdd(md, PS_LIST_TAIL, "template", PS_DATA_BOOL, NULL, true)) { 2868 psFree(md); 2869 exit(EXIT_FAILURE); 2870 } 2871 2872 object = p5InputScfileObjectFromMetadata(md); 2873 if (!object) { 2874 psFree(md); 2875 exit(EXIT_FAILURE); 2876 } 2877 2878 psFree(md); 2879 2880 if (!object->p5_id == -32) { 2881 psFree(object); 2882 exit(EXIT_FAILURE); 2883 } 2884 if (!object->p4_id == -32) { 2885 psFree(object); 2886 exit(EXIT_FAILURE); 2887 } 2888 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 2889 psFree(object); 2890 exit(EXIT_FAILURE); 2891 } 2892 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 2893 psFree(object); 2894 exit(EXIT_FAILURE); 2895 } 2896 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 2897 psFree(object); 2898 exit(EXIT_FAILURE); 2899 } 2900 if (!object->p3_version == -32) { 2901 psFree(object); 2902 exit(EXIT_FAILURE); 2903 } 2904 if (strncmp(object->kind, "a string", MAX_STRING_LENGTH)) { 2905 psFree(object); 2906 exit(EXIT_FAILURE); 2907 } 2908 if (!object->template == true) { 2909 psFree(object); 2910 exit(EXIT_FAILURE); 2911 } 2912 2913 psFree(object); 2914 } 2915 2916 { 2917 psMetadata *md; 2918 p5DiffScfileRow *object; 2919 2920 md = psMetadataAlloc(); 2921 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p5_id", 0, NULL, -32)) { 2922 psFree(md); 2923 exit(EXIT_FAILURE); 2924 } 2925 if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) { 2926 psFree(md); 2927 exit(EXIT_FAILURE); 2928 } 2929 if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) { 2930 psFree(md); 2931 exit(EXIT_FAILURE); 2932 } 2933 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 2934 psFree(md); 2935 exit(EXIT_FAILURE); 2936 } 2937 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) { 2938 psFree(md); 2939 exit(EXIT_FAILURE); 2940 } 2941 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) { 2942 psFree(md); 2943 exit(EXIT_FAILURE); 2944 } 2945 2946 object = p5DiffScfileObjectFromMetadata(md); 2947 if (!object) { 2948 psFree(md); 2949 exit(EXIT_FAILURE); 2950 } 2951 2952 psFree(md); 2953 2954 if (!object->p5_id == -32) { 2955 psFree(object); 2956 exit(EXIT_FAILURE); 2957 } 2958 if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) { 2959 psFree(object); 2960 exit(EXIT_FAILURE); 2961 } 2962 if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) { 2963 psFree(object); 2964 exit(EXIT_FAILURE); 2965 } 2966 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 2967 psFree(object); 2968 exit(EXIT_FAILURE); 2969 } 2970 if (!object->bg == 64.64) { 2971 psFree(object); 2972 exit(EXIT_FAILURE); 2973 } 2974 if (!object->bg_mean_stdev == 64.64) { 2975 psFree(object); 2976 exit(EXIT_FAILURE); 2977 } 2978 2979 psFree(object); 2980 } 2981 2786 2982 exit(EXIT_SUCCESS); 2787 2983 } -
trunk/ippdb/tests/selectrowsfits.c
r11780 r11809 777 777 } 778 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 (!p5RunSelectRowsFits(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 (!p5InputScfileSelectRowsFits(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 (!p5DiffScfileSelectRowsFits(dbh, fits, NULL, 1)) { 838 exit(EXIT_FAILURE); 839 } 840 841 psFree(fits); 842 psDBCleanup(dbh); 843 } 844 779 845 exit(EXIT_SUCCESS); 780 846 }
Note:
See TracChangeset
for help on using the changeset viewer.
