Changeset 18573 for trunk/ippTools/src/magictool.c
- Timestamp:
- Jul 15, 2008, 4:16:16 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r18571 r18573 38 38 static bool totreeMode(pxConfig *config); 39 39 static bool inputtreeMode(pxConfig *config); 40 static bool reverttreeMode(pxConfig *config); 40 41 static bool toprocessMode(pxConfig *config); 41 42 static bool addresultMode(pxConfig *config); 43 static bool revertnodeMode(pxConfig *config); 42 44 static bool inputsMode(pxConfig *config); 43 45 static bool tomaskMode(pxConfig *config); 44 46 static bool addmaskMode(pxConfig *config); 47 static bool revertmaskMode(pxConfig *config); 45 48 static bool maskMode(pxConfig *config); 46 49 … … 73 76 MODECASE(MAGICTOOL_MODE_TOTREE, totreeMode); 74 77 MODECASE(MAGICTOOL_MODE_INPUTTREE, inputtreeMode); 78 MODECASE(MAGICTOOL_MODE_REVERTTREE, reverttreeMode); 75 79 MODECASE(MAGICTOOL_MODE_TOPROCESS, toprocessMode); 76 80 MODECASE(MAGICTOOL_MODE_ADDRESULT, addresultMode); 81 MODECASE(MAGICTOOL_MODE_REVERTNODE, revertnodeMode); 77 82 MODECASE(MAGICTOOL_MODE_INPUTS, inputsMode); 78 83 MODECASE(MAGICTOOL_MODE_TOMASK, tomaskMode); 79 84 MODECASE(MAGICTOOL_MODE_ADDMASK, addmaskMode); 85 MODECASE(MAGICTOOL_MODE_REVERTMASK, revertmaskMode); 80 86 MODECASE(MAGICTOOL_MODE_MASK, maskMode); 81 87 default: … … 512 518 513 519 if (code > 0) { 514 char *query = "UPDATE magicRun SET fault = %d WHERE magic_id = %" PRId64;520 char *query = "UPDATE magicRun SET fault = %d, state = 'stop' WHERE magic_id = %" PRId64; 515 521 if (!p_psDBRunQuery(config->dbh, query, code, magic_id)) { 516 522 psError(PS_ERR_UNKNOWN, false, … … 528 534 return true; 529 535 } 536 537 static bool reverttreeMode(pxConfig *config) 538 { 539 PS_ASSERT_PTR_NON_NULL(config, false); 540 541 psMetadata *where = psMetadataAlloc(); 542 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 543 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 544 545 psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'run' WHERE fault != 0"); 546 547 if (psListLength(where->list)) { 548 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 549 psStringAppend(&query, " AND %s", whereClause); 550 psFree(whereClause); 551 } 552 psFree(where); 553 554 if (!p_psDBRunQuery(config->dbh, query)) { 555 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 556 return false; 557 } 558 return true; 559 } 560 530 561 531 562 static bool inputsMode(pxConfig *config) … … 622 653 bool findReadyNodes(void *arg, pxNode *node) 623 654 { 655 if (!node) { 656 // It's not there --- must have failed 657 return false; 658 } 659 624 660 if (psMetadataLookupBool(NULL, node->data, "done")) { 625 661 // It's already done … … 632 668 psMetadataRemoveKey(work, "dep"); 633 669 psMetadataRemoveKey(work, "done"); 634 #if 0635 psMetadataRemoveKey(work, "uri");636 #endif637 670 pxNode *child = NULL; 638 671 while ((child = psListGetAndIncrement(iter))) { … … 644 677 psAbort("failed to lookup value for done column"); 645 678 } 646 647 if (!done) { 679 psS16 bad = psMetadataLookupS16(&status, data, "bad"); 680 if (!status) { 681 psAbort("failed to lookup value for bad column"); 682 } 683 684 if (!done || bad) { 648 685 // if a child isn't "done", give up on this node and continue 649 686 // to crawl the tree … … 652 689 return true; 653 690 } 654 #if 0655 char *uri = psMetadataLookupStr(&status, data, "uri");656 if (!status) {657 psAbort("failed to lookup value for uri column");658 }659 660 psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri);661 #endif662 691 } 663 692 psFree(iter); … … 835 864 } 836 865 866 static bool revertnodeMode(pxConfig *config) 867 { 868 PS_ASSERT_PTR_NON_NULL(config, false); 869 870 psMetadata *where = psMetadataAlloc(); 871 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 872 PXOPT_COPY_STR(config->args, where, "-node", "node", "=="); 873 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 874 875 psString query = psStringCopy("DELETE FROM magicNodeResult WHERE fault != 0"); 876 877 if (psListLength(where->list)) { 878 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 879 psStringAppend(&query, " AND %s", whereClause); 880 psFree(whereClause); 881 } 882 psFree(where); 883 884 if (!p_psDBRunQuery(config->dbh, query)) { 885 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 886 return false; 887 } 888 return true; 889 } 890 891 837 892 static bool tomaskMode(pxConfig *config) 838 893 { … … 885 940 if (psArrayLength(output)) { 886 941 // negative simple so the default is true 887 if (!ippdbPrintMetadatas(stdout, output, "to process", !simple)) {942 if (!ippdbPrintMetadatas(stdout, output, "tomask", !simple)) { 888 943 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 889 944 psFree(output); … … 924 979 )) { 925 980 psError(PS_ERR_UNKNOWN, false, "database error"); 981 if (!psDBRollback(config->dbh)) { 982 psError(PS_ERR_UNKNOWN, false, "database error"); 983 } 926 984 return false; 927 985 } … … 931 989 if (!query) { 932 990 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 991 if (!psDBRollback(config->dbh)) { 992 psError(PS_ERR_UNKNOWN, false, "database error"); 993 } 933 994 return false; 934 995 } … … 940 1001 psError(PS_ERR_UNKNOWN, false, "database error"); 941 1002 psFree(query); 1003 if (!psDBRollback(config->dbh)) { 1004 psError(PS_ERR_UNKNOWN, false, "database error"); 1005 } 942 1006 return false; 943 1007 } … … 948 1012 return false; 949 1013 } 1014 1015 return true; 1016 } 1017 1018 static bool revertmaskMode(pxConfig *config) 1019 { 1020 PS_ASSERT_PTR_NON_NULL(config, false); 1021 1022 psMetadata *where = psMetadataAlloc(); 1023 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1024 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 1025 1026 if (!psDBTransaction(config->dbh)) { 1027 psError(PS_ERR_UNKNOWN, false, "database error"); 1028 return false; 1029 } 1030 1031 // Set to "run" 1032 { 1033 psString query = psStringCopy("UPDATE magicRun JOIN magicMask USING(magic_id) " 1034 "SET magicRun.state = 'run' WHERE magicMask.fault != 0"); 1035 1036 if (psListLength(where->list)) { 1037 psString whereClause = psDBGenerateWhereConditionSQL(where, "magicMask"); 1038 psStringAppend(&query, " AND %s", whereClause); 1039 psFree(whereClause); 1040 } 1041 1042 if (!p_psDBRunQuery(config->dbh, query)) { 1043 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 1044 if (!psDBRollback(config->dbh)) { 1045 psError(PS_ERR_UNKNOWN, false, "database error"); 1046 } 1047 return false; 1048 } 1049 1050 psFree(query); 1051 } 1052 1053 // Delete failed attempt at mask 1054 { 1055 psString query = psStringCopy("DELETE FROM magicMask WHERE fault != 0"); 1056 1057 if (psListLength(where->list)) { 1058 psString whereClause = psDBGenerateWhereConditionSQL(where, "magicMask"); 1059 psStringAppend(&query, " AND %s", whereClause); 1060 psFree(whereClause); 1061 } 1062 1063 if (!p_psDBRunQuery(config->dbh, query)) { 1064 psError(PS_ERR_UNKNOWN, false, "failed to revert"); 1065 if (!psDBRollback(config->dbh)) { 1066 psError(PS_ERR_UNKNOWN, false, "database error"); 1067 } 1068 return false; 1069 } 1070 1071 psFree(query); 1072 } 1073 1074 if (!psDBCommit(config->dbh)) { 1075 psError(PS_ERR_UNKNOWN, false, "database error"); 1076 return false; 1077 } 1078 1079 psFree(where); 950 1080 951 1081 return true; … … 1012 1142 if (psArrayLength(output)) { 1013 1143 // negative simple so the default is true 1014 if (!ippdbPrintMetadatas(stdout, output, "magic Node", !simple)) {1144 if (!ippdbPrintMetadatas(stdout, output, "magicMask", !simple)) { 1015 1145 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1016 1146 psFree(output);
Note:
See TracChangeset
for help on using the changeset viewer.
