Changeset 25027 for branches/pap/ippTools/src/disttool.c
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/disttool.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ippTools/src
- Property svn:ignore
-
old new 34 34 disttool 35 35 receivetool 36 37 pubtool
-
- Property svn:ignore
-
branches/pap/ippTools/src/disttool.c
r23912 r25027 47 47 static bool pendingdestMode(pxConfig *config); 48 48 49 static bool definetargetMode(pxConfig *config); 50 static bool updatetargetMode(pxConfig *config); 51 static bool listtargetMode(pxConfig *config); 52 53 static bool definedsproductMode(pxConfig *config); 54 static bool updatedsproductMode(pxConfig *config); 55 56 static bool definedestinationMode(pxConfig *config); 57 static bool updatedestinationMode(pxConfig *config); 58 59 static bool defineinterestMode(pxConfig *config); 60 static bool updateinterestMode(pxConfig *config); 61 49 62 # define MODECASE(caseName, func) \ 50 63 case caseName: \ … … 81 94 MODECASE(DISTTOOL_MODE_REVERTRCRUN, revertrcrunMode); 82 95 MODECASE(DISTTOOL_MODE_PENDINGDEST, pendingdestMode); 96 MODECASE(DISTTOOL_MODE_DEFINETARGET, definetargetMode); 97 MODECASE(DISTTOOL_MODE_UPDATETARGET, updatetargetMode); 98 MODECASE(DISTTOOL_MODE_LISTTARGET, listtargetMode); 99 MODECASE(DISTTOOL_MODE_DEFINEDSPRODUCT, definedsproductMode); 100 MODECASE(DISTTOOL_MODE_UPDATEDSPRODUCT, updatedsproductMode); 101 MODECASE(DISTTOOL_MODE_DEFINEDESTINATION, definedestinationMode); 102 MODECASE(DISTTOOL_MODE_UPDATEDESTINATION, updatedestinationMode); 103 MODECASE(DISTTOOL_MODE_DEFINEINTEREST, defineinterestMode); 104 MODECASE(DISTTOOL_MODE_UPDATEINTEREST, updateinterestMode); 83 105 default: 84 106 psAbort("invalid option (this should not happen)"); … … 151 173 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 152 174 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 175 176 // optional 153 177 PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", false, false); 154 155 // optional156 178 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 157 179 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 158 180 PXOPT_LOOKUP_S64(limit, config->args, "-limit", false, false); 181 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 159 182 160 183 PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false); … … 166 189 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 167 190 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 168 PXOPT_COPY_STR(config->args, where, "-obs_mode", "rawExp.obs_mode", "==");169 191 170 192 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); … … 181 203 psFree(where); 182 204 return false; 205 } 206 207 // for raw stage we select by chipRun.label because raw labels typically aren't set 208 if (label) { 209 psStringAppend(&query, " AND (chipRun.label = '%s')", label); 183 210 } 184 211 } else if (!strcmp(stage, "chip")) { … … 323 350 } 324 351 if (!psArrayLength(output)) { 325 psTrace(" warptool", PS_LOG_INFO, "no rows found");352 psTrace("disttool", PS_LOG_INFO, "no rows found"); 326 353 psFree(output); 327 354 return true; 328 355 } 329 356 330 // XXX Remove this debugging output at some point 331 if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) { 332 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 333 psFree(output); 334 return false; 335 } 357 336 358 if (dry_run) { 359 if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) { 360 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 361 psFree(output); 362 return false; 363 } 337 364 psFree(output); 338 365 return true; 339 366 } 340 367 368 if (!psDBTransaction(config->dbh)) { 369 psError(PS_ERR_UNKNOWN, false, "database error"); 370 return false; 371 } 372 373 psArray *list = psArrayAllocEmpty(limit); 341 374 for (long i=0; i < psArrayLength(output); i++) { 342 375 psMetadata *md = output->data[i]; … … 345 378 psS64 stage_id = psMetadataLookupS64(NULL, md, "stage_id"); 346 379 psS64 target_id = psMetadataLookupS64(NULL, md, "target_id"); 380 psString target_label = psMetadataLookupStr(NULL, md, "label"); 347 381 bool clean = psMetadataLookupBool(NULL, md, "clean"); 348 382 … … 350 384 psStringAppend(&outroot, "%s/%s/%s", workdir, run_tag, stage); 351 385 352 if (!distRunInsert(config->dbh, 386 if (set_label == NULL) { 387 set_label = target_label; 388 } 389 distRunRow *row = distRunRowAlloc( 353 390 0, // dist_id 354 391 target_id, … … 362 399 NULL, // time_stamp 363 400 0 // fault 364 )) { 401 ); 402 403 if (!row) { 404 psError(PS_ERR_UNKNOWN, false, "failed to allocate distRunRow"); 405 psFree(outroot); 406 psFree(output); 407 return false; 408 } 409 if (!distRunInsertObject(config->dbh, row)) { 365 410 psError(PS_ERR_UNKNOWN, false, "database error"); 366 411 psFree(outroot); … … 369 414 } 370 415 psFree(outroot); 371 } 372 416 psS64 dist_id = psDBLastInsertID(config->dbh); 417 row->dist_id = dist_id; 418 psArrayAdd(list, list->n, row); 419 psFree(row); 420 } 421 422 if (!psDBCommit(config->dbh)) { 423 psError(PS_ERR_UNKNOWN, false, "database error"); 424 return false; 425 } 426 if (!distRunPrintObjects(stdout, list, !simple)) { 427 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 428 psFree(list); 429 return false; 430 } 431 432 psFree(list); 373 433 psFree(output); 374 434 … … 436 496 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 437 497 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 438 PXOPT_COPY_S16(config->args, where, "-fault", "distComponent.fault", "=="); 498 499 // we need to disambiguate fault so make a copy of the where list before adding fault 500 psMetadata *whereComponent = psMetadataCopy(NULL, where); 501 PXOPT_COPY_S16(config->args, where, "-fault", "distRun.fault", "=="); 502 PXOPT_COPY_S16(config->args, whereComponent, "-fault", "distComponent.fault", "=="); 439 503 440 504 // It might be useful to be able to query by the parameters of the underlying runs … … 481 545 482 546 numUpdated = psDBAffectedRows(config->dbh); 483 484 #ifdef notdef485 // don't need this. distRun.state may still be in 'new' state486 if (numUpdated < 1) {487 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row");488 if (!psDBRollback(config->dbh)) {489 psError(PS_ERR_UNKNOWN, false, "database error");490 }491 return false;492 }493 #endif494 547 } 495 548 … … 508 561 } 509 562 510 if (psListLength(where ->list)) {511 psString whereClause = psDBGenerateWhereConditionSQL(where , NULL);563 if (psListLength(whereComponent->list)) { 564 psString whereClause = psDBGenerateWhereConditionSQL(whereComponent, NULL); 512 565 psStringAppend(&query, " AND %s", whereClause); 513 566 psFree(whereClause); … … 530 583 531 584 psFree(where); 585 psFree(whereComponent); 532 586 533 587 if (!psDBCommit(config->dbh)) { … … 546 600 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 547 601 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 548 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");602 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 549 603 550 604 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 667 721 psMetadata *where = psMetadataAlloc(); 668 722 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 669 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");723 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 670 724 671 725 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 811 865 psMetadata *where = psMetadataAlloc(); 812 866 PXOPT_COPY_S64(config->args, where, "-dist_id", "dist_id", "=="); 813 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");867 pxAddLabelSearchArgs (config, where, "-label", "distRun.label", "=="); 814 868 815 869 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 1109 1163 1110 1164 1111 PXOPT_LOOKUP_STR(last_fileset, config->args, "- last_fileset", false, false);1165 PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false); 1112 1166 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1113 1167 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 1213 1267 return true; 1214 1268 } 1269 1270 static bool definetargetMode(pxConfig *config) 1271 { 1272 PS_ASSERT_PTR_NON_NULL(config, false); 1273 1274 // required 1275 PXOPT_LOOKUP_STR(label, config->args, "-label", true, false); 1276 PXOPT_LOOKUP_STR(filter, config->args, "-filter", true, false); 1277 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 1278 1279 // optional 1280 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1281 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1282 PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false); 1283 1284 distTargetRow *row = distTargetRowAlloc( 1285 0, // target_id 1286 label, 1287 filter, 1288 stage, 1289 clean, 1290 state ? state : "enabled", 1291 comment 1292 ); 1293 1294 if (!row) { 1295 psError(PS_ERR_UNKNOWN, false, "failed to allocate distTarget object"); 1296 return false; 1297 } 1298 if (!distTargetInsertObject(config->dbh, row)) { 1299 psError(PS_ERR_UNKNOWN, false, "database error"); 1300 psFree(row); 1301 return false; 1302 } 1303 1304 // get the assigned target_id 1305 row->target_id = psDBLastInsertID(config->dbh); 1306 1307 if (!distTargetPrintObject(stdout, row, true)) { 1308 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1309 psFree(row); 1310 return false; 1311 } 1312 1313 psFree(row); 1314 1315 return true; 1316 } 1317 static bool updatetargetMode(pxConfig *config) 1318 { 1319 PS_ASSERT_PTR_NON_NULL(config, false); 1320 1321 psMetadata *where = psMetadataAlloc(); 1322 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1323 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1324 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1325 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1326 1327 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 1328 1329 psString query = psStringCopy("UPDATE distTarget SET state = '%s'"); 1330 1331 if (psListLength(where->list)) { 1332 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1333 psStringAppend(&query, " WHERE %s", whereClause); 1334 psFree(whereClause); 1335 } else { 1336 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1337 psFree(where); 1338 psFree(query); 1339 return false; 1340 } 1341 psFree(where); 1342 1343 if (!p_psDBRunQueryF(config->dbh, query, state)) { 1344 psError(PS_ERR_UNKNOWN, false, "database error"); 1345 psFree(query); 1346 return false; 1347 } 1348 psFree(query); 1349 1350 return true; 1351 } 1352 1353 static bool listtargetMode(pxConfig *config) 1354 { 1355 PS_ASSERT_PTR_NON_NULL(config, false); 1356 1357 psMetadata *where = psMetadataAlloc(); 1358 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1359 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1360 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "=="); 1361 PXOPT_COPY_STR(config->args, where, "-stage", "stage", "=="); 1362 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1363 1364 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1365 PXOPT_LOOKUP_BOOL(full, config->args, "-full", false); 1366 1367 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1368 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1369 1370 if (clean && full) { 1371 psError(PS_ERR_UNKNOWN, false, "can't select both -clean and -full"); 1372 return false; 1373 } 1374 1375 psString query = psStringCopy("SELECT * FROM distTarget"); 1376 1377 if (psListLength(where->list)) { 1378 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1379 psStringAppend(&query, " WHERE %s", whereClause); 1380 psFree(whereClause); 1381 if (clean) { 1382 psStringAppend(&query, " AND (clean)"); 1383 } else if (full) { 1384 psStringAppend(&query, " AND (!clean)"); 1385 } 1386 } else if (clean) { 1387 psStringAppend(&query, " WHERE clean"); 1388 } else if (full) { 1389 psStringAppend(&query, " WHERE !clean"); 1390 } 1391 psFree(where); 1392 1393 // treat limit == 0 as "no limit" 1394 if (limit) { 1395 psString limitString = psDBGenerateLimitSQL(limit); 1396 psStringAppend(&query, " %s", limitString); 1397 psFree(limitString); 1398 } 1399 1400 if (!p_psDBRunQuery(config->dbh, query)) { 1401 psError(PS_ERR_UNKNOWN, false, "database error"); 1402 psFree(query); 1403 if (!psDBRollback(config->dbh)) { 1404 psError(PS_ERR_UNKNOWN, false, "database error"); 1405 } 1406 return false; 1407 } 1408 psFree(query); 1409 1410 psArray *output = p_psDBFetchResult(config->dbh); 1411 if (!output) { 1412 psError(PS_ERR_UNKNOWN, false, "database error"); 1413 return false; 1414 } 1415 if (!psArrayLength(output)) { 1416 psTrace("disttool", PS_LOG_INFO, "no rows found"); 1417 psFree(output); 1418 return true; 1419 } 1420 1421 if (!ippdbPrintMetadatas(stdout, output, "distTarget", !simple)) { 1422 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1423 psFree(output); 1424 return false; 1425 } 1426 1427 psFree(output); 1428 1429 return true; 1430 } 1431 1432 static bool definedsproductMode(pxConfig *config) 1433 { 1434 PS_ASSERT_PTR_NON_NULL(config, false); 1435 1436 // required 1437 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1438 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", true, false); 1439 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", true, false); 1440 1441 // XXX: should we insure that these names do not contatin any whitespace? 1442 1443 rcDSProductRow *row = rcDSProductRowAlloc( 1444 0, // prod_id 1445 name, 1446 dbname, 1447 dbhost 1448 ); 1449 1450 if (!row) { 1451 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDSProduct object"); 1452 return false; 1453 } 1454 if (!rcDSProductInsertObject(config->dbh, row)) { 1455 psError(PS_ERR_UNKNOWN, false, "database error"); 1456 psFree(row); 1457 return false; 1458 } 1459 1460 // get the assigned target_id 1461 row->prod_id = psDBLastInsertID(config->dbh); 1462 1463 if (!rcDSProductPrintObject(stdout, row, true)) { 1464 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1465 psFree(row); 1466 return false; 1467 } 1468 1469 psFree(row); 1470 1471 return true; 1472 } 1473 static bool updatedsproductMode(pxConfig *config) 1474 { 1475 PS_ASSERT_PTR_NON_NULL(config, false); 1476 1477 psMetadata *where = psMetadataAlloc(); 1478 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1479 1480 PXOPT_LOOKUP_STR(dbname, config->args, "-ds_dbname", false, false); 1481 PXOPT_LOOKUP_STR(dbhost, config->args, "-ds_dbhost", false, false); 1482 1483 if (!(dbname || dbhost)) { 1484 psError(PS_ERR_UNKNOWN, true, "one or more of dbname or dbhost is required"); 1485 psFree(where); 1486 return false; 1487 } 1488 psString query = psStringCopy("UPDATE rcDSProduct SET"); 1489 psString sep = ""; 1490 if (dbname) { 1491 psStringAppend(&query, " dbname = '%s'", dbname); 1492 sep = ","; 1493 } 1494 if (dbhost) { 1495 psStringAppend(&query, " %s dbhost = '%s'", sep, dbhost); 1496 } 1497 1498 if (psListLength(where->list)) { 1499 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1500 psStringAppend(&query, " WHERE %s", whereClause); 1501 psFree(whereClause); 1502 } else { 1503 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1504 psFree(where); 1505 psFree(query); 1506 return false; 1507 } 1508 psFree(where); 1509 1510 if (!p_psDBRunQuery(config->dbh, query)) { 1511 psError(PS_ERR_UNKNOWN, false, "database error"); 1512 psFree(query); 1513 return false; 1514 } 1515 psFree(query); 1516 1517 return true; 1518 } 1519 1520 static bool definedestinationMode(pxConfig *config) 1521 { 1522 PS_ASSERT_PTR_NON_NULL(config, false); 1523 1524 // required 1525 PXOPT_LOOKUP_S64(prod_id, config->args, "-prod_id", true, false); 1526 PXOPT_LOOKUP_STR(name, config->args, "-name", true, false); 1527 1528 // optional 1529 PXOPT_LOOKUP_STR(status_uri, config->args, "-status_uri", false, false); 1530 PXOPT_LOOKUP_STR(comment, config->args, "-comment", false, false); 1531 PXOPT_LOOKUP_STR(last_fileset, config->args, "-last_fileset", false, false); 1532 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1533 1534 // XXX: should we insure that these names do not contatin any whitespace? 1535 1536 rcDestinationRow *row = rcDestinationRowAlloc( 1537 0, // dest_id 1538 prod_id, 1539 name, 1540 status_uri, 1541 comment, 1542 last_fileset, 1543 state ? state : "enabled" 1544 ); 1545 1546 if (!row) { 1547 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcDestination object"); 1548 return false; 1549 } 1550 if (!rcDestinationInsertObject(config->dbh, row)) { 1551 psError(PS_ERR_UNKNOWN, false, "database error"); 1552 psFree(row); 1553 return false; 1554 } 1555 1556 // get the assigned target_id 1557 row->dest_id = psDBLastInsertID(config->dbh); 1558 1559 if (!rcDestinationPrintObject(stdout, row, true)) { 1560 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1561 psFree(row); 1562 return false; 1563 } 1564 1565 psFree(row); 1566 1567 return true; 1568 } 1569 1570 static bool updatedestinationMode(pxConfig *config) 1571 { 1572 PS_ASSERT_PTR_NON_NULL(config, false); 1573 1574 psMetadata *where = psMetadataAlloc(); 1575 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1576 PXOPT_COPY_S64(config->args, where, "-prod_id", "prod_id", "=="); 1577 1578 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1579 #ifdef ALLOW_UPDATE_LAST_FILESET 1580 PXOPT_LOOKUP_STR(last_fileset, config->args, "-set_last_fileset", false, false); 1581 if (!(state || last_fileset)) { 1582 psError(PS_ERR_UNKNOWN, true, "one or more of -set_state or -set_last_fileset is required"); 1583 # else 1584 if (!state) { 1585 #endif 1586 psFree(where); 1587 return false; 1588 } 1589 psString query = psStringCopy("UPDATE rcDestination SET"); 1590 psString sep = ""; 1591 if (state) { 1592 psStringAppend(&query, " state = '%s'", state); 1593 sep = ","; 1594 } 1595 #ifdef ALLOW_UPDATE_LAST_FILESET 1596 // last_fileset normally gets set by updatercrunMode 1597 // Allowing it to be set here might cause problems 1598 // especially since we are allowing selection by prod_id 1599 if (last_fileset) { 1600 psStringAppend(&query, " %s last_fileset = '%s'", sep, last_fileset); 1601 } 1602 #endif 1603 1604 if (psListLength(where->list)) { 1605 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1606 psStringAppend(&query, " WHERE %s", whereClause); 1607 psFree(whereClause); 1608 } else { 1609 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1610 psFree(where); 1611 psFree(query); 1612 return false; 1613 } 1614 psFree(where); 1615 1616 if (!p_psDBRunQuery(config->dbh, query)) { 1617 psError(PS_ERR_UNKNOWN, false, "database error"); 1618 psFree(query); 1619 return false; 1620 } 1621 psFree(query); 1622 1623 return true; 1624 } 1625 1626 static bool defineinterestMode(pxConfig *config) 1627 { 1628 PS_ASSERT_PTR_NON_NULL(config, false); 1629 1630 // required 1631 PXOPT_LOOKUP_S64(dest_id, config->args, "-dest_id", true, false); 1632 PXOPT_LOOKUP_S64(target_id, config->args, "-target_id", true, false); 1633 1634 // optional 1635 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1636 1637 // XXX: should we insure that these names do not contatin any whitespace? 1638 1639 rcInterestRow *row = rcInterestRowAlloc( 1640 0, // int_id 1641 dest_id, 1642 target_id, 1643 state ? state : "enabled" 1644 ); 1645 1646 if (!row) { 1647 psError(PS_ERR_UNKNOWN, false, "failed to allocate rcInterest object"); 1648 return false; 1649 } 1650 if (!rcInterestInsertObject(config->dbh, row)) { 1651 psError(PS_ERR_UNKNOWN, false, "database error"); 1652 psFree(row); 1653 return false; 1654 } 1655 1656 // get the assigned target_id 1657 row->int_id = psDBLastInsertID(config->dbh); 1658 1659 if (!rcInterestPrintObject(stdout, row, true)) { 1660 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 1661 psFree(row); 1662 return false; 1663 } 1664 1665 psFree(row); 1666 1667 return true; 1668 } 1669 1670 static bool updateinterestMode(pxConfig *config) 1671 { 1672 PS_ASSERT_PTR_NON_NULL(config, false); 1673 1674 psMetadata *where = psMetadataAlloc(); 1675 PXOPT_COPY_S64(config->args, where, "-int_id", "int_id", "=="); 1676 PXOPT_COPY_S64(config->args, where, "-dest_id", "dest_id", "=="); 1677 PXOPT_COPY_S64(config->args, where, "-target_id", "target_id", "=="); 1678 1679 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1680 if (!state) { 1681 psError(PS_ERR_UNKNOWN, true, "-set_state is required"); 1682 psFree(where); 1683 return false; 1684 } 1685 psString query = NULL; 1686 psStringAppend(&query, "UPDATE rcInterest SET state = '%s'", state); 1687 1688 if (psListLength(where->list)) { 1689 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1690 psStringAppend(&query, " WHERE %s", whereClause); 1691 psFree(whereClause); 1692 } else { 1693 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 1694 psFree(where); 1695 psFree(query); 1696 return false; 1697 } 1698 psFree(where); 1699 1700 if (!p_psDBRunQuery(config->dbh, query)) { 1701 psError(PS_ERR_UNKNOWN, false, "database error"); 1702 psFree(query); 1703 return false; 1704 } 1705 psFree(query); 1706 1707 return true; 1708 } 1709
Note:
See TracChangeset
for help on using the changeset viewer.
