Changeset 31038 for trunk/ippTools/src/pztool.c
- Timestamp:
- Mar 24, 2011, 2:09:53 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r30907 r31038 53 53 static psArray *pzGetPendingCameras(pxConfig *config); 54 54 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 55 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state);55 static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state); 56 56 57 57 # define MODECASE(caseName, func) \ … … 222 222 223 223 psMetadata *where = psMetadataAlloc(); 224 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 224 225 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 225 226 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 237 238 " FROM summitExp" 238 239 " LEFT JOIN pzDownloadExp" 239 " USING(exp_name, camera, telescope)"240 " USING(summit_id)" 240 241 " WHERE" 241 " pzDownloadExp.exp_name IS NULL" 242 " AND pzDownloadExp.camera IS NULL" 243 " AND pzDownloadExp.telescope IS NULL" 242 " pzDownloadExp.summit_id IS NULL" 244 243 " AND summitExp.fault = 0" 245 244 ); … … 260 259 if (limit) { 261 260 psString limitString = psDBGenerateLimitSQL(limit); 261 262 262 psStringAppend(&query, " %s", limitString); 263 263 psFree(limitString); … … 299 299 300 300 psMetadata *where = psMetadataAlloc(); 301 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 301 302 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 302 303 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 401 402 402 403 // required 404 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 403 405 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 404 406 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); … … 428 430 429 431 psMetadata *where = psMetadataAlloc(); 432 PXOPT_COPY_S64(config->args, where, "-summit_id", "summit_id", "=="); 430 433 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 431 434 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 459 462 460 463 if (!pzDownloadImfileInsert(config->dbh, 464 summit_id, 461 465 exp_name, 462 466 camera, … … 505 509 506 510 psMetadata *where = psMetadataAlloc(); 511 PXOPT_COPY_STR(config->args, where, "-summit_id", "summit_id", "=="); 507 512 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 508 513 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); … … 560 565 561 566 // required 567 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 562 568 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 563 569 PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false); … … 579 585 if (!newExpInsert(config->dbh, 580 586 0x0, // exp_id 587 summit_id, // summit_id 581 588 exp_name, // tmp_exp_name 582 589 inst, // tmp_camera … … 597 604 } 598 605 599 psS64 exp_id = psDBLastInsertID(config->dbh);600 601 // insert newImfiles602 {603 char *query =606 psS64 exp_id = psDBLastInsertID(config->dbh); 607 608 // insert newImfiles 609 { 610 char *query = 604 611 "INSERT INTO newImfile" 605 " SE lECT"612 " SELECT" 606 613 " %" PRId64 "," // exp_id 614 " %" PRId64 "," // summit_id 607 615 " pzDownloadImfile.class_id," // tmp_class_id 608 616 " pzDownloadImfile.uri," // uri … … 616 624 " AND pzDownloadImfile.telescope = '%s'"; 617 625 618 if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) {619 psError(PS_ERR_UNKNOWN, false, "database error");620 return false;621 }622 623 // sanity check: we should have inserted at least one row624 psU64 affected = psDBAffectedRows(config->dbh);625 if (psDBAffectedRows(config->dbh) < 1) {626 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);627 return false;628 }626 if (!p_psDBRunQueryF(config->dbh, query, exp_id, summit_id, exp_name, inst, telescope)) { 627 psError(PS_ERR_UNKNOWN, false, "database error"); 628 return false; 629 } 630 631 // sanity check: we should have inserted at least one row 632 psU64 affected = psDBAffectedRows(config->dbh); 633 if (psDBAffectedRows(config->dbh) < 1) { 634 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected); 635 return false; 636 } 629 637 } 630 638 631 639 // set pzDownloadExp.state to 'stop' 632 if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) {633 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for % s:%s:%s", exp_name, inst, telescope);640 if (!pzDownloadExpSetState(config, summit_id, "stop")) { 641 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %ld", summit_id); 634 642 return false; 635 643 } … … 887 895 888 896 889 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)897 static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state) 890 898 { 891 899 PS_ASSERT_PTR_NON_NULL(state, false); … … 904 912 } 905 913 906 char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'";907 if (!p_psDBRunQueryF(config->dbh, query, state, exp_name, camera, telescope)) {908 psError(PS_ERR_UNKNOWN, false, "failed to change state for % s:%s:%s", exp_name, camera, telescope);914 char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE summit_id = %ld"; 915 if (!p_psDBRunQueryF(config->dbh, query, state, summit_id)) { 916 psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id); 909 917 return false; 910 918 } … … 916 924 { 917 925 PS_ASSERT_PTR_NON_NULL(config, false); 918 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 919 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); 920 PXOPT_LOOKUP_STR(telescope,config->args, "-telescope",true, false); 926 PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false); 921 927 PXOPT_LOOKUP_STR(state, config->args, "-set_state",true, false); 922 928 923 if (!pzDownloadExpSetState(config, exp_name,camera,telescope,state)) {924 psError(PS_ERR_UNKNOWN, false, "failed to change state for % s:%s:%s", exp_name, camera, telescope);929 if (!pzDownloadExpSetState(config,summit_id, state)) { 930 psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id); 925 931 return false; 926 932 }
Note:
See TracChangeset
for help on using the changeset viewer.
