- Timestamp:
- Jun 25, 2009, 2:00:56 PM (17 years ago)
- Location:
- branches/eam_branches/20090522
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/magicdstool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090522
- Property svn:mergeinfo changed
-
branches/eam_branches/20090522/ippTools/src
- Property svn:ignore
-
old new 34 34 disttool 35 35 receivetool 36 37 pubtool
-
- Property svn:ignore
-
branches/eam_branches/20090522/ippTools/src/magicdstool.c
r23974 r24557 38 38 static bool revertdestreakedfileMode(pxConfig *config); 39 39 static bool getskycellsMode(pxConfig *config); 40 static bool toremoveMode(pxConfig *config); 41 static bool torestoreMode(pxConfig *config); 40 42 41 43 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state); … … 68 70 MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode); 69 71 MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS, getskycellsMode); 72 MODECASE(MAGICDSTOOL_MODE_TOREMOVE, toremoveMode); 73 MODECASE(MAGICDSTOOL_MODE_TORESTORE, torestoreMode); 70 74 default: 71 75 psAbort("invalid option (this should not happen)"); … … 501 505 // chose the appropriate query based on the stage 502 506 if (!strcmp(stage, "raw")) { 503 query = "UPDATE rawImfile SET magicked = 1where exp_id = %" PRId64 " AND class_id = '%s'";507 query = "UPDATE rawImfile SET magicked = %" PRId64 " where exp_id = %" PRId64 " AND class_id = '%s'"; 504 508 } else if (!strcmp(stage, "chip")) { 505 query = "UPDATE chipProcessedImfile SET magicked = 1where chip_id = %" PRId64 " AND class_id = '%s'";509 query = "UPDATE chipProcessedImfile SET magicked = %" PRId64 " where chip_id = %" PRId64 " AND class_id = '%s'"; 506 510 } else if (!strcmp(stage, "warp")) { 507 query = "UPDATE warpSkyfile SET magicked = 1where warp_id = %" PRId64 " AND skycell_id = '%s'";511 query = "UPDATE warpSkyfile SET magicked = %" PRId64 " where warp_id = %" PRId64 " AND skycell_id = '%s'"; 508 512 } else if (!strcmp(stage, "diff")) { 509 query = "UPDATE diffSkyfile SET magicked = 1where diff_id = %" PRId64 " AND skycell_id = '%s'";513 query = "UPDATE diffSkyfile SET magicked = %" PRId64 " where diff_id = %" PRId64 " AND skycell_id = '%s'"; 510 514 } else { 511 515 psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage); … … 513 517 return false; 514 518 } 515 if (!p_psDBRunQueryF(config->dbh, query, stage_id, component)) {519 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id, component)) { 516 520 psError(PS_ERR_UNKNOWN, false, "database error"); 517 521 return false; … … 563 567 // chose the appropriate query based on the stage 564 568 if (!strcmp(stage, "raw")) { 565 query = "UPDATE rawExp SET magicked = 1where exp_id = %" PRId64;569 query = "UPDATE rawExp SET magicked = %" PRId64 " where exp_id = %" PRId64; 566 570 } else if (!strcmp(stage, "chip")) { 567 query = "UPDATE chipRun SET magicked = 1where chip_id = %" PRId64;571 query = "UPDATE chipRun SET magicked = %" PRId64 " where chip_id = %" PRId64; 568 572 } else if (!strcmp(stage, "warp")) { 569 query = "UPDATE warpRun SET magicked = 1where warp_id = %" PRId64;573 query = "UPDATE warpRun SET magicked = %" PRId64 " where warp_id = %" PRId64; 570 574 } else if (!strcmp(stage, "diff")) { 571 query = "UPDATE diffRun SET magicked = 1where diff_id = %" PRId64;575 query = "UPDATE diffRun SET magicked = %" PRId64 " where diff_id = %" PRId64; 572 576 } else { 573 577 psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage); … … 575 579 return false; 576 580 } 577 if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {581 if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id, stage_id)) { 578 582 psError(PS_ERR_UNKNOWN, false, "database error"); 579 583 return false; … … 625 629 } 626 630 627 if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault )) {631 if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault, "full")) { 628 632 // rollback 629 633 if (!psDBRollback(config->dbh)) { … … 889 893 } 890 894 895 static bool toremoveMode(pxConfig *config) 896 { 897 PS_ASSERT_PTR_NON_NULL(config, false); 898 899 psMetadata *where = psMetadataAlloc(); 900 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 901 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 902 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 903 904 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 905 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 906 907 // look for "inputs" that need to processed 908 psString query = pxDataGet("magicdstool_toremove.sql"); 909 if (!query) { 910 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 911 return false; 912 } 913 914 if (psListLength(where->list)) { 915 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 916 psStringAppend(&query, " WHERE %s", whereClause); 917 psFree(whereClause); 918 } 919 psFree(where); 920 921 // treat limit == 0 as "no limit" 922 if (limit) { 923 psString limitString = psDBGenerateLimitSQL(limit); 924 psStringAppend(&query, " %s", limitString); 925 psFree(limitString); 926 } 927 928 if (!p_psDBRunQuery(config->dbh, query)) { 929 psError(PS_ERR_UNKNOWN, false, "database error"); 930 psFree(query); 931 return false; 932 } 933 psFree(query); 934 935 psArray *output = p_psDBFetchResult(config->dbh); 936 if (!output) { 937 psErrorCode err = psErrorCodeLast(); 938 switch (err) { 939 case PS_ERR_DB_CLIENT: 940 psError(PXTOOLS_ERR_SYS, false, "database error"); 941 case PS_ERR_DB_SERVER: 942 psError(PXTOOLS_ERR_PROG, false, "database error"); 943 default: 944 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 945 } 946 947 return false; 948 } 949 if (!psArrayLength(output)) { 950 psTrace("magicdstool", PS_LOG_INFO, "no rows found"); 951 psFree(output); 952 return true; 953 } 954 955 if (psArrayLength(output)) { 956 // negative simple so the default is true 957 if (!ippdbPrintMetadatas(stdout, output, "toremove", !simple)) { 958 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 959 psFree(output); 960 return false; 961 } 962 } 963 964 psFree(output); 965 966 return true; 967 } 968 static bool torestoreMode(pxConfig *config) 969 { 970 PS_ASSERT_PTR_NON_NULL(config, false); 971 972 psMetadata *where = psMetadataAlloc(); 973 PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "=="); 974 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 975 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 976 977 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 978 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 979 980 // look for "inputs" that need to processed 981 psString query = pxDataGet("magicdstool_torestore.sql"); 982 if (!query) { 983 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 984 return false; 985 } 986 987 if (psListLength(where->list)) { 988 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 989 psStringAppend(&query, " WHERE %s", whereClause); 990 psFree(whereClause); 991 } 992 psFree(where); 993 994 // treat limit == 0 as "no limit" 995 if (limit) { 996 psString limitString = psDBGenerateLimitSQL(limit); 997 psStringAppend(&query, " %s", limitString); 998 psFree(limitString); 999 } 1000 1001 if (!p_psDBRunQuery(config->dbh, query)) { 1002 psError(PS_ERR_UNKNOWN, false, "database error"); 1003 psFree(query); 1004 return false; 1005 } 1006 psFree(query); 1007 1008 psArray *output = p_psDBFetchResult(config->dbh); 1009 if (!output) { 1010 psErrorCode err = psErrorCodeLast(); 1011 switch (err) { 1012 case PS_ERR_DB_CLIENT: 1013 psError(PXTOOLS_ERR_SYS, false, "database error"); 1014 case PS_ERR_DB_SERVER: 1015 psError(PXTOOLS_ERR_PROG, false, "database error"); 1016 default: 1017 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1018 } 1019 1020 return false; 1021 } 1022 if (!psArrayLength(output)) { 1023 psTrace("magicdstool", PS_LOG_INFO, "no rows found"); 1024 psFree(output); 1025 return true; 1026 } 1027 1028 if (psArrayLength(output)) { 1029 // negative simple so the default is true 1030 if (!ippdbPrintMetadatas(stdout, output, "torestore", !simple)) { 1031 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1032 psFree(output); 1033 return false; 1034 } 1035 } 1036 1037 psFree(output); 1038 1039 return true; 1040 }
Note:
See TracChangeset
for help on using the changeset viewer.
