Changeset 25870 for branches/eam_branches/20090820/ippTools/src/addtool.c
- Timestamp:
- Oct 18, 2009, 10:23:28 AM (17 years ago)
- Location:
- branches/eam_branches/20090820
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippTools/src/addtool.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090820
-
branches/eam_branches/20090820/ippTools/src/addtool.c
r25766 r25870 40 40 static bool maskedMode(pxConfig *config); 41 41 static bool unblockMode(pxConfig *config); 42 static bool pendingcleanuprunMode(pxConfig *config);43 static bool pendingcleanupexpMode(pxConfig *config);44 static bool donecleanupMode(pxConfig *config);45 static bool exportrunMode(pxConfig *config);46 static bool importrunMode(pxConfig *config);47 42 48 43 # define MODECASE(caseName, func) \ … … 74 69 MODECASE(ADDTOOL_MODE_MASKED, maskedMode); 75 70 MODECASE(ADDTOOL_MODE_UNBLOCK, unblockMode); 76 MODECASE(ADDTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode);77 MODECASE(ADDTOOL_MODE_PENDINGCLEANUPEXP, pendingcleanupexpMode);78 MODECASE(ADDTOOL_MODE_DONECLEANUP, donecleanupMode);79 MODECASE(ADDTOOL_MODE_EXPORTRUN, exportrunMode);80 MODECASE(ADDTOOL_MODE_IMPORTRUN, importrunMode);81 71 default: 82 72 psAbort("invalid option (this should not happen)"); … … 106 96 107 97 psMetadata *where = psMetadataAlloc(); 108 pxaddGetSearchArgs (config, where); 109 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); 110 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 98 pxcamGetSearchArgs (config, where); 99 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 100 pxAddLabelSearchArgs (config, where, "-label", "camRun.label", "=="); 101 PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "=="); 111 102 112 103 if (!psListLength(where->list) && … … 117 108 } 118 109 119 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false); 120 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 121 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 122 PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false); 110 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false); 111 PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false); 112 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 113 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 114 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 115 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 116 PXOPT_LOOKUP_BOOL(image_only, config->args, "-image_only", false); 117 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 118 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 123 119 124 120 // find the cam_id of all the exposures that we want to queue up. … … 130 126 } 131 127 132 // use psDBGenerateWhere SQL because the SQL yields an intermediate table128 // use psDBGenerateWhereConditionSQL because the SQL ends in a WHERE 133 129 if (where && psListLength(where->list)) { 134 130 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 136 132 psFree(whereClause); 137 133 } 138 139 134 psFree(where); 140 135 … … 155 150 psFree(output); 156 151 return true; 152 } 153 154 if (pretend) { 155 // negative simple so the default is true 156 if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) { 157 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 158 psFree(output); 159 return false; 160 } 161 psFree(output); 162 return true; 163 } 164 165 // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values: 166 for (long i = 0; i < psArrayLength(output); i++) { 167 psMetadata *md = output->data[i]; 168 169 camRunRow *row = camRunObjectFromMetadata(md); 170 if (!row) { 171 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 172 psFree(output); 173 return false; 174 } 175 176 if (!dvodb && !row->dvodb) { 177 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id); 178 psFree(output); 179 return false; 180 } 181 if (!workdir && !row->workdir) { 182 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id); 183 psFree(output); 184 return false; 185 } 186 187 psFree(row); 157 188 } 158 189 … … 170 201 // old values in place (i.e., passing the values through). 171 202 172 173 // loop over our list of addRun rows 203 // loop over our list of camRun rows 174 204 for (long i = 0; i < psArrayLength(output); i++) { 175 205 psMetadata *md = output->data[i]; 176 206 177 addRunRow *row = addRunObjectFromMetadata(md);207 camRunRow *row = camRunObjectFromMetadata(md); 178 208 if (!row) { 179 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into addRun");209 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun"); 180 210 psFree(output); 181 211 return false; … … 186 216 row->cam_id, 187 217 workdir ? workdir : row->workdir, 218 reduction ? reduction : row->reduction, 188 219 label ? label : row->label, 189 "RECIPE", 190 dvodb ? dvodb : row->dvodb 191 220 data_group ? data_group : (label ? label : row->label), 221 dvodb ? dvodb : row->dvodb, 222 note ? note : NULL, 223 image_only 192 224 )) { 193 225 if (!psDBRollback(config->dbh)) { … … 218 250 219 251 psMetadata *where = psMetadataAlloc(); 220 pxaddGetSearchArgs (config, where);221 252 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); 253 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 254 pxcamGetSearchArgs (config, where); // most search arguments based on camera 222 255 PXOPT_COPY_STR(config->args, where, "-label", "addRun.label", "=="); 223 256 PXOPT_COPY_STR(config->args, where, "-state", "addRun.state", "=="); 224 257 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 225 258 226 if (!psListLength(where->list) 227 && !psMetadataLookupBool(NULL, config->args, "-all")) { 259 if (!psListLength(where->list)) { 228 260 psFree(where); 229 261 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); … … 231 263 } 232 264 265 psString query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)"); 266 267 // pxUpdateRun gets parameters from config->args and runs the update query 268 bool result = pxUpdateRun(config, where, &query, "addRun", false); 269 270 psFree(query); 271 psFree(where); 272 273 return result; 274 275 276 #ifdef notdef 233 277 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 234 278 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); … … 259 303 260 304 return true; 305 #endif 261 306 } 262 307 … … 267 312 268 313 psMetadata *where = psMetadataAlloc(); 269 pxaddGetSearchArgs (config, where);270 314 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); 315 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 316 pxcamGetSearchArgs (config, where); 271 317 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); 272 318 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 273 274 319 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 275 320 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); … … 325 370 } 326 371 327 /* static bool pendingimfileMode(pxConfig *config) */328 /* { */329 /* PS_ASSERT_PTR_NON_NULL(config, false); */330 331 /* psMetadata *where = psMetadataAlloc(); */332 /* pxaddGetSearchArgs (config, where); */333 /* PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); */334 /* pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); */335 /* PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); */336 /* PXOPT_COPY_S64(config->args, where, "-chip_id", "addRun.chip_id", "=="); */337 /* PXOPT_COPY_STR(config->args, where, "-class_id", "addProcessedExp.class_id", "=="); */338 339 /* PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); */340 341 /* psString query = pxDataGet("addtool_find_pendingimfile.sql"); */342 /* if (!query) { */343 /* psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); */344 /* return false; */345 /* } */346 347 /* // use psDBGenerateWhereSQL because the SQL yields an intermediate table */348 /* if (psListLength(where->list)) { */349 /* psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); */350 /* psStringAppend(&query, " AND %s", whereClause); */351 /* psFree(whereClause); */352 /* } */353 /* psFree(where); */354 355 /* if (!p_psDBRunQuery(config->dbh, query)) { */356 /* psError(PS_ERR_UNKNOWN, false, "database error"); */357 /* psFree(query); */358 /* return false; */359 /* } */360 /* psFree(query); */361 362 /* psArray *output = p_psDBFetchResult(config->dbh); */363 /* if (!output) { */364 /* psError(PS_ERR_UNKNOWN, false, "database error"); */365 /* return false; */366 /* } */367 /* if (!psArrayLength(output)) { */368 /* psTrace("addtool", PS_LOG_INFO, "no rows found"); */369 /* psFree(output); */370 /* return true; */371 /* } */372 373 /* // negate simple so the default is true */374 /* if (!ippdbPrintMetadatas(stdout, output, "addProcessedExp", !simple)) { */375 /* psError(PS_ERR_UNKNOWN, false, "failed to print array"); */376 /* psFree(output); */377 /* return false; */378 /* } */379 380 /* psFree(output); */381 382 /* return true; */383 /* } */384 385 372 static bool addprocessedexpMode(pxConfig *config) 386 373 { … … 391 378 392 379 // optional 393 PXOPT_LOOKUP_F32(dtime_addstar, config->args, "-dtime_addstar", false, false); 394 395 PXOPT_LOOKUP_S32(n_stars, config->args, "-n_stars", false, false); 396 397 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 398 399 PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false); 380 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 381 PXOPT_LOOKUP_F32(dtime_addstar, config->args, "-dtime_addstar", false, false); 382 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 400 383 401 384 // generate restrictions … … 446 429 pendingRow->add_id, 447 430 dtime_addstar, 448 n_stars,449 431 path_base, 450 0432 fault 451 433 ); 452 434 … … 463 445 464 446 // since there is only one exp per 'new' set addRun.state = 'full' 465 if (!pxaddRunSetState(config, row->add_id, "full" , magicked)) {447 if (!pxaddRunSetState(config, row->add_id, "full")) { 466 448 psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id); 467 449 psFree(row); … … 469 451 return false; 470 452 } 471 472 // NULL for end_stage means go as far as possible473 // EAM : skip here if fault != 0474 // Also, we can run fake even if tess_id is not defined475 /* if (fault || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "add"))) { */476 /* psFree(row); */477 /* psFree(pendingRow); */478 /* if (!psDBCommit(config->dbh)) { */479 /* psError(PS_ERR_UNKNOWN, false, "database error"); */480 /* return false; */481 /* } */482 /* return true; */483 /* } */484 453 psFree(row); 485 // else continue on...486 487 /* if (!pxfakeQueueByAddID(config, */488 /* pendingRow->add_id, */489 /* pendingRow->workdir, */490 /* pendingRow->label, */491 /* pendingRow->reduction, */492 /* pendingRow->expgroup, */493 /* pendingRow->dvodb, */494 /* pendingRow->tess_id, */495 /* pendingRow->end_stage */496 /* )) { */497 /* // rollback */498 /* if (!psDBRollback(config->dbh)) { */499 /* psError(PS_ERR_UNKNOWN, false, "database error"); */500 /* } */501 /* psError(PS_ERR_UNKNOWN, false, "failed to queue new fakeRun"); */502 /* psFree(pendingRow); */503 /* return false; */504 /* } */505 454 psFree(pendingRow); 506 455 … … 517 466 { 518 467 PS_ASSERT_PTR_NON_NULL(config, false); 468 469 // generate restrictions 470 psMetadata *where = psMetadataAlloc(); 471 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); 472 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 473 pxcamGetSearchArgs (config, where); 474 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); 475 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 519 476 520 477 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 521 478 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 522 479 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 523 524 // generate restrictions525 psMetadata *where = psMetadataAlloc();526 pxaddGetSearchArgs (config, where);527 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "==");528 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");529 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");530 480 531 481 if (!psListLength(where->list) && … … 613 563 614 564 psMetadata *where = psMetadataAlloc(); 615 pxaddGetSearchArgs (config, where);616 565 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); 566 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 567 pxcamGetSearchArgs (config, where); 617 568 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); 618 569 PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "=="); 619 /* PXOPT_COPY_S16(config->args, where, "-fault", "addProcessedExp.fault", "=="); */620 570 621 571 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { … … 705 655 PS_ASSERT_PTR_NON_NULL(config, false); 706 656 707 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);708 709 657 psMetadata *where = psMetadataAlloc(); 710 658 PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "=="); 711 659 PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "=="); 712 /* PXOPT_COPY_STR(config->args, where, "-class", "class", "=="); */ 713 /* PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); */ 660 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 714 661 715 662 if (!pxSetFaultCode(config->dbh, "addProcessedExp", where, fault)) { … … 777 724 } 778 725 779 780 726 static bool unblockMode(pxConfig *config) 781 727 { … … 793 739 return true; 794 740 } 795 796 static bool pendingcleanuprunMode(pxConfig *config)797 {798 PS_ASSERT_PTR_NON_NULL(config, NULL);799 800 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);801 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);802 803 psMetadata *where = psMetadataAlloc();804 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");805 806 psString query = pxDataGet("addtool_pendingcleanuprun.sql");807 if (!query) {808 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");809 return false;810 }811 812 if (where && psListLength(where->list)) {813 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);814 psStringAppend(&query, " AND %s", whereClause);815 psFree(whereClause);816 }817 psFree(where);818 819 // treat limit == 0 as "no limit"820 if (limit) {821 psString limitString = psDBGenerateLimitSQL(limit);822 psStringAppend(&query, " %s", limitString);823 psFree(limitString);824 }825 826 if (!p_psDBRunQuery(config->dbh, query)) {827 psError(PS_ERR_UNKNOWN, false, "database error");828 psFree(query);829 return false;830 }831 psFree(query);832 833 psArray *output = p_psDBFetchResult(config->dbh);834 if (!output) {835 psError(PS_ERR_UNKNOWN, false, "database error");836 return false;837 }838 if (!psArrayLength(output)) {839 psTrace("addtool", PS_LOG_INFO, "no rows found");840 psFree(output);841 return true;842 }843 844 // negative simple so the default is true845 if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupRun", !simple)) {846 psError(PS_ERR_UNKNOWN, false, "failed to print array");847 psFree(output);848 return false;849 }850 851 psFree(output);852 853 return true;854 }855 856 857 static bool pendingcleanupexpMode(pxConfig *config)858 {859 PS_ASSERT_PTR_NON_NULL(config, NULL);860 861 PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", false, false);862 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);863 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);864 865 psMetadata *where = psMetadataAlloc();866 if (add_id) {867 PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");868 }869 pxAddLabelSearchArgs (config, where, "-label", "label", "==");870 871 psString query = pxDataGet("addtool_pendingcleanupexp.sql");872 if (!query) {873 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");874 return false;875 }876 877 if (where && psListLength(where->list)) {878 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);879 psStringAppend(&query, " AND %s", whereClause);880 psFree(whereClause);881 }882 psFree(where);883 884 // treat limit == 0 as "no limit"885 if (limit) {886 psString limitString = psDBGenerateLimitSQL(limit);887 psStringAppend(&query, " %s", limitString);888 psFree(limitString);889 }890 891 if (!p_psDBRunQuery(config->dbh, query)) {892 psError(PS_ERR_UNKNOWN, false, "database error");893 psFree(query);894 return false;895 }896 psFree(query);897 898 psArray *output = p_psDBFetchResult(config->dbh);899 if (!output) {900 psError(PS_ERR_UNKNOWN, false, "database error");901 return false;902 }903 if (!psArrayLength(output)) {904 psTrace("chiptool", PS_LOG_INFO, "no rows found");905 psFree(output);906 return true;907 }908 909 // negative simple so the default is true910 if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupExp", !simple)) {911 psError(PS_ERR_UNKNOWN, false, "failed to print array");912 psFree(output);913 return false;914 }915 916 psFree(output);917 918 return true;919 }920 921 922 static bool donecleanupMode(pxConfig *config)923 {924 PS_ASSERT_PTR_NON_NULL(config, NULL);925 926 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);927 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);928 929 psMetadata *where = psMetadataAlloc();930 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");931 932 psString query = pxDataGet("addtool_donecleanup.sql");933 if (!query) {934 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");935 return false;936 }937 938 if (where && psListLength(where->list)) {939 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);940 psStringAppend(&query, " AND %s", whereClause);941 psFree(whereClause);942 }943 psFree(where);944 945 // treat limit == 0 as "no limit"946 if (limit) {947 psString limitString = psDBGenerateLimitSQL(limit);948 psStringAppend(&query, " %s", limitString);949 psFree(limitString);950 }951 952 if (!p_psDBRunQuery(config->dbh, query)) {953 psError(PS_ERR_UNKNOWN, false, "database error");954 psFree(query);955 return false;956 }957 psFree(query);958 959 psArray *output = p_psDBFetchResult(config->dbh);960 if (!output) {961 psError(PS_ERR_UNKNOWN, false, "database error");962 return false;963 }964 if (!psArrayLength(output)) {965 psTrace("addtool", PS_LOG_INFO, "no rows found");966 psFree(output);967 return true;968 }969 970 // negative simple so the default is true971 if (!ippdbPrintMetadatas(stdout, output, "addDoneCleanup", !simple)) {972 psError(PS_ERR_UNKNOWN, false, "failed to print array");973 psFree(output);974 return false;975 }976 977 psFree(output);978 979 return true;980 }981 982 bool exportrunMode(pxConfig *config)983 {984 typedef struct ExportTable {985 char tableName[80];986 char sqlFilename[80];987 } ExportTable;988 989 int numExportTables = 2;990 991 PS_ASSERT_PTR_NON_NULL(config, NULL);992 993 PXOPT_LOOKUP_S64(det_id, config->args, "-add_id", true, false);994 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false);995 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);996 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);997 998 FILE *f = fopen (outfile, "w");999 if (f == NULL) {1000 psError(PS_ERR_UNKNOWN, false, "failed to open output file");1001 return false;1002 }1003 1004 psMetadata *where = psMetadataAlloc();1005 PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");1006 1007 ExportTable tables [] = {1008 {"addRun", "addtool_export_run.sql"},1009 {"addProcessedExp", "addtool_export_processed_exp.sql"},1010 };1011 1012 for (int i=0; i < numExportTables; i++) {1013 psString query = pxDataGet(tables[i].sqlFilename);1014 if (!query) {1015 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");1016 return false;1017 }1018 1019 if (where && psListLength(where->list)) {1020 psString whereClause = psDBGenerateWhereSQL(where, NULL);1021 psStringAppend(&query, " %s", whereClause);1022 psFree(whereClause);1023 }1024 1025 // treat limit == 0 as "no limit"1026 if (limit) {1027 psString limitString = psDBGenerateLimitSQL(limit);1028 psStringAppend(&query, " %s", limitString);1029 psFree(limitString);1030 }1031 1032 if (!p_psDBRunQuery(config->dbh, query)) {1033 psError(PS_ERR_UNKNOWN, false, "database error");1034 psFree(query);1035 return false;1036 }1037 psFree(query);1038 1039 psArray *output = p_psDBFetchResult(config->dbh);1040 if (!output) {1041 psError(PS_ERR_UNKNOWN, false, "database error");1042 return false;1043 }1044 if (!psArrayLength(output)) {1045 psError(PS_ERR_UNKNOWN, true, "no rows found");1046 psFree(output);1047 return false;1048 }1049 1050 if (clean) {1051 if (!strcmp(tables[i].tableName, "addRun")) {1052 if (!pxSetStateCleaned("addRun", "state", output)) {1053 psFree(output);1054 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s", tables[i].tableName);1055 return false;1056 }1057 }1058 }1059 1060 // we must write the export table in non-simple (true) format1061 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {1062 psError(PS_ERR_UNKNOWN, false, "failed to print array");1063 psFree(output);1064 return false;1065 }1066 psFree(output);1067 }1068 1069 fclose (f);1070 1071 return true;1072 }1073 1074 bool importrunMode(pxConfig *config)1075 {1076 unsigned int nFail;1077 1078 PS_ASSERT_PTR_NON_NULL(config, NULL);1079 1080 PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false);1081 1082 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);1083 1084 fprintf (stdout, "---- input ----\n");1085 psMetadataPrint (stderr, input, 1);1086 1087 psMetadataItem *item = psMetadataLookup (input, "addRun");1088 psAssert (item, "entry not in input?");1089 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");1090 1091 psMetadataItem *entry = psListGet (item->data.list, 0);1092 assert (entry);1093 assert (entry->type == PS_DATA_METADATA);1094 addRunRow *addRun = addRunObjectFromMetadata (entry->data.md);1095 addRunInsertObject (config->dbh, addRun);1096 1097 // fprintf (stdout, "---- add run ----\n");1098 // psMetadataPrint (stderr, entry->data.md, 1);1099 1100 item = psMetadataLookup (input, "addProcessedExp");1101 psAssert (item, "entry not in input?");1102 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");1103 1104 for (int i = 0; i < item->data.list->n; i++) {1105 psMetadataItem *entry = psListGet (item->data.list, i);1106 assert (entry);1107 assert (entry->type == PS_DATA_METADATA);1108 addProcessedExpRow *addProcessedExp = addProcessedExpObjectFromMetadata (entry->data.md);1109 addProcessedExpInsertObject (config->dbh, addProcessedExp);1110 1111 // fprintf (stdout, "---- row %d ----\n", i);1112 // psMetadataPrint (stderr, entry->data.md, 1);1113 }1114 1115 return true;1116 }
Note:
See TracChangeset
for help on using the changeset viewer.
