- Timestamp:
- Dec 2, 2011, 11:44:07 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20111122/ippTools/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamptool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippTools/src
- Property svn:mergeinfo changed
/trunk/ippTools/src (added) merged: 32764,32770-32771,32786,32832-32833
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20111122/ippTools/src/pstamptool.c
r32360 r32851 56 56 static bool revertdependentMode(pxConfig *config); 57 57 static bool getwebrequestnumMode(pxConfig *config); 58 static bool addfileMode(pxConfig *config); 59 static bool listfileMode(pxConfig *config); 60 static bool deletefileMode(pxConfig *config); 58 61 59 62 # define MODECASE(caseName, func) \ … … 103 106 MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode); 104 107 MODECASE(PSTAMPTOOL_MODE_GETWEBREQUESTNUM, getwebrequestnumMode); 108 MODECASE(PSTAMPTOOL_MODE_ADDFILE, addfileMode); 109 MODECASE(PSTAMPTOOL_MODE_LISTFILE, listfileMode); 110 MODECASE(PSTAMPTOOL_MODE_DELETEFILE, deletefileMode); 105 111 default: 106 112 psAbort("invalid option (this should not happen)"); … … 1476 1482 return true; 1477 1483 } 1484 1485 static bool addfileMode(pxConfig *config) 1486 { 1487 PS_ASSERT_PTR_NON_NULL(config, false); 1488 1489 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 1490 PXOPT_LOOKUP_STR(path, config->args, "-path", true, false); 1491 1492 if (!pstampFileInsert(config->dbh, 1493 0, // file_id 1494 job_id, 1495 path 1496 )) { 1497 psError(PS_ERR_UNKNOWN, false, "database error"); 1498 return false; 1499 } 1500 1501 psU64 affected = psDBAffectedRows(config->dbh); 1502 if (affected != 1) { 1503 psError(PS_ERR_UNKNOWN, false, 1504 "should have affected one row but %" PRIu64 " rows were modified", 1505 affected); 1506 return false; 1507 } 1508 1509 psS64 file_id = psDBLastInsertID(config->dbh); 1510 printf("%" PRId64 "\n", file_id); 1511 1512 return true; 1513 } 1514 1515 static bool listfileMode(pxConfig *config) 1516 { 1517 PS_ASSERT_PTR_NON_NULL(config, false); 1518 1519 psMetadata *where = psMetadataAlloc(); 1520 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 1521 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 1522 PXOPT_COPY_S64(config->args, where, "-file_id", "file_id", "=="); 1523 1524 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1525 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1526 1527 if (!psListLength(where->list)) { 1528 fprintf(stderr, "search arguments are required\n"); 1529 exit (1); 1530 } 1531 1532 psString query = pxDataGet("pstamptool_listfile.sql"); 1533 if (!query) { 1534 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1535 return false; 1536 } 1537 1538 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 1539 if (psListLength(where->list)) { 1540 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1541 psStringAppend(&query, " WHERE %s", whereClause); 1542 psFree(whereClause); 1543 } 1544 psFree(where); 1545 1546 // treat limit == 0 as "no limit" 1547 if (limit) { 1548 psString limitString = psDBGenerateLimitSQL(limit); 1549 psStringAppend(&query, " %s", limitString); 1550 psFree(limitString); 1551 } 1552 1553 if (!p_psDBRunQuery(config->dbh, query)) { 1554 psError(PS_ERR_UNKNOWN, false, "database error"); 1555 psFree(query); 1556 return false; 1557 } 1558 psFree(query); 1559 1560 psArray *output = p_psDBFetchResult(config->dbh); 1561 if (!output) { 1562 psError(PS_ERR_UNKNOWN, false, "database error"); 1563 return false; 1564 } 1565 if (!psArrayLength(output)) { 1566 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 1567 psFree(output); 1568 return true; 1569 } 1570 1571 // negative simple so the default is true 1572 if (!ippdbPrintMetadatas(stdout, output, "pstampFile", !simple)) { 1573 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1574 psFree(output); 1575 return false; 1576 } 1577 1578 psFree(output); 1579 1580 return true; 1581 } 1582 1583 static bool deletefileMode(pxConfig *config) 1584 { 1585 PS_ASSERT_PTR_NON_NULL(config, false); 1586 1587 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 1588 1589 psString query = NULL; 1590 psStringAppend(&query, "DELETE FROM pstampFile WHERE job_id = %" PRId64, job_id); 1591 1592 if (!p_psDBRunQuery(config->dbh, query)) { 1593 psError(PS_ERR_UNKNOWN, false, "database error"); 1594 psFree(query); 1595 return false; 1596 } 1597 psFree(query); 1598 1599 psU64 affected = psDBAffectedRows(config->dbh); 1600 psLogMsg("pstamptool", PS_LOG_INFO, "Deleted %" PRIu64 " rows from pstampFile", affected); 1601 1602 return true; 1603 }
Note:
See TracChangeset
for help on using the changeset viewer.
