IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2007, 12:19:29 PM (19 years ago)
Author:
jhoblitt
Message:

stub out all p5tool modes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/difftool.c

    r11784 r11787  
    5353    psLibInit(NULL);
    5454
    55     pxConfig *config = p4toolConfig(NULL, argc, argv);
     55    pxConfig *config = p5toolConfig(NULL, argc, argv);
    5656
    5757    switch (config->mode) {
    58         MODECASE(54TOOL_MODE_DEFINERUN,         definerunMode);
    59         MODECASE(54TOOL_MODE_UPDATERUN,         updaterunMode);
    60         MODECASE(P4TOOL_MODE_ADDINPUTSCFILE,    addinputscfile);
    61         MODECASE(P4TOOL_MODE_INPUTSCFILE,       inputscfileMode);
    62         MODECASE(P4TOOL_MODE_TODIFFSCFILE,      todiffscfileMode);
    63         MODECASE(P4TOOL_MODE_ADDDIFFSCFILE,     adddiffscfileMode);
    64         MODECASE(P4TOOL_MODE_DIFFSCFILE,        diffscfileMode);
     58        MODECASE(P5TOOL_MODE_DEFINERUN,         definerunMode);
     59        MODECASE(P5TOOL_MODE_UPDATERUN,         updaterunMode);
     60        MODECASE(P5TOOL_MODE_ADDINPUTSCFILE,    addinputscfileMode);
     61        MODECASE(P5TOOL_MODE_INPUTSCFILE,       inputscfileMode);
     62        MODECASE(P5TOOL_MODE_TODIFFSCFILE,      todiffscfileMode);
     63        MODECASE(P5TOOL_MODE_ADDDIFFSCFILE,     adddiffscfileMode);
     64        MODECASE(P5TOOL_MODE_DIFFSCFILE,        diffscfileMode);
    6565        default:
    6666            psAbort("invalid option (this should not happen)");
     
    198198    if (state) {
    199199        // set detRun.state to state
    200         return setp4RunState(config, p4_id, state);
    201     }
    202 
    203     return true;
    204 }
    205 
    206 
    207 static bool addinputexpMode(pxConfig *config)
     200        return setp5RunState(config, p4_id, state);
     201    }
     202
     203    return true;
     204}
     205
     206
     207static bool addinputscfileMode(pxConfig *config)
    208208{
    209209    PS_ASSERT_PTR_NON_NULL(config, false);
     
    261261
    262262
    263 static bool expMode(pxConfig *config)
     263static bool inputscfileMode(pxConfig *config)
    264264{
    265265    PS_ASSERT_PTR_NON_NULL(config, false);
     
    352352
    353353
    354 static bool imfileMode(pxConfig *config)
    355 {
    356     PS_ASSERT_PTR_NON_NULL(config, false);
    357 
    358     bool status = false;
    359     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    360     if (!status) {
    361         psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
    362         return false;
    363     }
    364 
    365     // find all rawImfiles matching the default query
    366     psString query = psStringCopy(
    367         "SELECT\n"
    368         "   rawImfile.*\n"
    369         " FROM p4Run\n"
    370         " JOIN p4InputExp\n"
    371         "   USING(p4_id)\n"
    372         " JOIN rawImfile\n -- is there any reason not to refer back to rawimfiles?"
    373         "   ON p4InputExp.exp_tag = rawImfile.exp_tag\n"
    374         " WHERE\n"
    375         "   p4Run.state = 'run'\n"
    376     );
    377     if (config->where) {
    378         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp");
    379         psStringAppend(&query, " AND %s", whereClause);
    380         psFree(whereClause);
    381     }
    382 
    383     // treat limit == 0 as "no limit"
    384     if (limit) {
    385         psString limitString = psDBGenerateLimitSQL(limit);
    386         psStringAppend(&query, " %s", limitString);
    387         psFree(limitString);
    388     }
    389 
    390     if (!p_psDBRunQuery(config->dbh, query)) {
    391         psError(PS_ERR_UNKNOWN, false, "database error");
    392         psFree(query);
    393         return false;
    394     }
    395     psFree(query);
    396 
    397     psArray *output = p_psDBFetchResult(config->dbh);
    398     if (!output) {
    399         psErrorCode err = psErrorCodeLast();
    400         switch (err) {
    401             case PS_ERR_DB_CLIENT:
    402                 psError(PXTOOLS_ERR_SYS, false, "database error");
    403             case PS_ERR_DB_SERVER:
    404                 psError(PXTOOLS_ERR_PROG, false, "database error");
    405             default:
    406                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    407         }
    408 
    409         return false;
    410     }
    411     if (!psArrayLength(output)) {
    412         psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found");
    413         psFree(output);
    414         return true;
    415     }
    416 
    417     bool simple = false;
    418     {
    419         bool status = false;
    420         simple = psMetadataLookupBool(&status, config->args, "-simple");
    421         if (!status) {
    422             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    423             return false;
    424         }
    425     }
    426 
    427     if (psArrayLength(output)) {
    428         // negative simple so the default is true
    429         if (!ippdbPrintMetadatas(stdout, output, "p4InputImfile", !simple)) {
    430             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    431             psFree(output);
    432             return false;
    433         }
    434     }
    435 
    436     psFree(output);
    437 
    438     return true;
    439 }
    440 
    441 
    442 static bool tooverlapMode(pxConfig *config)
     354static bool todiffscfileMode(pxConfig *config)
    443355{
    444356    PS_ASSERT_PTR_NON_NULL(config, false);
     
    538450
    539451
    540 static bool addoverlapMode(pxConfig *config)
    541 {
    542     PS_ASSERT_PTR_NON_NULL(config, false);
    543 
    544     bool status = false;
    545     psString mapfile = psMetadataLookupStr(&status, config->args, "-mapfile");
    546     if (!status) {
    547         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -mapfile");
    548         return false;
    549     }
    550     if (!mapfile) {
    551         psError(PS_ERR_UNKNOWN, true, "-mapfile is required");
    552         return false;
    553     }
    554 
    555     if (!psDBTransaction(config->dbh)) {
    556         psError(PS_ERR_UNKNOWN, false, "database error");
    557         return false;
    558     }
    559 
    560     if (!parseAndInsertSkyCellMap(config, mapfile)) {
    561         psError(PS_ERR_UNKNOWN, false, "failed to inject mapfile: %s into the database", mapfile);
    562         // rollback
    563         if (!psDBRollback(config->dbh)) {
    564             psError(PS_ERR_UNKNOWN, false, "database error");
    565         }
    566         return false;
    567     }
    568 
    569     // point of no return
    570     if (!psDBCommit(config->dbh)) {
    571         psError(PS_ERR_UNKNOWN, false, "database error");
    572         return false;
    573     }
    574 
    575     return true;
    576 }
    577 
    578 
    579 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile)
    580 {
    581     unsigned int nFail = 0;
    582     psMetadata *skycells = psMetadataConfigRead(NULL, &nFail, mapfile, false);
    583     if (!skycells) {
    584         psError(PS_ERR_UNKNOWN, false, "failed to parse mapfile: %s", mapfile);
    585         return false;
    586     }       
    587     if (nFail) {
    588         psError(PS_ERR_UNKNOWN, false, "there were %d errors parsing mapfile: %s", nFail, mapfile);
    589         psFree(skycells);
    590         return false;
    591     }
    592 
    593     psMetadataItem *item = NULL;
    594     psMetadataIterator *iter = psMetadataIteratorAlloc(skycells, 0, NULL);
    595     if ((item = psMetadataGetAndIncrement(iter))) {
    596         if (item->type != PS_DATA_METADATA) {
    597             psError(PS_ERR_UNKNOWN, false, "mapfile: %s is in the wrong format", mapfile);
    598             psFree(iter);
    599             psFree(skycells);
    600             return false;
    601         }
    602 
    603         psMetadata *sc = item->data.md;
    604         // this conversion isn't strictly nessicary but it's an easy way of
    605         // validating the format
    606         p4SkyCellMapRow *row = p4SkyCellMapObjectFromMetadata(sc);
    607         if (!row) {
    608             psError(PS_ERR_UNKNOWN, false, "failed to convert mapfile: %s metdata entry into a p4SkyCellMap object", mapfile);
    609             psFree(iter);
    610             psFree(skycells);
    611             return false;
    612         }
    613 
    614         if (!p4SkyCellMapInsertObject(config->dbh, row)) {
    615             psErrorCode err = psErrorCodeLast();
    616             switch (err) {
    617                 case PS_ERR_DB_CLIENT:
    618                     psError(PXTOOLS_ERR_SYS, false, "database error");
    619                 case PS_ERR_DB_SERVER:
    620                     psError(PXTOOLS_ERR_PROG, false, "database error");
    621                 default:
    622                     psError(PXTOOLS_ERR_PROG, false, "unknown error");
    623             }
    624             psFree(row);
    625             psFree(iter);
    626             psFree(skycells);
    627             return false;
    628         }
    629 
    630         psFree(row);
    631     }
    632     psFree(iter);
    633     psFree(skycells);
    634 
    635     return true;
    636 }
    637 
    638 
    639 static bool scmapMode(pxConfig *config)
    640 {
    641     PS_ASSERT_PTR_NON_NULL(config, false);
    642 
    643     bool status = false;
    644     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    645     if (!status) {
    646         psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
    647         return false;
    648     }
    649 
    650     // find all rawImfiles matching the default query
    651     psString query = psStringCopy(
    652         "SELECT\n"
    653         "   p4SkyCellMap.*\n"
    654         " FROM p4Run\n"
    655         " JOIN p4SkyCellMap\n"
    656         "   USING(p4_id)\n"
    657         " WHERE\n"
    658         "   p4Run.state = 'run'\n"
    659     );
    660 
    661     if (config->where) {
    662         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");
    663         psStringAppend(&query, " AND %s", whereClause);
    664         psFree(whereClause);
    665     }
    666 
    667     // treat limit == 0 as "no limit"
    668     if (limit) {
    669         psString limitString = psDBGenerateLimitSQL(limit);
    670         psStringAppend(&query, " %s", limitString);
    671         psFree(limitString);
    672     }
    673 
    674     if (!p_psDBRunQuery(config->dbh, query)) {
    675         psError(PS_ERR_UNKNOWN, false, "database error");
    676         psFree(query);
    677         return false;
    678     }
    679     psFree(query);
    680 
    681     psArray *output = p_psDBFetchResult(config->dbh);
    682     if (!output) {
    683         psErrorCode err = psErrorCodeLast();
    684         switch (err) {
    685             case PS_ERR_DB_CLIENT:
    686                 psError(PXTOOLS_ERR_SYS, false, "database error");
    687             case PS_ERR_DB_SERVER:
    688                 psError(PXTOOLS_ERR_PROG, false, "database error");
    689             default:
    690                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    691         }
    692 
    693         return false;
    694     }
    695     if (!psArrayLength(output)) {
    696         psError(PS_ERR_UNKNOWN, false, "no p4SkyCellMap rows found");
    697         psFree(output);
    698         return true;
    699     }
    700 
    701     bool simple = false;
    702     {
    703         bool status = false;
    704         simple = psMetadataLookupBool(&status, config->args, "-simple");
    705         if (!status) {
    706             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    707             return false;
    708         }
    709     }
    710 
    711     if (psArrayLength(output)) {
    712         // negative simple so the default is true
    713         if (!ippdbPrintMetadatas(stdout, output, "p4SkyCellMap", !simple)) {
    714             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    715             psFree(output);
    716             return false;
    717         }
    718     }
    719 
    720     psFree(output);
    721 
    722     return true;
    723 }
    724 
    725 
    726 static bool towarpedMode(pxConfig *config)
    727 {
    728     PS_ASSERT_PTR_NON_NULL(config, false);
    729 
    730     bool status = false;
    731     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    732     if (!status) {
    733         psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
    734         return false;
    735     }
    736 
    737     // find all rawImfiles matching the default query
    738     psString query = psStringCopy(
    739         "SELECT\n"
    740         "   p4SkyCellMap.*\n"
    741         " FROM p4Run\n"
    742         " JOIN p4SkyCellMap\n"
    743         "   USING(p4_id)\n"
    744         " LEFT JOIN p4Scfile\n"
    745         "   USING(p4_id, skycell_id, tess_id, exp_tag, p3_version)\n"
    746         " WHERE\n"
    747         "   p4Run.state = 'run'\n"
    748         "   AND p4Scfile.p4_id IS NULL\n"
    749         "   AND p4Scfile.skycell_id IS NULL\n"
    750         "   AND p4Scfile.tess_id IS NULL\n"
    751         "   AND p4Scfile.exp_tag IS NULL\n"
    752         "   AND p4Scfile.p3_version IS NULL\n"
    753     );
    754 
    755     if (config->where) {
    756         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");
    757         psStringAppend(&query, " AND %s", whereClause);
    758         psFree(whereClause);
    759     }
    760 
    761     // treat limit == 0 as "no limit"
    762     if (limit) {
    763         psString limitString = psDBGenerateLimitSQL(limit);
    764         psStringAppend(&query, " %s", limitString);
    765         psFree(limitString);
    766     }
    767 
    768     if (!p_psDBRunQuery(config->dbh, query)) {
    769         psError(PS_ERR_UNKNOWN, false, "database error");
    770         psFree(query);
    771         return false;
    772     }
    773     psFree(query);
    774 
    775     psArray *output = p_psDBFetchResult(config->dbh);
    776     if (!output) {
    777         psErrorCode err = psErrorCodeLast();
    778         switch (err) {
    779             case PS_ERR_DB_CLIENT:
    780                 psError(PXTOOLS_ERR_SYS, false, "database error");
    781             case PS_ERR_DB_SERVER:
    782                 psError(PXTOOLS_ERR_PROG, false, "database error");
    783             default:
    784                 psError(PXTOOLS_ERR_PROG, false, "unknown error");
    785         }
    786 
    787         return false;
    788     }
    789     if (!psArrayLength(output)) {
    790         psError(PS_ERR_UNKNOWN, false, "no p4PendingSkyCell rows found");
    791         psFree(output);
    792         return true;
    793     }
    794 
    795     bool simple = false;
    796     {
    797         bool status = false;
    798         simple = psMetadataLookupBool(&status, config->args, "-simple");
    799         if (!status) {
    800             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    801             return false;
    802         }
    803     }
    804 
    805     if (psArrayLength(output)) {
    806         // negative simple so the default is true
    807         if (!ippdbPrintMetadatas(stdout, output, "p4PendingSkyCell", !simple)) {
    808             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    809             psFree(output);
    810             return false;
    811         }
    812     }
    813 
    814     psFree(output);
    815 
    816     return true;
    817 }
    818 
    819 
    820 static bool addwarpedMode(pxConfig *config)
     452static bool adddiffscfileMode(pxConfig *config)
    821453{
    822454    PS_ASSERT_PTR_NON_NULL(config, false);
     
    912544}
    913545
    914 static bool warpedMode(pxConfig *config)
     546static bool diffscfileMode(pxConfig *config)
    915547{
    916548    PS_ASSERT_PTR_NON_NULL(config, false);
     
    998630}
    999631
    1000 #if 0
    1001 static bool tostackedimfileMode(pxConfig *config)
    1002 {
    1003     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1004 
    1005     psString query = psStringCopy(
    1006         " SELECT DISTINCT"
    1007         "   p4WarpedImfile.*,"
    1008         "   p4Run.workdir"
    1009         " FROM p4Run"
    1010         " JOIN p4WarpedImfile"
    1011         "   USING(p4_id)"
    1012         " LEFT JOIN p4StackedImfile"
    1013         "   USING(p4_id, class_id)"
    1014         " WHERE"
    1015         "   p4Run.state = 'run'"
    1016         "   AND p4StackedImfile.p4_id IS NULL"
    1017         "   AND p4Stackedmfile.class_id IS NULL"
    1018     );
    1019 
    1020     if (config->where) {
    1021         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4WarpedImfile");
    1022         psStringAppend(&query, " AND %s", whereClause);
    1023         psFree(whereClause);
    1024     }
    1025 
    1026     if (!p_psDBRunQuery(config->dbh, query)) {
    1027         psError(PS_ERR_UNKNOWN, false, "database error");
    1028         psFree(query);
    1029         return false;
    1030     }
    1031     psFree(query);
    1032 
    1033     psArray *output = p_psDBFetchResult(config->dbh);
    1034     if (!output) {
    1035         psError(PS_ERR_UNKNOWN, false, "database error");
    1036         return false;
    1037     }
    1038     if (!psArrayLength(output)) {
    1039         psError(PS_ERR_UNKNOWN, false, "no p4WarpedImfile rows found");
    1040         psFree(output);
    1041         return true;
    1042     }
    1043 
    1044     bool simple = false;
    1045     {
    1046         bool status = false;
    1047         simple = psMetadataLookupBool(&status, config->args, "-simple");
    1048         if (!status) {
    1049             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    1050             return false;
    1051         }
    1052     }
    1053 
    1054     // negative simple so the default is true
    1055     if (!ippdbPrintMetadatas(stdout, output, "p4WarpedImfile", !simple)) {
    1056         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1057         psFree(output);
    1058         return false;
    1059     }
    1060 
    1061     psFree(output);
    1062 
    1063     return true;
    1064 }
    1065 
    1066 static bool addstackedimfileMode(pxConfig *config)
    1067 {
    1068     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1069 
    1070     bool status = false;
    1071     psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
    1072     if (!status) {
    1073         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
    1074         return false;
    1075     }
    1076     if (!p4_id) {
    1077         psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
    1078         return false;
    1079     }
    1080 
    1081     psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
    1082     if (!status) {
    1083         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
    1084         return false;
    1085     }
    1086     if (!class_id) {
    1087         psError(PS_ERR_UNKNOWN, true, "-class_id is required");
    1088         return false;
    1089     }
    1090 
    1091     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    1092     if (!status) {
    1093         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
    1094         return false;
    1095     }
    1096     if (!uri) {
    1097         psError(PS_ERR_UNKNOWN, true, "-uri is required");
    1098         return false;
    1099     }
    1100 
    1101     // optional
    1102     psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
    1103     if (!status) {
    1104         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
    1105         return false;
    1106     }
    1107 
    1108     psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
    1109     if (!status) {
    1110         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
    1111         return false;
    1112     }
    1113 
    1114     // XXX need to validate that this coresponds to an p4WarpedImfile
    1115     if (!p4StackedImfileInsert(config->dbh,
    1116             (psS32)atoi(p4_id),
    1117             class_id,
    1118             uri,
    1119             b1_uri,
    1120             b2_uri
    1121         )) {
    1122         psError(PS_ERR_UNKNOWN, false, "database error");
    1123         return false;
    1124     }
    1125 
    1126     return true;
    1127 }
    1128 
    1129 static bool stackedimfileMode(pxConfig *config)
    1130 {
    1131     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1132 
    1133     psString query = psStringCopy(
    1134         " SELECT DISTINCT"
    1135         "   p4StackedImfile.*"
    1136         " FROM p4Run"
    1137         " JOIN p4StackedImfile"
    1138         "   USING(p4_id)"
    1139         " WHERE"
    1140         "   p4Run.state = 'run'"
    1141     );
    1142 
    1143     if (config->where) {
    1144         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile");
    1145         psStringAppend(&query, " AND %s", whereClause);
    1146         psFree(whereClause);
    1147     }
    1148 
    1149     if (!p_psDBRunQuery(config->dbh, query)) {
    1150         psError(PS_ERR_UNKNOWN, false, "database error");
    1151         psFree(query);
    1152         return false;
    1153     }
    1154     psFree(query);
    1155 
    1156     psArray *output = p_psDBFetchResult(config->dbh);
    1157     if (!output) {
    1158         psError(PS_ERR_UNKNOWN, false, "database error");
    1159         return false;
    1160     }
    1161     if (!psArrayLength(output)) {
    1162         psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found");
    1163         psFree(output);
    1164         return true;
    1165     }
    1166 
    1167     bool simple = false;
    1168     {
    1169         bool status = false;
    1170         simple = psMetadataLookupBool(&status, config->args, "-simple");
    1171         if (!status) {
    1172             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    1173             return false;
    1174         }
    1175     }
    1176 
    1177     // negative simple so the default is true
    1178     if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) {
    1179         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1180         psFree(output);
    1181         return false;
    1182     }
    1183 
    1184     psFree(output);
    1185 
    1186     return true;
    1187 }
    1188 
    1189 static bool todiffimfileMode(pxConfig *config)
    1190 {
    1191     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1192 
    1193     psString query = psStringCopy(
    1194         " SELECT DISTINCT"
    1195         "   p4StackedImfile.*,"
    1196         "   p4WarpedImfile.uri as warped_uri,"
    1197         "   p4Run.workdir"
    1198         " FROM p4Run"
    1199         " JOIN p4StackedImfile"
    1200         "   USING(p4_id)"
    1201         " JOIN p4WarpedImfile"
    1202         "   USING(p4_id, class_id)"
    1203         " LEFT JOIN p4DiffImfile"
    1204         "   ON p4WarpedImfile.p4_id = p4DiffImfile.p4_id"
    1205         "   AND p4WarpedImfile.exp_tag = p4DiffImfile.exp_tag"
    1206         "   AND p4WarpedImfile.p3_version = p4DiffImfile.p3_version"
    1207         "   AND p4WarpedImfile.class_id = p4DiffImfile.class_id"
    1208         " WHERE"
    1209         "   p4Run.state = 'run'"
    1210         "   AND p4DiffImfile.p4_id IS NULL"
    1211         "   AND p4DiffImfile.exp_tag IS NULL"
    1212         "   AND p4DiffImfile.p3_version IS NULL"
    1213         "   AND p4DiffImfile.class_id IS NULL"
    1214     );
    1215 
    1216     if (config->where) {
    1217         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile");
    1218         psStringAppend(&query, " AND %s", whereClause);
    1219         psFree(whereClause);
    1220     }
    1221 
    1222     if (!p_psDBRunQuery(config->dbh, query)) {
    1223         psError(PS_ERR_UNKNOWN, false, "database error");
    1224         psFree(query);
    1225         return false;
    1226     }
    1227     psFree(query);
    1228 
    1229     psArray *output = p_psDBFetchResult(config->dbh);
    1230     if (!output) {
    1231         psError(PS_ERR_UNKNOWN, false, "database error");
    1232         return false;
    1233     }
    1234     if (!psArrayLength(output)) {
    1235         psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found");
    1236         psFree(output);
    1237         return true;
    1238     }
    1239 
    1240     bool simple = false;
    1241     {
    1242         bool status = false;
    1243         simple = psMetadataLookupBool(&status, config->args, "-simple");
    1244         if (!status) {
    1245             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    1246             return false;
    1247         }
    1248     }
    1249 
    1250     // negative simple so the default is true
    1251     if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) {
    1252         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1253         psFree(output);
    1254         return false;
    1255     }
    1256 
    1257     psFree(output);
    1258 
    1259     return true;
    1260 }
    1261 
    1262 static bool adddiffimfileMode(pxConfig *config)
    1263 {
    1264     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1265 
    1266     bool status = false;
    1267     psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
    1268     if (!status) {
    1269         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
    1270         return false;
    1271     }
    1272     if (!p4_id) {
    1273         psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
    1274         return false;
    1275     }
    1276 
    1277     psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
    1278     if (!status) {
    1279         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
    1280         return false;
    1281     }
    1282     if (!exp_tag) {
    1283         psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
    1284         return false;
    1285     }
    1286 
    1287     psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
    1288     if (!status) {
    1289         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
    1290         return false;
    1291     }
    1292     if (!class_id) {
    1293         psError(PS_ERR_UNKNOWN, true, "-class_id is required");
    1294         return false;
    1295     }
    1296 
    1297     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    1298     if (!status) {
    1299         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
    1300         return false;
    1301     }
    1302     if (!uri) {
    1303         psError(PS_ERR_UNKNOWN, true, "-uri is required");
    1304         return false;
    1305     }
    1306 
    1307     // defaults to 0
    1308     psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");
    1309     if (!status) {
    1310         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
    1311         return false;
    1312     }
    1313 
    1314     // optional
    1315     psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
    1316     if (!status) {
    1317         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
    1318         return false;
    1319     }
    1320 
    1321     psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
    1322     if (!status) {
    1323         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
    1324         return false;
    1325     }
    1326 
    1327     // XXX need to validate that this coresponds to an p4InputImfile
    1328     if (!p4DiffImfileInsert(config->dbh,
    1329             (psS32)atoi(p4_id),
    1330             exp_tag,
    1331             p3_version,
    1332             class_id,
    1333             uri,
    1334             b1_uri,
    1335             b2_uri
    1336         )) {
    1337         psError(PS_ERR_UNKNOWN, false, "database error");
    1338         return false;
    1339     }
    1340 
    1341     return true;
    1342 }
    1343 
    1344 static bool diffimfileMode(pxConfig *config)
    1345 {
    1346     PS_ASSERT_PTR_NON_NULL(config, NULL);
    1347 
    1348     psString query = psStringCopy(
    1349         " SELECT DISTINCT"
    1350         "   p4DiffImfile.*"
    1351         " FROM p4Run"
    1352         " JOIN p4DiffImfile"
    1353         "   USING(p4_id)"
    1354         " WHERE"
    1355         "   p4Run.state = 'run'"
    1356     );
    1357 
    1358     if (config->where) {
    1359         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4DiffImfile");
    1360         psStringAppend(&query, " AND %s", whereClause);
    1361         psFree(whereClause);
    1362     }
    1363 
    1364     if (!p_psDBRunQuery(config->dbh, query)) {
    1365         psError(PS_ERR_UNKNOWN, false, "database error");
    1366         psFree(query);
    1367         return false;
    1368     }
    1369     psFree(query);
    1370 
    1371     psArray *output = p_psDBFetchResult(config->dbh);
    1372     if (!output) {
    1373         psError(PS_ERR_UNKNOWN, false, "database error");
    1374         return false;
    1375     }
    1376     if (!psArrayLength(output)) {
    1377         psError(PS_ERR_UNKNOWN, false, "no p4DiffImfile rows found");
    1378         psFree(output);
    1379         return true;
    1380     }
    1381 
    1382     bool simple = false;
    1383     {
    1384         bool status = false;
    1385         simple = psMetadataLookupBool(&status, config->args, "-simple");
    1386         if (!status) {
    1387             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    1388             return false;
    1389         }
    1390     }
    1391 
    1392     // negative simple so the default is true
    1393     if (!ippdbPrintMetadatas(stdout, output, "p4DiffImfile", !simple)) {
    1394         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1395         psFree(output);
    1396         return false;
    1397     }
    1398 
    1399     psFree(output);
    1400 
    1401     return true;
    1402 }
    1403 #endif
    1404 
    1405 static bool setp4RunState(pxConfig *config, const char *p4_id, const char *state)
     632static bool setp5RunState(pxConfig *config, const char *p4_id, const char *state)
    1406633{
    1407634    PS_ASSERT_PTR_NON_NULL(p4_id, false);
Note: See TracChangeset for help on using the changeset viewer.