Changeset 23310 for trunk/ippTools/src/warptool.c
- Timestamp:
- Mar 12, 2009, 3:42:47 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/warptool.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/warptool.c
r23251 r23310 54 54 static bool tofullskyfileMode(pxConfig *config); 55 55 static bool updateskyfileMode(pxConfig *config); 56 57 static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state); 56 static bool exportrunMode(pxConfig *config); 57 static bool importrunMode(pxConfig *config); 58 58 59 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile); 59 60 static bool isValidMode(pxConfig *config, const char *mode); … … 100 101 MODECASE(WARPTOOL_MODE_TOFULLSKYFILE, tofullskyfileMode); 101 102 MODECASE(WARPTOOL_MODE_UPDATESKYFILE, updateskyfileMode); 103 MODECASE(WARPTOOL_MODE_EXPORTRUN, exportrunMode); 104 MODECASE(WARPTOOL_MODE_IMPORTRUN, importrunMode); 102 105 103 106 default: … … 1271 1274 1272 1275 if (numUpdated < 1) { 1273 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row");1276 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 1274 1277 if (!psDBRollback(config->dbh)) { 1275 1278 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1605 1608 // shared code for the modes -tocleanedskyfile -tofullskyfile -topurgedskyfile 1606 1609 1607 // XXX EAM : this function was enforcing only certain transitions with the SQL. However,1608 // this is getting fairly messy now that we have added a few additional target and1609 // destination states. I'm disabling these restrictions for now; is there are better way1610 // to enforce the allowed state transitions?1611 1612 1610 static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state) 1613 1611 { … … 1625 1623 } 1626 1624 1627 // XXX this feature is disabled (run_state is ignored)1628 1625 // note only updates if warpRun.state = run_state 1629 1630 if (!p_psDBRunQueryF(config->dbh, query, data_state, warp_id, skycell_id)) { 1626 if (!p_psDBRunQueryF(config->dbh, query, data_state, warp_id, skycell_id, run_state)) { 1631 1627 psError(PS_ERR_UNKNOWN, false, "database error"); 1632 1628 // rollback … … 1676 1672 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false); 1677 1673 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 1678 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);1679 1674 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 1680 1675 1681 if (state && code) { 1682 psError(PS_ERR_UNKNOWN, true, "only one of -set_state and -code may be supplied"); 1683 return false; 1684 } 1685 1686 if (state) { 1687 // make sure that the state string is valid 1688 if (!pxIsValidState(state)) { 1689 psError(PXTOOLS_ERR_DATA, false, "%s is not a valid state", state); 1690 return false; 1676 psString query = pxDataGet("warptool_updateskyfile.sql"); 1677 1678 if (!p_psDBRunQueryF(config->dbh, query, code, warp_id, skycell_id)) { 1679 psError(PS_ERR_UNKNOWN, false, "database error"); 1680 return false; 1681 } 1682 psFree(query); 1683 1684 return true; 1685 } 1686 1687 bool exportrunMode(pxConfig *config) 1688 { 1689 typedef struct ExportTable { 1690 char tableName[80]; 1691 char sqlFilename[80]; 1692 } ExportTable; 1693 1694 PS_ASSERT_PTR_NON_NULL(config, NULL); 1695 1696 PXOPT_LOOKUP_S64(det_id, config->args, "-warp_id", true, false); 1697 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false); 1698 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1699 1700 FILE *f = fopen (outfile, "w"); 1701 if (f == NULL) { 1702 psError(PS_ERR_UNKNOWN, false, "failed to open output file"); 1703 return false; 1704 } 1705 1706 psMetadata *where = psMetadataAlloc(); 1707 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 1708 1709 ExportTable tables [] = { 1710 {"warpRun", "warptool_export_run.sql"}, 1711 {"warpImfile", "warptool_export_imfile.sql"}, 1712 {"warpSkyfile", "warptool_export_skyfile.sql"}, 1713 {"warpSkyCellMap", "warptool_export_sky_cell_map.sql"}, 1714 }; 1715 1716 1717 for (int i=0; i < sizeof(tables); i++) { 1718 psString query = pxDataGet(tables[i].sqlFilename); 1719 if (!query) { 1720 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1721 return false; 1691 1722 } 1692 if (!change_skyfile_data_state(config, state, "unknown")) { 1693 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1694 return false; 1723 1724 if (where && psListLength(where->list)) { 1725 psString whereClause = psDBGenerateWhereSQL(where, NULL); 1726 psStringAppend(&query, " %s", whereClause); 1727 psFree(whereClause); 1695 1728 } 1696 return true; 1697 } 1698 1699 if (code) { 1700 psString query = pxDataGet("warptool_updateskyfile.sql"); 1701 1702 if (!p_psDBRunQueryF(config->dbh, query, code, warp_id, skycell_id)) { 1703 psError(PS_ERR_UNKNOWN, false, "database error"); 1729 1730 // treat limit == 0 as "no limit" 1731 if (limit) { 1732 psString limitString = psDBGenerateLimitSQL(limit); 1733 psStringAppend(&query, " %s", limitString); 1734 psFree(limitString); 1735 } 1736 1737 if (!p_psDBRunQuery(config->dbh, query)) { 1738 psError(PS_ERR_UNKNOWN, false, "database error"); 1739 psFree(query); 1704 1740 return false; 1705 1741 } 1706 1742 psFree(query); 1707 return true; 1708 } 1709 1710 psError(PS_ERR_UNKNOWN, true, "one of -set_state or -code must be supplied"); 1711 return false; 1712 } 1743 1744 psArray *output = p_psDBFetchResult(config->dbh); 1745 if (!output) { 1746 psError(PS_ERR_UNKNOWN, false, "database error"); 1747 return false; 1748 } 1749 if (!psArrayLength(output)) { 1750 psTrace("regtool", PS_LOG_INFO, "no rows found"); 1751 psFree(output); 1752 return true; 1753 } 1754 1755 // we must write the export table in non-simple (true) format 1756 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) { 1757 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1758 psFree(output); 1759 return false; 1760 } 1761 psFree(output); 1762 } 1763 1764 fclose (f); 1765 1766 return true; 1767 } 1768 1769 bool importrunMode(pxConfig *config) 1770 { 1771 unsigned int nFail; 1772 1773 int numImportTables = 3; 1774 1775 char tables[3] [80] = {"warpImfile", "warpSkyfile", "warpSkyCellMap"}; 1776 1777 PS_ASSERT_PTR_NON_NULL(config, NULL); 1778 1779 PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false); 1780 1781 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false); 1782 1783 fprintf (stdout, "---- input ----\n"); 1784 psMetadataPrint (stderr, input, 1); 1785 1786 psMetadataItem *item = psMetadataLookup (input, "warpRun"); 1787 psAssert (item, "entry not in input?"); 1788 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 1789 1790 psMetadataItem *entry = psListGet (item->data.list, 0); 1791 assert (entry); 1792 assert (entry->type == PS_DATA_METADATA); 1793 warpRunRow *warpRun = warpRunObjectFromMetadata (entry->data.md); 1794 warpRunInsertObject (config->dbh, warpRun); 1795 1796 // fprintf (stdout, "---- warp run ----\n"); 1797 // psMetadataPrint (stderr, entry->data.md, 1); 1798 1799 for (int i = 0; i < numImportTables; i++) { 1800 item = psMetadataLookup (input, tables[i]); 1801 psAssert (item, "entry not in input?"); 1802 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 1803 1804 switch (i) { 1805 case 0: 1806 for (int i = 0; i < item->data.list->n; i++) { 1807 entry = psListGet (item->data.list, i); 1808 assert (entry); 1809 assert (entry->type == PS_DATA_METADATA); 1810 warpImfileRow *warpImfile = warpImfileObjectFromMetadata (entry->data.md); 1811 warpImfileInsertObject (config->dbh, warpImfile); 1812 1813 // fprintf (stdout, "---- row %d ----\n", i); 1814 // psMetadataPrint (stderr, entry->data.md, 1); 1815 } 1816 break; 1817 1818 case 1: 1819 for (int i = 0; i < item->data.list->n; i++) { 1820 entry = psListGet (item->data.list, i); 1821 assert (entry); 1822 assert (entry->type == PS_DATA_METADATA); 1823 warpSkyfileRow *warpSkyfile = warpSkyfileObjectFromMetadata (entry->data.md); 1824 warpSkyfileInsertObject (config->dbh, warpSkyfile); 1825 1826 // fprintf (stdout, "---- row %d ----\n", i); 1827 // psMetadataPrint (stderr, entry->data.md, 1); 1828 } 1829 break; 1830 1831 case 2: 1832 for (int i = 0; i < item->data.list->n; i++) { 1833 entry = psListGet (item->data.list, i); 1834 assert (entry); 1835 assert (entry->type == PS_DATA_METADATA); 1836 warpSkyCellMapRow *warpSkyCellMap = warpSkyCellMapObjectFromMetadata (entry->data.md); 1837 warpSkyCellMapInsertObject (config->dbh, warpSkyCellMap); 1838 1839 // fprintf (stdout, "---- row %d ----\n", i); 1840 // psMetadataPrint (stderr, entry->data.md, 1); 1841 } 1842 break; 1843 } 1844 } 1845 return true; 1846 }
Note:
See TracChangeset
for help on using the changeset viewer.
