Changeset 32771 for trunk/ippTools/src/pstamptool.c
- Timestamp:
- Nov 22, 2011, 2:22:43 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r32360 r32771 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); 58 60 59 61 # define MODECASE(caseName, func) \ … … 103 105 MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode); 104 106 MODECASE(PSTAMPTOOL_MODE_GETWEBREQUESTNUM, getwebrequestnumMode); 107 MODECASE(PSTAMPTOOL_MODE_ADDFILE, addfileMode); 108 MODECASE(PSTAMPTOOL_MODE_LISTFILE, listfileMode); 105 109 default: 106 110 psAbort("invalid option (this should not happen)"); … … 1476 1480 return true; 1477 1481 } 1482 1483 static bool addfileMode(pxConfig *config) 1484 { 1485 PS_ASSERT_PTR_NON_NULL(config, false); 1486 1487 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 1488 PXOPT_LOOKUP_STR(path, config->args, "-path", true, false); 1489 1490 if (!pstampFileInsert(config->dbh, 1491 0, // file_id 1492 job_id, 1493 path 1494 )) { 1495 psError(PS_ERR_UNKNOWN, false, "database error"); 1496 return false; 1497 } 1498 1499 psU64 affected = psDBAffectedRows(config->dbh); 1500 if (affected != 1) { 1501 psError(PS_ERR_UNKNOWN, false, 1502 "should have affected one row but %" PRIu64 " rows were modified", 1503 affected); 1504 return false; 1505 } 1506 1507 psS64 file_id = psDBLastInsertID(config->dbh); 1508 printf("%" PRId64 "\n", file_id); 1509 1510 return true; 1511 } 1512 1513 static bool listfileMode(pxConfig *config) 1514 { 1515 PS_ASSERT_PTR_NON_NULL(config, false); 1516 1517 psMetadata *where = psMetadataAlloc(); 1518 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 1519 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 1520 PXOPT_COPY_S64(config->args, where, "-file_id", "file_id", "=="); 1521 1522 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1523 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1524 1525 if (!psListLength(where->list)) { 1526 fprintf(stderr, "search arguments are required\n"); 1527 exit (1); 1528 } 1529 1530 psString query = pxDataGet("pstamptool_listfile.sql"); 1531 if (!query) { 1532 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1533 return false; 1534 } 1535 1536 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 1537 if (psListLength(where->list)) { 1538 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1539 psStringAppend(&query, " WHERE %s", whereClause); 1540 psFree(whereClause); 1541 } 1542 psFree(where); 1543 1544 // treat limit == 0 as "no limit" 1545 if (limit) { 1546 psString limitString = psDBGenerateLimitSQL(limit); 1547 psStringAppend(&query, " %s", limitString); 1548 psFree(limitString); 1549 } 1550 1551 if (!p_psDBRunQuery(config->dbh, query)) { 1552 psError(PS_ERR_UNKNOWN, false, "database error"); 1553 psFree(query); 1554 return false; 1555 } 1556 psFree(query); 1557 1558 psArray *output = p_psDBFetchResult(config->dbh); 1559 if (!output) { 1560 psError(PS_ERR_UNKNOWN, false, "database error"); 1561 return false; 1562 } 1563 if (!psArrayLength(output)) { 1564 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 1565 psFree(output); 1566 return true; 1567 } 1568 1569 // negative simple so the default is true 1570 if (!ippdbPrintMetadatas(stdout, output, "pstampFile", !simple)) { 1571 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1572 psFree(output); 1573 return false; 1574 } 1575 1576 psFree(output); 1577 1578 return true; 1579 } 1580
Note:
See TracChangeset
for help on using the changeset viewer.
