- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (2 props)
-
ippTools/src/pstamptool.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippTools/src
- Property svn:ignore
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20110710/ippTools/src (added) merged: 32337 /branches/eam_branches/ipp-20110906/ippTools/src (added) merged: 32630 /branches/eam_branches/ipp-20111110/ippTools/src (added) merged: 32694 /branches/haf_add201112/ippTools/src (added) merged: 32980,32986,33003,33023,33027
-
branches/meh_branches/ppstack_test/ippTools/src/pstamptool.c
r31517 r33415 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)"); … … 173 179 174 180 if (psListLength(where->list)) { 175 psString whereClause = psDBGenerateWhere SQL(where, NULL);176 psStringAppend(&query, " %s", whereClause);181 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 182 psStringAppend(&query, " AND %s", whereClause); 177 183 psFree(whereClause); 178 184 } … … 698 704 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 699 705 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 700 PXOPT_LOOKUP_S64(options, config->args, "-options", false, false);706 PXOPT_LOOKUP_S64(options, config->args, "-options", false, false); 701 707 PXOPT_LOOKUP_S64(dep_id, config->args, "-dep_id", false, false); 708 PXOPT_LOOKUP_S64(parent_id, config->args, "-parent_id", false, false); 709 PXOPT_LOOKUP_BOOL(is_parent, config->args, "-is_parent", false); 702 710 703 711 // unless the job is being inserted with stop state require outputBase … … 710 718 if (!strcmp(job_type, "get_image") || !strcmp(job_type, "detect_query") || !strcmp(job_type, "none")) { 711 719 stampJob = false; 720 } else if (!strcmp(job_type, "child")) { 721 // job_type child's only action is to resolve a dependent 722 // XXX: IS this necessary? 723 if (!dep_id) { 724 psError(PS_ERR_UNKNOWN, true, "dep_id required for child job\n"); 725 return false; 726 } 727 if (is_parent) { 728 psError(PS_ERR_UNKNOWN, true, "job type child can not be a parent job\n"); 729 return false; 730 } 731 stampJob = false; 732 } else if (!strcmp(job_type, "mosaic")) { 733 stampJob = false; 734 is_parent = true; 712 735 } else if (!strcmp(job_type, "stamp")) { 713 736 stampJob = true; … … 717 740 } 718 741 if (!pstampJobInsert(config->dbh, 719 0, // job_id742 0, // job_id 720 743 req_id, 721 744 rownum, … … 727 750 options, 728 751 dep_id, 729 0 // fault_count 752 0, // fault_count 753 parent_id, 754 is_parent 730 755 )) { 731 756 psError(PS_ERR_UNKNOWN, false, "database error"); … … 755 780 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 756 781 PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "=="); 782 PXOPT_COPY_STR(config->args, where, "-jobType", "jobType", "=="); 757 783 PXOPT_COPY_S64(config->args, where, "-fault", "fault", "=="); 758 784 … … 836 862 837 863 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 864 psString whereStr = NULL; 838 865 if (psListLength(where->list)) { 839 866 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 840 psStringAppend(& query, "AND %s", whereClause);867 psStringAppend(&whereStr, "\n AND %s", whereClause); 841 868 psFree(whereClause); 869 } else { 870 psStringAppend(&whereStr, "%s", ""); 842 871 } 843 872 psFree(where); … … 852 881 } 853 882 854 if (!p_psDBRunQuery(config->dbh, query)) { 855 psError(PS_ERR_UNKNOWN, false, "database error"); 856 psFree(query); 857 return false; 858 } 883 if (!p_psDBRunQueryF(config->dbh, query, whereStr, whereStr)) { 884 psError(PS_ERR_UNKNOWN, false, "database error"); 885 psFree(whereStr); 886 psFree(query); 887 return false; 888 } 889 psFree(whereStr); 859 890 psFree(query); 860 891 … … 950 981 951 982 PXOPT_LOOKUP_S32(fault, config->args, "-set_fault", true, false); 983 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 952 984 953 985 psMetadata *where = psMetadataAlloc(); … … 980 1012 psFree(where); 981 1013 982 if (!p_psDBRunQueryF(config->dbh, query, fault, fault )) {1014 if (!p_psDBRunQueryF(config->dbh, query, fault, fault, state)) { 983 1015 psError(PS_ERR_UNKNOWN, false, "database error"); 984 1016 psFree(query); … … 1476 1508 return true; 1477 1509 } 1510 1511 static bool addfileMode(pxConfig *config) 1512 { 1513 PS_ASSERT_PTR_NON_NULL(config, false); 1514 1515 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 1516 PXOPT_LOOKUP_STR(path, config->args, "-path", true, false); 1517 1518 if (!pstampFileInsert(config->dbh, 1519 0, // file_id 1520 job_id, 1521 path 1522 )) { 1523 psError(PS_ERR_UNKNOWN, false, "database error"); 1524 return false; 1525 } 1526 1527 psU64 affected = psDBAffectedRows(config->dbh); 1528 if (affected != 1) { 1529 psError(PS_ERR_UNKNOWN, false, 1530 "should have affected one row but %" PRIu64 " rows were modified", 1531 affected); 1532 return false; 1533 } 1534 1535 psS64 file_id = psDBLastInsertID(config->dbh); 1536 printf("%" PRId64 "\n", file_id); 1537 1538 return true; 1539 } 1540 1541 static bool listfileMode(pxConfig *config) 1542 { 1543 PS_ASSERT_PTR_NON_NULL(config, false); 1544 1545 psMetadata *where = psMetadataAlloc(); 1546 PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "=="); 1547 PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "=="); 1548 PXOPT_COPY_S64(config->args, where, "-file_id", "file_id", "=="); 1549 1550 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1551 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1552 1553 if (!psListLength(where->list)) { 1554 fprintf(stderr, "search arguments are required\n"); 1555 exit (1); 1556 } 1557 1558 psString query = pxDataGet("pstamptool_listfile.sql"); 1559 if (!query) { 1560 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1561 return false; 1562 } 1563 1564 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 1565 if (psListLength(where->list)) { 1566 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1567 psStringAppend(&query, " WHERE %s", whereClause); 1568 psFree(whereClause); 1569 } 1570 psFree(where); 1571 1572 // treat limit == 0 as "no limit" 1573 if (limit) { 1574 psString limitString = psDBGenerateLimitSQL(limit); 1575 psStringAppend(&query, " %s", limitString); 1576 psFree(limitString); 1577 } 1578 1579 if (!p_psDBRunQuery(config->dbh, query)) { 1580 psError(PS_ERR_UNKNOWN, false, "database error"); 1581 psFree(query); 1582 return false; 1583 } 1584 psFree(query); 1585 1586 psArray *output = p_psDBFetchResult(config->dbh); 1587 if (!output) { 1588 psError(PS_ERR_UNKNOWN, false, "database error"); 1589 return false; 1590 } 1591 if (!psArrayLength(output)) { 1592 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 1593 psFree(output); 1594 return true; 1595 } 1596 1597 // negative simple so the default is true 1598 if (!ippdbPrintMetadatas(stdout, output, "pstampFile", !simple)) { 1599 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1600 psFree(output); 1601 return false; 1602 } 1603 1604 psFree(output); 1605 1606 return true; 1607 } 1608 1609 static bool deletefileMode(pxConfig *config) 1610 { 1611 PS_ASSERT_PTR_NON_NULL(config, false); 1612 1613 PXOPT_LOOKUP_S64(job_id, config->args, "-job_id", true, false); 1614 1615 psString query = NULL; 1616 psStringAppend(&query, "DELETE FROM pstampFile WHERE job_id = %" PRId64, job_id); 1617 1618 if (!p_psDBRunQuery(config->dbh, query)) { 1619 psError(PS_ERR_UNKNOWN, false, "database error"); 1620 psFree(query); 1621 return false; 1622 } 1623 psFree(query); 1624 1625 psU64 affected = psDBAffectedRows(config->dbh); 1626 psLogMsg("pstamptool", PS_LOG_INFO, "Deleted %" PRIu64 " rows from pstampFile", affected); 1627 1628 return true; 1629 }
Note:
See TracChangeset
for help on using the changeset viewer.
