Changeset 31407 for branches/czw_branch/20110406/ippTools/src/laptool.c
- Timestamp:
- Apr 28, 2011, 6:41:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20110406/ippTools/src/laptool.c
r31397 r31407 121 121 } 122 122 123 if ( lapSequencePrintObject(stdout, run, !simple)) {123 if (!lapSequencePrintObject(stdout, run, !simple)) { 124 124 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 125 125 psFree(run); … … 141 141 psMetadata *where = psMetadataAlloc(); 142 142 PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "=="); 143 PXOPT_COPY_STR(config->args, where, "- name", "name", "LIKE");143 PXOPT_COPY_STR(config->args, where, "-seq_name", "name", "LIKE"); 144 144 145 145 psString query = pxDataGet("laptool_listsequence.sql"); … … 214 214 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 215 215 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false); 216 PXOPT_LOOKUP_BOOL(all_obsmode, config->args, "-all_obsmode", false); 216 217 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 217 218 … … 226 227 NULL, // registered 227 228 0, // fault 228 0, // quick_sass_id229 0// final_sass_id229 INT64_MAX, // quick_sass_id 230 INT64_MAX // final_sass_id 230 231 ); 231 232 if (!run) { … … 248 249 } 249 250 250 // point of no return 251 if (!psDBCommit(config->dbh)) { 252 psError(PS_ERR_UNKNOWN, false, "database error"); 253 return false; 254 } 255 256 if (lapRunPrintObject(stdout, run, !simple)) { 251 252 if (!lapRunPrintObject(stdout, run, !simple)) { 253 if (!psDBRollback(config->dbh)) { 254 psError(PS_ERR_UNKNOWN, false, "database error"); 255 } 257 256 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 258 257 psFree(run); … … 265 264 psString query = pxDataGet("laptool_definerun.sql"); 266 265 if (!query) { 266 if (!psDBRollback(config->dbh)) { 267 psError(PS_ERR_UNKNOWN, false, "database error"); 268 } 269 267 270 psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement"); 268 271 return(false); 269 272 } 270 psString where = NULL; 271 if (!pxspaceAddWhere(config, &where, "rawExp")) { 273 274 // Add constraints to the exposure search: 275 psMetadata *where = psMetadataAlloc(); 276 PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "=="); 277 278 // This seems unnecessarily clunky. 279 if (!all_obsmode) { 280 // fprintf(stderr, "Not doing all obsmodes!\n"); 281 if (!psMetadataLookupStr(NULL,config->args,"-obsmode")) { 282 // fprintf(stderr, "Not doing all obsmodes and none specified!\n"); 283 psMetadataAddStr(where,PS_LIST_TAIL,"rawExp.obs_mode",0,"==","3PI"); 284 } 285 pxAddLabelSearchArgs (config, where, "-obsmode", "rawExp.obsmode", "=="); 286 } 287 288 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 289 if (!pxspaceAddWhere(config, &whereClause, "rawExp")) { 290 if (!psDBRollback(config->dbh)) { 291 psError(PS_ERR_UNKNOWN, false, "database error"); 292 } 293 272 294 psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed"); 273 295 return(false); 274 296 } 275 psStringAppend(&query, " %s", where );297 psStringAppend(&query, " %s", whereClause); 276 298 psFree(where); 277 299 300 // Fetch exposures 278 301 if (!p_psDBRunQuery(config->dbh, query)) { 302 if (!psDBRollback(config->dbh)) { 303 psError(PS_ERR_UNKNOWN, false, "database error"); 304 } 305 279 306 psError(PS_ERR_UNKNOWN, false, "database error"); 280 307 psFree(query); … … 285 312 psArray *output = p_psDBFetchResult(config->dbh); 286 313 if (!output) { 314 if (!psDBRollback(config->dbh)) { 315 psError(PS_ERR_UNKNOWN, false, "database error"); 316 } 317 287 318 psError(PS_ERR_UNKNOWN, false, "database error"); 288 319 return(false); 289 320 } 290 321 if (!psArrayLength(output)) { 322 if (!psDBRollback(config->dbh)) { 323 psError(PS_ERR_UNKNOWN, false, "database error"); 324 } 325 291 326 psTrace("laptool", PS_LOG_INFO, "no rows found"); 292 327 psFree(output); … … 294 329 } 295 330 296 297 331 // Insert the exposure data 298 332 for (long i = 0; i < output->n; i++) { 299 333 psMetadata *row = output->data[i]; // Row from select 334 // Add default values from this run: 335 psMetadataAddS64(row, PS_LIST_TAIL, "lap_id", 0, "", lap_id); 336 psMetadataAddS64(row, PS_LIST_TAIL, "pair_id", 0, "", INT64_MAX); 337 psMetadataAddStr(row, PS_LIST_TAIL, "data_state", 0, "", "new"); 300 338 lapExpRow *lapExp = lapExpObjectFromMetadata(row); 301 339 lapExp->lap_id = lap_id; 302 340 303 341 if (!lapExpInsertObject(config->dbh,lapExp)) { 342 if (!lapExpPrintObject(stdout, lapExp, !simple)) { 343 if (!psDBRollback(config->dbh)) { 344 psError(PS_ERR_UNKNOWN, false, "database error"); 345 } 346 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 347 psFree(run); 348 return false; 349 } 350 304 351 if (!psDBRollback(config->dbh)) { 305 352 psError(PS_ERR_UNKNOWN, false, "database error"); … … 312 359 } 313 360 361 // point of no return 362 if (!psDBCommit(config->dbh)) { 363 psError(PS_ERR_UNKNOWN, false, "database error"); 364 return false; 365 } 366 367 314 368 psFree(output); 315 369 return(true); … … 341 395 psFree(whereClause); 342 396 } 343 psStringAppend(&query, " ORDER BY rawExp.dateobs ");344 397 345 398 if (!p_psDBRunQuery(config->dbh, query)) { … … 452 505 psFree(limitString); 453 506 } 507 psStringAppend(&query, " ORDER BY rawExp.dateobs "); 508 454 509 if (!p_psDBRunQuery(config->dbh, query)) { 455 510 psError(PS_ERR_UNKNOWN, false, "database error"); … … 554 609 { 555 610 PS_ASSERT_PTR_NON_NULL(config, false); 611 PXOPT_LOOKUP_S64(lap_id, config->args, "-lap_id", true, false); 612 556 613 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 557 614 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 558 615 559 616 psMetadata *where = psMetadataAlloc(); 560 617 PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "=="); … … 565 622 return(false); 566 623 } 567 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 568 if (whereClause) { 624 625 if (psListLength(where->list)) { 626 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 569 627 psStringPrepend(&whereClause, "\n AND "); 570 } 571 572 psString limitString = NULL; 628 psStringSubstitute(&query,whereClause,"@WHERE@"); 629 psFree(whereClause); 630 } 631 573 632 if (limit) { 574 limitString = psDBGenerateLimitSQL(limit); 575 psStringPrepend(&limitString, "\n"); 576 } 577 578 if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) { 579 psError(PXTOOLS_ERR_PROG, false, "database error"); 633 psString limitString = psDBGenerateLimitSQL(limit); 634 psStringAppend(&query, " %s", limitString); 580 635 psFree(limitString); 636 } 637 638 639 if (!p_psDBRunQuery(config->dbh, query)) { 640 psError(PS_ERR_UNKNOWN, false, "database error"); 581 641 psFree(query); 582 psFree(whereClause); 583 return(false); 584 } 585 psFree(limitString); 642 return false; 643 } 586 644 psFree(query); 587 psFree(whereClause); 588 645 589 646 psArray *output = p_psDBFetchResult(config->dbh); 590 647 if (!output) { 591 psError(PS_ERR_UNKNOWN, false, "database error"); 592 return(false); 648 psErrorCode err = psErrorCodeLast(); 649 switch (err) { 650 case PS_ERR_DB_CLIENT: 651 psError(PXTOOLS_ERR_SYS, false, "database error"); 652 case PS_ERR_DB_SERVER: 653 psError(PXTOOLS_ERR_PROG, false, "database error"); 654 default: 655 psError(PXTOOLS_ERR_PROG, false, "unknown error %d",err); 656 } 657 658 return false; 593 659 } 594 660 if (!psArrayLength(output)) { 595 661 psTrace("laptool", PS_LOG_INFO, "no rows found"); 596 662 psFree(output); 597 return(true); 598 } 599 600 if (!ippdbPrintMetadatas(stdout, output, "lapRunStacks", !simple)) { 601 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 602 psFree(output); 603 return(false); 663 return true; 664 } 665 666 if (psArrayLength(output)) { 667 if (!ippdbPrintMetadatas(stdout, output, "lapRunStacks", !simple)) { 668 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 669 psFree(output); 670 return false; 671 } 604 672 } 605 673
Note:
See TracChangeset
for help on using the changeset viewer.
