Changeset 15576
- Timestamp:
- Nov 9, 2007, 5:14:16 PM (19 years ago)
- Location:
- trunk/ippdb
- Files:
-
- 14 edited
-
Makefile.am (modified) (1 diff)
-
src/ippdb.c (modified) (2 diffs)
-
src/ippdb.h (modified) (2 diffs)
-
tests/alloc.c (modified) (1 diff)
-
tests/createtable.c (modified) (1 diff)
-
tests/dbcleanup.c (modified) (1 diff)
-
tests/dbsetup.c (modified) (1 diff)
-
tests/droptable.c (modified) (1 diff)
-
tests/insert.c (modified) (1 diff)
-
tests/insertfits.c (modified) (1 diff)
-
tests/insertobject.c (modified) (1 diff)
-
tests/metadatafromobject.c (modified) (1 diff)
-
tests/objectfrommetadata.c (modified) (1 diff)
-
tests/selectrowsfits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/Makefile.am
r15569 r15576 59 59 $(top_builddir)/docs/man/man3/magicSkyfileMaskRow.3 \ 60 60 $(top_builddir)/docs/man/man3/calDBRow.3 \ 61 $(top_builddir)/docs/man/man3/calRunRow.3 61 $(top_builddir)/docs/man/man3/calRunRow.3 \ 62 $(top_builddir)/docs/man/man3/flatcorrRunRow.3 \ 63 $(top_builddir)/docs/man/man3/flatcorrExpRow.3 62 64 63 65 64 docs/man/man3/ippdb.3 docs/man/man3/pzDataStoreRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/guidePendingExpRow.3 docs/man/man3/chipRunRow.3 docs/man/man3/chipProcessedImfileRow.3 docs/man/man3/chipMaskRow.3 docs/man/man3/camRunRow.3 docs/man/man3/camProcessedExpRow.3 docs/man/man3/camMaskRow.3 docs/man/man3/warpRunRow.3 docs/man/man3/warpInputExpRow.3 docs/man/man3/warpSkyCellMapRow.3 docs/man/man3/warpSkyfileRow.3 docs/man/man3/diffRunRow.3 docs/man/man3/diffInputSkyfileRow.3 docs/man/man3/diffSkyfileRow.3 docs/man/man3/stackRunRow.3 docs/man/man3/stackInputSkyfileRow.3 docs/man/man3/stackSumSkyfileRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/detRegisteredImfileRow.3 docs/man/man3/detCorrectedExpRow.3 docs/man/man3/detCorrectedImfileRow.3 docs/man/man3/magicRunRow.3 docs/man/man3/magicInputSkyfileRow.3 docs/man/man3/magicTreeRow.3 docs/man/man3/magicNodeResultRow.3 docs/man/man3/magicMaskRow.3 docs/man/man3/magicSkyfileMaskRow.3 docs/man/man3/calDBRow.3 docs/man/man3/calRunRow.3 :66 docs/man/man3/ippdb.3 docs/man/man3/pzDataStoreRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/guidePendingExpRow.3 docs/man/man3/chipRunRow.3 docs/man/man3/chipProcessedImfileRow.3 docs/man/man3/chipMaskRow.3 docs/man/man3/camRunRow.3 docs/man/man3/camProcessedExpRow.3 docs/man/man3/camMaskRow.3 docs/man/man3/warpRunRow.3 docs/man/man3/warpInputExpRow.3 docs/man/man3/warpSkyCellMapRow.3 docs/man/man3/warpSkyfileRow.3 docs/man/man3/diffRunRow.3 docs/man/man3/diffInputSkyfileRow.3 docs/man/man3/diffSkyfileRow.3 docs/man/man3/stackRunRow.3 docs/man/man3/stackInputSkyfileRow.3 docs/man/man3/stackSumSkyfileRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/detRegisteredImfileRow.3 docs/man/man3/detCorrectedExpRow.3 docs/man/man3/detCorrectedImfileRow.3 docs/man/man3/magicRunRow.3 docs/man/man3/magicInputSkyfileRow.3 docs/man/man3/magicTreeRow.3 docs/man/man3/magicNodeResultRow.3 docs/man/man3/magicMaskRow.3 docs/man/man3/magicSkyfileMaskRow.3 docs/man/man3/calDBRow.3 docs/man/man3/calRunRow.3 docs/man/man3/flatcorrRunRow.3 docs/man/man3/flatcorrExpRow.3: 65 67 $(DOXYGEN) 66 68 -
trunk/ippdb/src/ippdb.c
r15569 r15576 81 81 #define CALDB_TABLE_NAME "calDB" 82 82 #define CALRUN_TABLE_NAME "calRun" 83 #define FLATCORRRUN_TABLE_NAME "flatcorrRun" 84 #define FLATCORREXP_TABLE_NAME "flatcorrExp" 83 85 #define MAX_STRING_LENGTH 1024 84 86 … … 22700 22702 return true; 22701 22703 } 22704 static void flatcorrRunRowFree(flatcorrRunRow *object); 22705 22706 flatcorrRunRow *flatcorrRunRowAlloc(psS64 corr_id, const char *dvodb, const char *state, const char *workdir, const char *label) 22707 { 22708 flatcorrRunRow *_object; 22709 22710 _object = psAlloc(sizeof(flatcorrRunRow)); 22711 psMemSetDeallocator(_object, (psFreeFunc)flatcorrRunRowFree); 22712 22713 _object->corr_id = corr_id; 22714 _object->dvodb = psStringCopy(dvodb); 22715 _object->state = psStringCopy(state); 22716 _object->workdir = psStringCopy(workdir); 22717 _object->label = psStringCopy(label); 22718 22719 return _object; 22720 } 22721 22722 static void flatcorrRunRowFree(flatcorrRunRow *object) 22723 { 22724 psFree(object->dvodb); 22725 psFree(object->state); 22726 psFree(object->workdir); 22727 psFree(object->label); 22728 } 22729 22730 bool flatcorrRunCreateTable(psDB *dbh) 22731 { 22732 psMetadata *md = psMetadataAlloc(); 22733 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) { 22734 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 22735 psFree(md); 22736 return false; 22737 } 22738 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "64")) { 22739 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 22740 psFree(md); 22741 return false; 22742 } 22743 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, "64")) { 22744 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 22745 psFree(md); 22746 return false; 22747 } 22748 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 22749 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 22750 psFree(md); 22751 return false; 22752 } 22753 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, "64")) { 22754 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 22755 psFree(md); 22756 return false; 22757 } 22758 22759 bool status = psDBCreateTable(dbh, FLATCORRRUN_TABLE_NAME, md); 22760 22761 psFree(md); 22762 22763 return status; 22764 } 22765 22766 bool flatcorrRunDropTable(psDB *dbh) 22767 { 22768 return psDBDropTable(dbh, FLATCORRRUN_TABLE_NAME); 22769 } 22770 22771 bool flatcorrRunInsert(psDB * dbh, psS64 corr_id, const char *dvodb, const char *state, const char *workdir, const char *label) 22772 { 22773 psMetadata *md = psMetadataAlloc(); 22774 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, NULL, corr_id)) { 22775 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 22776 psFree(md); 22777 return false; 22778 } 22779 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) { 22780 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 22781 psFree(md); 22782 return false; 22783 } 22784 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 22785 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 22786 psFree(md); 22787 return false; 22788 } 22789 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 22790 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 22791 psFree(md); 22792 return false; 22793 } 22794 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, label)) { 22795 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 22796 psFree(md); 22797 return false; 22798 } 22799 22800 bool status = psDBInsertOneRow(dbh, FLATCORRRUN_TABLE_NAME, md); 22801 psFree(md); 22802 22803 return status; 22804 } 22805 22806 long long flatcorrRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 22807 { 22808 long long deleted = 0; 22809 22810 long long count = psDBDeleteRows(dbh, FLATCORRRUN_TABLE_NAME, where, limit); 22811 if (count < 0) { 22812 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrRun"); 22813 return count; 22814 22815 deleted += count; 22816 } 22817 22818 return deleted; 22819 } 22820 bool flatcorrRunInsertObject(psDB *dbh, flatcorrRunRow *object) 22821 { 22822 return flatcorrRunInsert(dbh, object->corr_id, object->dvodb, object->state, object->workdir, object->label); 22823 } 22824 22825 bool flatcorrRunInsertObjects(psDB *dbh, psArray *objects) 22826 { 22827 for (long i = 0; i < psArrayLength(objects); i++) { 22828 if (!flatcorrRunInsertObject(dbh, objects->data[i])) { 22829 return false; 22830 } 22831 } 22832 22833 return true; 22834 } 22835 22836 bool flatcorrRunInsertFits(psDB *dbh, const psFits *fits) 22837 { 22838 psArray *rowSet; 22839 22840 // move to (the first?) extension named FLATCORRRUN_TABLE_NAME 22841 if (!psFitsMoveExtName(fits, FLATCORRRUN_TABLE_NAME)) { 22842 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", FLATCORRRUN_TABLE_NAME); 22843 return false; 22844 } 22845 22846 // check HDU type 22847 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 22848 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 22849 return false; 22850 } 22851 22852 // read fits table 22853 rowSet = psFitsReadTable(fits); 22854 if (!rowSet) { 22855 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 22856 psFree(rowSet); 22857 return false; 22858 } 22859 22860 if (!psDBInsertRows(dbh, FLATCORRRUN_TABLE_NAME, rowSet)) { 22861 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 22862 psFree(rowSet); 22863 return false; 22864 } 22865 22866 psFree(rowSet); 22867 22868 return true; 22869 } 22870 22871 bool flatcorrRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 22872 { 22873 psArray *rowSet; 22874 22875 rowSet = psDBSelectRows(dbh, FLATCORRRUN_TABLE_NAME, where, limit); 22876 if (!rowSet) { 22877 return false; 22878 } 22879 22880 // output to fits 22881 if (!psFitsWriteTable(fits, NULL, rowSet, FLATCORRRUN_TABLE_NAME)) { 22882 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 22883 psFree(rowSet); 22884 return false; 22885 } 22886 22887 psFree(rowSet); 22888 22889 return true; 22890 } 22891 22892 psMetadata *flatcorrRunMetadataFromObject(const flatcorrRunRow *object) 22893 { 22894 psMetadata *md = psMetadataAlloc(); 22895 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, NULL, object->corr_id)) { 22896 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 22897 psFree(md); 22898 return false; 22899 } 22900 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) { 22901 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 22902 psFree(md); 22903 return false; 22904 } 22905 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 22906 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 22907 psFree(md); 22908 return false; 22909 } 22910 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 22911 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 22912 psFree(md); 22913 return false; 22914 } 22915 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, object->label)) { 22916 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 22917 psFree(md); 22918 return false; 22919 } 22920 22921 22922 return md; 22923 } 22924 22925 flatcorrRunRow *flatcorrRunObjectFromMetadata(psMetadata *md) 22926 { 22927 22928 bool status = false; 22929 psS64 corr_id = psMetadataLookupS64(&status, md, "corr_id"); 22930 if (!status) { 22931 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item corr_id"); 22932 return false; 22933 } 22934 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb"); 22935 if (!status) { 22936 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb"); 22937 return false; 22938 } 22939 char* state = psMetadataLookupPtr(&status, md, "state"); 22940 if (!status) { 22941 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 22942 return false; 22943 } 22944 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 22945 if (!status) { 22946 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 22947 return false; 22948 } 22949 char* label = psMetadataLookupPtr(&status, md, "label"); 22950 if (!status) { 22951 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item label"); 22952 return false; 22953 } 22954 22955 return flatcorrRunRowAlloc(corr_id, dvodb, state, workdir, label); 22956 } 22957 psArray *flatcorrRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 22958 { 22959 psArray *rowSet; 22960 psArray *returnSet; 22961 psU64 i; 22962 22963 rowSet = psDBSelectRows(dbh, FLATCORRRUN_TABLE_NAME, where, limit); 22964 if (!rowSet) { 22965 return NULL; 22966 } 22967 22968 // convert psMetadata rows to row objects 22969 22970 returnSet = psArrayAllocEmpty(rowSet->n); 22971 22972 for (i = 0; i < rowSet->n; i++) { 22973 flatcorrRunRow *object = flatcorrRunObjectFromMetadata(rowSet->data[i]); 22974 psArrayAdd(returnSet, 0, object); 22975 psFree(object); 22976 } 22977 22978 psFree(rowSet); 22979 22980 return returnSet; 22981 } 22982 bool flatcorrRunDeleteObject(psDB *dbh, const flatcorrRunRow *object) 22983 { 22984 psMetadata *where = flatcorrRunMetadataFromObject(object); 22985 long long count = psDBDeleteRows(dbh, FLATCORRRUN_TABLE_NAME, where, 0); 22986 psFree(where); 22987 if (count < 0) { 22988 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrRun"); 22989 return false; 22990 } 22991 if (count > 1) { 22992 // XXX should this be a psAbort() instead? It is possible that 22993 // having an object match multiple rows was by design. 22994 psError(PS_ERR_UNKNOWN, true, "flatcorrRunRow object matched more then one row. Check your database schema"); 22995 return false; 22996 } 22997 22998 return true; 22999 } 23000 long long flatcorrRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 23001 { 23002 long long deleted = 0; 23003 23004 for (long long i = 0; i < objects->n; i++) { 23005 flatcorrRunRow *object = objects->data[i]; 23006 psMetadata *where = flatcorrRunMetadataFromObject(object); 23007 long long count = psDBDeleteRows(dbh, FLATCORRRUN_TABLE_NAME, where, limit); 23008 psFree(where); 23009 if (count < 0) { 23010 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrRun"); 23011 return count; 23012 } 23013 23014 deleted += count; 23015 } 23016 23017 return deleted; 23018 } 23019 bool flatcorrRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 23020 { 23021 PS_ASSERT_PTR_NON_NULL(objects, false); 23022 23023 psMetadata *output = psMetadataAlloc(); 23024 for (long i = 0; i < psArrayLength(objects); i++) { 23025 psMetadata *md = flatcorrRunMetadataFromObject(objects->data[i]); 23026 if (!psMetadataAddMetadata( 23027 output, 23028 PS_LIST_TAIL, 23029 FLATCORRRUN_TABLE_NAME, 23030 PS_META_DUPLICATE_OK, 23031 NULL, 23032 md 23033 )) { 23034 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 23035 psFree(md); 23036 psFree(output); 23037 return false; 23038 } 23039 psFree(md); 23040 } 23041 23042 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 23043 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 23044 psFree(output); 23045 } 23046 psFree(output); 23047 23048 return true; 23049 } 23050 bool flatcorrRunPrintObject(FILE *stream, flatcorrRunRow *object, bool mdcf) 23051 { 23052 PS_ASSERT_PTR_NON_NULL(object, false); 23053 23054 psMetadata *md = flatcorrRunMetadataFromObject(object); 23055 23056 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 23057 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 23058 psFree(md); 23059 } 23060 23061 psFree(md); 23062 23063 return true; 23064 } 23065 static void flatcorrExpRowFree(flatcorrExpRow *object); 23066 23067 flatcorrExpRow *flatcorrExpRowAlloc(psS64 corr_id, psS64 chip_id, const char *state) 23068 { 23069 flatcorrExpRow *_object; 23070 23071 _object = psAlloc(sizeof(flatcorrExpRow)); 23072 psMemSetDeallocator(_object, (psFreeFunc)flatcorrExpRowFree); 23073 23074 _object->corr_id = corr_id; 23075 _object->chip_id = chip_id; 23076 _object->state = psStringCopy(state); 23077 23078 return _object; 23079 } 23080 23081 static void flatcorrExpRowFree(flatcorrExpRow *object) 23082 { 23083 psFree(object->state); 23084 } 23085 23086 bool flatcorrExpCreateTable(psDB *dbh) 23087 { 23088 psMetadata *md = psMetadataAlloc(); 23089 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, "Primary Key", 0)) { 23090 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 23091 psFree(md); 23092 return false; 23093 } 23094 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key", 64)) { 23095 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 23096 psFree(md); 23097 return false; 23098 } 23099 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "fkey(corr_id) ref flatcorrRun(corr_id)", "64")) { 23100 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 23101 psFree(md); 23102 return false; 23103 } 23104 23105 bool status = psDBCreateTable(dbh, FLATCORREXP_TABLE_NAME, md); 23106 23107 psFree(md); 23108 23109 return status; 23110 } 23111 23112 bool flatcorrExpDropTable(psDB *dbh) 23113 { 23114 return psDBDropTable(dbh, FLATCORREXP_TABLE_NAME); 23115 } 23116 23117 bool flatcorrExpInsert(psDB * dbh, psS64 corr_id, psS64 chip_id, const char *state) 23118 { 23119 psMetadata *md = psMetadataAlloc(); 23120 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, NULL, corr_id)) { 23121 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 23122 psFree(md); 23123 return false; 23124 } 23125 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, NULL, chip_id)) { 23126 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 23127 psFree(md); 23128 return false; 23129 } 23130 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 23131 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 23132 psFree(md); 23133 return false; 23134 } 23135 23136 bool status = psDBInsertOneRow(dbh, FLATCORREXP_TABLE_NAME, md); 23137 psFree(md); 23138 23139 return status; 23140 } 23141 23142 long long flatcorrExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 23143 { 23144 long long deleted = 0; 23145 23146 long long count = psDBDeleteRows(dbh, FLATCORREXP_TABLE_NAME, where, limit); 23147 if (count < 0) { 23148 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrExp"); 23149 return count; 23150 23151 deleted += count; 23152 } 23153 23154 return deleted; 23155 } 23156 bool flatcorrExpInsertObject(psDB *dbh, flatcorrExpRow *object) 23157 { 23158 return flatcorrExpInsert(dbh, object->corr_id, object->chip_id, object->state); 23159 } 23160 23161 bool flatcorrExpInsertObjects(psDB *dbh, psArray *objects) 23162 { 23163 for (long i = 0; i < psArrayLength(objects); i++) { 23164 if (!flatcorrExpInsertObject(dbh, objects->data[i])) { 23165 return false; 23166 } 23167 } 23168 23169 return true; 23170 } 23171 23172 bool flatcorrExpInsertFits(psDB *dbh, const psFits *fits) 23173 { 23174 psArray *rowSet; 23175 23176 // move to (the first?) extension named FLATCORREXP_TABLE_NAME 23177 if (!psFitsMoveExtName(fits, FLATCORREXP_TABLE_NAME)) { 23178 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", FLATCORREXP_TABLE_NAME); 23179 return false; 23180 } 23181 23182 // check HDU type 23183 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 23184 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 23185 return false; 23186 } 23187 23188 // read fits table 23189 rowSet = psFitsReadTable(fits); 23190 if (!rowSet) { 23191 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 23192 psFree(rowSet); 23193 return false; 23194 } 23195 23196 if (!psDBInsertRows(dbh, FLATCORREXP_TABLE_NAME, rowSet)) { 23197 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 23198 psFree(rowSet); 23199 return false; 23200 } 23201 23202 psFree(rowSet); 23203 23204 return true; 23205 } 23206 23207 bool flatcorrExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 23208 { 23209 psArray *rowSet; 23210 23211 rowSet = psDBSelectRows(dbh, FLATCORREXP_TABLE_NAME, where, limit); 23212 if (!rowSet) { 23213 return false; 23214 } 23215 23216 // output to fits 23217 if (!psFitsWriteTable(fits, NULL, rowSet, FLATCORREXP_TABLE_NAME)) { 23218 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 23219 psFree(rowSet); 23220 return false; 23221 } 23222 23223 psFree(rowSet); 23224 23225 return true; 23226 } 23227 23228 psMetadata *flatcorrExpMetadataFromObject(const flatcorrExpRow *object) 23229 { 23230 psMetadata *md = psMetadataAlloc(); 23231 if (!psMetadataAdd(md, PS_LIST_TAIL, "corr_id", PS_DATA_S64, NULL, object->corr_id)) { 23232 psError(PS_ERR_UNKNOWN, false, "failed to add item corr_id"); 23233 psFree(md); 23234 return false; 23235 } 23236 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, NULL, object->chip_id)) { 23237 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 23238 psFree(md); 23239 return false; 23240 } 23241 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 23242 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 23243 psFree(md); 23244 return false; 23245 } 23246 23247 23248 return md; 23249 } 23250 23251 flatcorrExpRow *flatcorrExpObjectFromMetadata(psMetadata *md) 23252 { 23253 23254 bool status = false; 23255 psS64 corr_id = psMetadataLookupS64(&status, md, "corr_id"); 23256 if (!status) { 23257 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item corr_id"); 23258 return false; 23259 } 23260 psS64 chip_id = psMetadataLookupS64(&status, md, "chip_id"); 23261 if (!status) { 23262 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item chip_id"); 23263 return false; 23264 } 23265 char* state = psMetadataLookupPtr(&status, md, "state"); 23266 if (!status) { 23267 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 23268 return false; 23269 } 23270 23271 return flatcorrExpRowAlloc(corr_id, chip_id, state); 23272 } 23273 psArray *flatcorrExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 23274 { 23275 psArray *rowSet; 23276 psArray *returnSet; 23277 psU64 i; 23278 23279 rowSet = psDBSelectRows(dbh, FLATCORREXP_TABLE_NAME, where, limit); 23280 if (!rowSet) { 23281 return NULL; 23282 } 23283 23284 // convert psMetadata rows to row objects 23285 23286 returnSet = psArrayAllocEmpty(rowSet->n); 23287 23288 for (i = 0; i < rowSet->n; i++) { 23289 flatcorrExpRow *object = flatcorrExpObjectFromMetadata(rowSet->data[i]); 23290 psArrayAdd(returnSet, 0, object); 23291 psFree(object); 23292 } 23293 23294 psFree(rowSet); 23295 23296 return returnSet; 23297 } 23298 bool flatcorrExpDeleteObject(psDB *dbh, const flatcorrExpRow *object) 23299 { 23300 psMetadata *where = flatcorrExpMetadataFromObject(object); 23301 long long count = psDBDeleteRows(dbh, FLATCORREXP_TABLE_NAME, where, 0); 23302 psFree(where); 23303 if (count < 0) { 23304 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrExp"); 23305 return false; 23306 } 23307 if (count > 1) { 23308 // XXX should this be a psAbort() instead? It is possible that 23309 // having an object match multiple rows was by design. 23310 psError(PS_ERR_UNKNOWN, true, "flatcorrExpRow object matched more then one row. Check your database schema"); 23311 return false; 23312 } 23313 23314 return true; 23315 } 23316 long long flatcorrExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 23317 { 23318 long long deleted = 0; 23319 23320 for (long long i = 0; i < objects->n; i++) { 23321 flatcorrExpRow *object = objects->data[i]; 23322 psMetadata *where = flatcorrExpMetadataFromObject(object); 23323 long long count = psDBDeleteRows(dbh, FLATCORREXP_TABLE_NAME, where, limit); 23324 psFree(where); 23325 if (count < 0) { 23326 psError(PS_ERR_UNKNOWN, true, "failed to delete row from flatcorrExp"); 23327 return count; 23328 } 23329 23330 deleted += count; 23331 } 23332 23333 return deleted; 23334 } 23335 bool flatcorrExpPrintObjects(FILE *stream, psArray *objects, bool mdcf) 23336 { 23337 PS_ASSERT_PTR_NON_NULL(objects, false); 23338 23339 psMetadata *output = psMetadataAlloc(); 23340 for (long i = 0; i < psArrayLength(objects); i++) { 23341 psMetadata *md = flatcorrExpMetadataFromObject(objects->data[i]); 23342 if (!psMetadataAddMetadata( 23343 output, 23344 PS_LIST_TAIL, 23345 FLATCORREXP_TABLE_NAME, 23346 PS_META_DUPLICATE_OK, 23347 NULL, 23348 md 23349 )) { 23350 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 23351 psFree(md); 23352 psFree(output); 23353 return false; 23354 } 23355 psFree(md); 23356 } 23357 23358 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 23359 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 23360 psFree(output); 23361 } 23362 psFree(output); 23363 23364 return true; 23365 } 23366 bool flatcorrExpPrintObject(FILE *stream, flatcorrExpRow *object, bool mdcf) 23367 { 23368 PS_ASSERT_PTR_NON_NULL(object, false); 23369 23370 psMetadata *md = flatcorrExpMetadataFromObject(object); 23371 23372 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 23373 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 23374 psFree(md); 23375 } 23376 23377 psFree(md); 23378 23379 return true; 23380 } -
trunk/ippdb/src/ippdb.h
r15569 r15576 11105 11105 bool mdcf ///< format as mdconfig or simple 11106 11106 ); 11107 /** flatcorrRunRow data structure 11108 * 11109 * Structure for representing a single row of flatcorrRun table data. 11110 */ 11111 11112 typedef struct { 11113 psS64 corr_id; 11114 char *dvodb; 11115 char *state; 11116 char *workdir; 11117 char *label; 11118 } flatcorrRunRow; 11119 11120 /** Creates a new flatcorrRunRow object 11121 * 11122 * @return A new flatcorrRunRow object or NULL on failure. 11123 */ 11124 11125 flatcorrRunRow *flatcorrRunRowAlloc( 11126 psS64 corr_id, 11127 const char *dvodb, 11128 const char *state, 11129 const char *workdir, 11130 const char *label 11131 ); 11132 11133 /** Creates a new flatcorrRun table 11134 * 11135 * @return true on success 11136 */ 11137 11138 bool flatcorrRunCreateTable( 11139 psDB *dbh ///< Database handle 11140 ); 11141 11142 /** Deletes a flatcorrRun table 11143 * 11144 * @return true on success 11145 */ 11146 11147 bool flatcorrRunDropTable( 11148 psDB *dbh ///< Database handle 11149 ); 11150 11151 /** Insert a single row into a table 11152 * 11153 * This function constructs and inserts a single row based on it's parameters. 11154 * 11155 * @return true on success 11156 */ 11157 11158 bool flatcorrRunInsert( 11159 psDB *dbh, ///< Database handle 11160 psS64 corr_id, 11161 const char *dvodb, 11162 const char *state, 11163 const char *workdir, 11164 const char *label 11165 ); 11166 11167 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 11168 * 11169 * @return A The number of rows removed or a negative value on error 11170 */ 11171 11172 long long flatcorrRunDelete( 11173 psDB *dbh, ///< Database handle 11174 const psMetadata *where, ///< Row match criteria 11175 unsigned long long limit ///< Maximum number of elements to delete 11176 ); 11177 11178 /** Insert a single flatcorrRunRow object into a table 11179 * 11180 * This function constructs and inserts a single row based on it's parameters. 11181 * 11182 * @return true on success 11183 */ 11184 11185 bool flatcorrRunInsertObject( 11186 psDB *dbh, ///< Database handle 11187 flatcorrRunRow *object ///< flatcorrRunRow object 11188 ); 11189 11190 /** Insert an array of flatcorrRunRow object into a table 11191 * 11192 * This function constructs and inserts multiple rows based on it's parameters. 11193 * 11194 * @return true on success 11195 */ 11196 11197 bool flatcorrRunInsertObjects( 11198 psDB *dbh, ///< Database handle 11199 psArray *objects ///< array of flatcorrRunRow objects 11200 ); 11201 11202 /** Insert data from a binary FITS table flatcorrRunRow into the database 11203 * 11204 * This function expects a psFits object with a FITS table as the first 11205 * extension. The table must have at least one row of data in it, that is of 11206 * the appropriate format (number of columns and their type). All other 11207 * extensions are ignored. 11208 * 11209 * @return true on success 11210 */ 11211 11212 bool flatcorrRunInsertFits( 11213 psDB *dbh, ///< Database handle 11214 const psFits *fits ///< psFits object 11215 ); 11216 11217 /** Selects up to limit from the database and returns them in a binary FITS table 11218 * 11219 * This function assumes an empty psFits object and will create a FITS table 11220 * as the first extension. 11221 * 11222 * See psDBSelectRows() for documentation on the format of where. 11223 * 11224 * @return true on success 11225 */ 11226 11227 bool flatcorrRunSelectRowsFits( 11228 psDB *dbh, ///< Database handle 11229 psFits *fits, ///< psFits object 11230 const psMetadata *where, ///< Row match criteria 11231 unsigned long long limit ///< Maximum number of elements to return 11232 ); 11233 11234 /** Convert a flatcorrRunRow into an equivalent psMetadata 11235 * 11236 * @return A psMetadata pointer or NULL on error 11237 */ 11238 11239 psMetadata *flatcorrRunMetadataFromObject( 11240 const flatcorrRunRow *object ///< fooRow to convert into a psMetadata 11241 ); 11242 11243 /** Convert a psMetadata into an equivalent fooRow 11244 * 11245 * @return A flatcorrRunRow pointer or NULL on error 11246 */ 11247 11248 flatcorrRunRow *flatcorrRunObjectFromMetadata( 11249 psMetadata *md ///< psMetadata to convert into a fooRow 11250 ); 11251 /** Selects up to limit rows from the database and returns as flatcorrRunRow objects in a psArray 11252 * 11253 * See psDBSelectRows() for documentation on the format of where. 11254 * 11255 * @return A psArray pointer or NULL on error 11256 */ 11257 11258 psArray *flatcorrRunSelectRowObjects( 11259 psDB *dbh, ///< Database handle 11260 const psMetadata *where, ///< Row match criteria 11261 unsigned long long limit ///< Maximum number of elements to return 11262 ); 11263 /** Deletes a row from the database coresponding to an flatcorrRun 11264 * 11265 * Note that a 'where' search psMetadata is constructed from each object and 11266 * used to find rows to delete. 11267 * 11268 * @return A The number of rows removed or a negative value on error 11269 */ 11270 11271 bool flatcorrRunDeleteObject( 11272 psDB *dbh, ///< Database handle 11273 const flatcorrRunRow *object ///< Object to delete 11274 ); 11275 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 11276 * 11277 * Note that a 'where' search psMetadata is constructed from each object and 11278 * used to find rows to delete. 11279 * 11280 * @return A The number of rows removed or a negative value on error 11281 */ 11282 11283 long long flatcorrRunDeleteRowObjects( 11284 psDB *dbh, ///< Database handle 11285 const psArray *objects, ///< Array of objects to delete 11286 unsigned long long limit ///< Maximum number of elements to delete 11287 ); 11288 /** Formats and prints an array of flatcorrRunRow objects 11289 * 11290 * When mdcf is set the formated output is in psMetadataConfig 11291 * format, otherwise it is in a simple tabular format. 11292 * 11293 * @return true on success 11294 */ 11295 11296 bool flatcorrRunPrintObjects( 11297 FILE *stream, ///< a stream 11298 psArray *objects, ///< An array of flatcorrRunRow objects 11299 bool mdcf ///< format as mdconfig or simple 11300 ); 11301 /** Formats and prints an flatcorrRunRow object 11302 * 11303 * When mdcf is set the formated output is in psMetadataConfig 11304 * format, otherwise it is in a simple tabular format. 11305 * 11306 * @return true on success 11307 */ 11308 11309 bool flatcorrRunPrintObject( 11310 FILE *stream, ///< a stream 11311 flatcorrRunRow *object, ///< an flatcorrRunRow object 11312 bool mdcf ///< format as mdconfig or simple 11313 ); 11314 /** flatcorrExpRow data structure 11315 * 11316 * Structure for representing a single row of flatcorrExp table data. 11317 */ 11318 11319 typedef struct { 11320 psS64 corr_id; 11321 psS64 chip_id; 11322 char *state; 11323 } flatcorrExpRow; 11324 11325 /** Creates a new flatcorrExpRow object 11326 * 11327 * @return A new flatcorrExpRow object or NULL on failure. 11328 */ 11329 11330 flatcorrExpRow *flatcorrExpRowAlloc( 11331 psS64 corr_id, 11332 psS64 chip_id, 11333 const char *state 11334 ); 11335 11336 /** Creates a new flatcorrExp table 11337 * 11338 * @return true on success 11339 */ 11340 11341 bool flatcorrExpCreateTable( 11342 psDB *dbh ///< Database handle 11343 ); 11344 11345 /** Deletes a flatcorrExp table 11346 * 11347 * @return true on success 11348 */ 11349 11350 bool flatcorrExpDropTable( 11351 psDB *dbh ///< Database handle 11352 ); 11353 11354 /** Insert a single row into a table 11355 * 11356 * This function constructs and inserts a single row based on it's parameters. 11357 * 11358 * @return true on success 11359 */ 11360 11361 bool flatcorrExpInsert( 11362 psDB *dbh, ///< Database handle 11363 psS64 corr_id, 11364 psS64 chip_id, 11365 const char *state 11366 ); 11367 11368 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 11369 * 11370 * @return A The number of rows removed or a negative value on error 11371 */ 11372 11373 long long flatcorrExpDelete( 11374 psDB *dbh, ///< Database handle 11375 const psMetadata *where, ///< Row match criteria 11376 unsigned long long limit ///< Maximum number of elements to delete 11377 ); 11378 11379 /** Insert a single flatcorrExpRow object into a table 11380 * 11381 * This function constructs and inserts a single row based on it's parameters. 11382 * 11383 * @return true on success 11384 */ 11385 11386 bool flatcorrExpInsertObject( 11387 psDB *dbh, ///< Database handle 11388 flatcorrExpRow *object ///< flatcorrExpRow object 11389 ); 11390 11391 /** Insert an array of flatcorrExpRow object into a table 11392 * 11393 * This function constructs and inserts multiple rows based on it's parameters. 11394 * 11395 * @return true on success 11396 */ 11397 11398 bool flatcorrExpInsertObjects( 11399 psDB *dbh, ///< Database handle 11400 psArray *objects ///< array of flatcorrExpRow objects 11401 ); 11402 11403 /** Insert data from a binary FITS table flatcorrExpRow into the database 11404 * 11405 * This function expects a psFits object with a FITS table as the first 11406 * extension. The table must have at least one row of data in it, that is of 11407 * the appropriate format (number of columns and their type). All other 11408 * extensions are ignored. 11409 * 11410 * @return true on success 11411 */ 11412 11413 bool flatcorrExpInsertFits( 11414 psDB *dbh, ///< Database handle 11415 const psFits *fits ///< psFits object 11416 ); 11417 11418 /** Selects up to limit from the database and returns them in a binary FITS table 11419 * 11420 * This function assumes an empty psFits object and will create a FITS table 11421 * as the first extension. 11422 * 11423 * See psDBSelectRows() for documentation on the format of where. 11424 * 11425 * @return true on success 11426 */ 11427 11428 bool flatcorrExpSelectRowsFits( 11429 psDB *dbh, ///< Database handle 11430 psFits *fits, ///< psFits object 11431 const psMetadata *where, ///< Row match criteria 11432 unsigned long long limit ///< Maximum number of elements to return 11433 ); 11434 11435 /** Convert a flatcorrExpRow into an equivalent psMetadata 11436 * 11437 * @return A psMetadata pointer or NULL on error 11438 */ 11439 11440 psMetadata *flatcorrExpMetadataFromObject( 11441 const flatcorrExpRow *object ///< fooRow to convert into a psMetadata 11442 ); 11443 11444 /** Convert a psMetadata into an equivalent fooRow 11445 * 11446 * @return A flatcorrExpRow pointer or NULL on error 11447 */ 11448 11449 flatcorrExpRow *flatcorrExpObjectFromMetadata( 11450 psMetadata *md ///< psMetadata to convert into a fooRow 11451 ); 11452 /** Selects up to limit rows from the database and returns as flatcorrExpRow objects in a psArray 11453 * 11454 * See psDBSelectRows() for documentation on the format of where. 11455 * 11456 * @return A psArray pointer or NULL on error 11457 */ 11458 11459 psArray *flatcorrExpSelectRowObjects( 11460 psDB *dbh, ///< Database handle 11461 const psMetadata *where, ///< Row match criteria 11462 unsigned long long limit ///< Maximum number of elements to return 11463 ); 11464 /** Deletes a row from the database coresponding to an flatcorrExp 11465 * 11466 * Note that a 'where' search psMetadata is constructed from each object and 11467 * used to find rows to delete. 11468 * 11469 * @return A The number of rows removed or a negative value on error 11470 */ 11471 11472 bool flatcorrExpDeleteObject( 11473 psDB *dbh, ///< Database handle 11474 const flatcorrExpRow *object ///< Object to delete 11475 ); 11476 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 11477 * 11478 * Note that a 'where' search psMetadata is constructed from each object and 11479 * used to find rows to delete. 11480 * 11481 * @return A The number of rows removed or a negative value on error 11482 */ 11483 11484 long long flatcorrExpDeleteRowObjects( 11485 psDB *dbh, ///< Database handle 11486 const psArray *objects, ///< Array of objects to delete 11487 unsigned long long limit ///< Maximum number of elements to delete 11488 ); 11489 /** Formats and prints an array of flatcorrExpRow objects 11490 * 11491 * When mdcf is set the formated output is in psMetadataConfig 11492 * format, otherwise it is in a simple tabular format. 11493 * 11494 * @return true on success 11495 */ 11496 11497 bool flatcorrExpPrintObjects( 11498 FILE *stream, ///< a stream 11499 psArray *objects, ///< An array of flatcorrExpRow objects 11500 bool mdcf ///< format as mdconfig or simple 11501 ); 11502 /** Formats and prints an flatcorrExpRow object 11503 * 11504 * When mdcf is set the formated output is in psMetadataConfig 11505 * format, otherwise it is in a simple tabular format. 11506 * 11507 * @return true on success 11508 */ 11509 11510 bool flatcorrExpPrintObject( 11511 FILE *stream, ///< a stream 11512 flatcorrExpRow *object, ///< an flatcorrExpRow object 11513 bool mdcf ///< format as mdconfig or simple 11514 ); 11107 11515 11108 11516 /// @} … … 11112 11520 #endif 11113 11521 11114 #endif // CALRUN_DB_H11522 #endif // FLATCORREXP_DB_H -
trunk/ippdb/tests/alloc.c
r15569 r15576 2486 2486 } 2487 2487 2488 { 2489 flatcorrRunRow *object; 2490 2491 object = flatcorrRunRowAlloc(-64, "a string", "a string", "a string", "a string" ); 2492 2493 if (!object) { 2494 exit(EXIT_FAILURE); 2495 } 2496 2497 if (!object->corr_id == -64) { 2498 psFree(object); 2499 exit(EXIT_FAILURE); 2500 } 2501 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 2502 psFree(object); 2503 exit(EXIT_FAILURE); 2504 } 2505 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 2506 psFree(object); 2507 exit(EXIT_FAILURE); 2508 } 2509 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 2510 psFree(object); 2511 exit(EXIT_FAILURE); 2512 } 2513 if (strncmp(object->label, "a string", MAX_STRING_LENGTH)) { 2514 psFree(object); 2515 exit(EXIT_FAILURE); 2516 } 2517 2518 psFree(object); 2519 } 2520 2521 { 2522 flatcorrExpRow *object; 2523 2524 object = flatcorrExpRowAlloc(-64, -64, "a string" ); 2525 2526 if (!object) { 2527 exit(EXIT_FAILURE); 2528 } 2529 2530 if (!object->corr_id == -64) { 2531 psFree(object); 2532 exit(EXIT_FAILURE); 2533 } 2534 if (!object->chip_id == -64) { 2535 psFree(object); 2536 exit(EXIT_FAILURE); 2537 } 2538 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 2539 psFree(object); 2540 exit(EXIT_FAILURE); 2541 } 2542 2543 psFree(object); 2544 } 2545 2488 2546 exit(EXIT_SUCCESS); 2489 2547 } -
trunk/ippdb/tests/createtable.c
r15569 r15576 755 755 } 756 756 757 { 758 psDB *dbh; 759 760 dbh = psDBInit("localhost", "test", NULL, "test"); 761 if (!dbh) { 762 exit(EXIT_FAILURE); 763 } 764 765 if(!flatcorrRunCreateTable(dbh)) { 766 exit(EXIT_FAILURE); 767 } 768 769 psDBCleanup(dbh); 770 } 771 772 { 773 psDB *dbh; 774 775 dbh = psDBInit("localhost", "test", NULL, "test"); 776 if (!dbh) { 777 exit(EXIT_FAILURE); 778 } 779 780 if(!flatcorrExpCreateTable(dbh)) { 781 exit(EXIT_FAILURE); 782 } 783 784 psDBCleanup(dbh); 785 } 786 757 787 exit(EXIT_SUCCESS); 758 788 } -
trunk/ippdb/tests/dbcleanup.c
r15569 r15576 61 61 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calDB"); 62 62 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calRun"); 63 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS flatcorrRun"); 64 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS flatcorrExp"); 63 65 64 66 psDBCleanup(dbh); -
trunk/ippdb/tests/dbsetup.c
r15569 r15576 163 163 calRunCreateTable(dbh); 164 164 165 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS flatcorrRun"); 166 flatcorrRunCreateTable(dbh); 167 168 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS flatcorrExp"); 169 flatcorrExpCreateTable(dbh); 170 165 171 psDBCleanup(dbh); 166 172 -
trunk/ippdb/tests/droptable.c
r15569 r15576 755 755 } 756 756 757 { 758 psDB *dbh; 759 760 dbh = psDBInit("localhost", "test", NULL, "test"); 761 if (!dbh) { 762 exit(EXIT_FAILURE); 763 } 764 765 if (!flatcorrRunDropTable(dbh)) { 766 exit(EXIT_FAILURE); 767 } 768 769 psDBCleanup(dbh); 770 } 771 772 { 773 psDB *dbh; 774 775 dbh = psDBInit("localhost", "test", NULL, "test"); 776 if (!dbh) { 777 exit(EXIT_FAILURE); 778 } 779 780 if (!flatcorrExpDropTable(dbh)) { 781 exit(EXIT_FAILURE); 782 } 783 784 psDBCleanup(dbh); 785 } 786 757 787 exit(EXIT_SUCCESS); 758 788 } -
trunk/ippdb/tests/insert.c
r15569 r15576 755 755 } 756 756 757 { 758 psDB *dbh; 759 760 dbh = psDBInit("localhost", "test", NULL, "test"); 761 if (!dbh) { 762 exit(EXIT_FAILURE); 763 } 764 765 if (!flatcorrRunInsert(dbh, -64, "a string", "a string", "a string", "a string")) { 766 exit(EXIT_FAILURE); 767 } 768 769 psDBCleanup(dbh); 770 } 771 772 { 773 psDB *dbh; 774 775 dbh = psDBInit("localhost", "test", NULL, "test"); 776 if (!dbh) { 777 exit(EXIT_FAILURE); 778 } 779 780 if (!flatcorrExpInsert(dbh, -64, -64, "a string")) { 781 exit(EXIT_FAILURE); 782 } 783 784 psDBCleanup(dbh); 785 } 786 757 787 exit(EXIT_SUCCESS); 758 788 } -
trunk/ippdb/tests/insertfits.c
r15569 r15576 1309 1309 } 1310 1310 1311 { 1312 psDB *dbh; 1313 psFits *fits; 1314 1315 dbh = psDBInit("localhost", "test", NULL, "test"); 1316 if (!dbh) { 1317 exit(EXIT_FAILURE); 1318 } 1319 1320 // open a temp 1321 fits = psFitsOpen(TMP_FILENAME, "r"); 1322 if (!fits) { 1323 exit(EXIT_FAILURE); 1324 } 1325 1326 if (!flatcorrRunInsertFits(dbh, fits)) { 1327 exit(EXIT_FAILURE); 1328 } 1329 1330 if (!psFitsClose(fits)) { 1331 exit(EXIT_FAILURE); 1332 } 1333 1334 psDBCleanup(dbh); 1335 } 1336 1337 { 1338 psDB *dbh; 1339 psFits *fits; 1340 1341 dbh = psDBInit("localhost", "test", NULL, "test"); 1342 if (!dbh) { 1343 exit(EXIT_FAILURE); 1344 } 1345 1346 // open a temp 1347 fits = psFitsOpen(TMP_FILENAME, "r"); 1348 if (!fits) { 1349 exit(EXIT_FAILURE); 1350 } 1351 1352 if (!flatcorrExpInsertFits(dbh, fits)) { 1353 exit(EXIT_FAILURE); 1354 } 1355 1356 if (!psFitsClose(fits)) { 1357 exit(EXIT_FAILURE); 1358 } 1359 1360 psDBCleanup(dbh); 1361 } 1362 1311 1363 exit(EXIT_SUCCESS); 1312 1364 } -
trunk/ippdb/tests/insertobject.c
r15569 r15576 1105 1105 } 1106 1106 1107 { 1108 psDB *dbh; 1109 flatcorrRunRow *object; 1110 1111 dbh = psDBInit("localhost", "test", NULL, "test"); 1112 if (!dbh) { 1113 exit(EXIT_FAILURE); 1114 } 1115 1116 object = flatcorrRunRowAlloc(-64, "a string", "a string", "a string", "a string"); 1117 if (!object) { 1118 exit(EXIT_FAILURE); 1119 } 1120 1121 if (!flatcorrRunInsertObject(dbh, object)) { 1122 exit(EXIT_FAILURE); 1123 } 1124 1125 psFree(object); 1126 psDBCleanup(dbh); 1127 } 1128 1129 { 1130 psDB *dbh; 1131 flatcorrExpRow *object; 1132 1133 dbh = psDBInit("localhost", "test", NULL, "test"); 1134 if (!dbh) { 1135 exit(EXIT_FAILURE); 1136 } 1137 1138 object = flatcorrExpRowAlloc(-64, -64, "a string"); 1139 if (!object) { 1140 exit(EXIT_FAILURE); 1141 } 1142 1143 if (!flatcorrExpInsertObject(dbh, object)) { 1144 exit(EXIT_FAILURE); 1145 } 1146 1147 psFree(object); 1148 psDBCleanup(dbh); 1149 } 1150 1107 1151 exit(EXIT_SUCCESS); 1108 1152 } -
trunk/ippdb/tests/metadatafromobject.c
r15569 r15576 2805 2805 } 2806 2806 2807 { 2808 psMetadata *md; 2809 flatcorrRunRow *object; 2810 bool status; 2811 2812 object = flatcorrRunRowAlloc(-64, "a string", "a string", "a string", "a string"); 2813 if (!object) { 2814 exit(EXIT_FAILURE); 2815 } 2816 2817 md = flatcorrRunMetadataFromObject(object); 2818 if (!md) { 2819 exit(EXIT_FAILURE); 2820 } 2821 2822 psFree(object); 2823 2824 psFree(md); 2825 exit(EXIT_FAILURE); 2826 } 2827 if (strncmp(psMetadataLookupPtr(&status, md, "dvodb"), "a string", MAX_STRING_LENGTH)) { 2828 psFree(md); 2829 exit(EXIT_FAILURE); 2830 } 2831 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 2832 psFree(md); 2833 exit(EXIT_FAILURE); 2834 } 2835 if (strncmp(psMetadataLookupPtr(&status, md, "workdir"), "a string", MAX_STRING_LENGTH)) { 2836 psFree(md); 2837 exit(EXIT_FAILURE); 2838 } 2839 if (strncmp(psMetadataLookupPtr(&status, md, "label"), "a string", MAX_STRING_LENGTH)) { 2840 psFree(md); 2841 exit(EXIT_FAILURE); 2842 } 2843 2844 psFree(md); 2845 } 2846 2847 { 2848 psMetadata *md; 2849 flatcorrExpRow *object; 2850 bool status; 2851 2852 object = flatcorrExpRowAlloc(-64, -64, "a string"); 2853 if (!object) { 2854 exit(EXIT_FAILURE); 2855 } 2856 2857 md = flatcorrExpMetadataFromObject(object); 2858 if (!md) { 2859 exit(EXIT_FAILURE); 2860 } 2861 2862 psFree(object); 2863 2864 psFree(md); 2865 exit(EXIT_FAILURE); 2866 } 2867 psFree(md); 2868 exit(EXIT_FAILURE); 2869 } 2870 if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) { 2871 psFree(md); 2872 exit(EXIT_FAILURE); 2873 } 2874 2875 psFree(md); 2876 } 2877 2807 2878 exit(EXIT_SUCCESS); 2808 2879 } -
trunk/ippdb/tests/objectfrommetadata.c
r15569 r15576 4402 4402 } 4403 4403 4404 { 4405 psMetadata *md; 4406 flatcorrRunRow *object; 4407 4408 md = psMetadataAlloc(); 4409 psFree(md); 4410 exit(EXIT_FAILURE); 4411 } 4412 if (!psMetadataAddStr(md, PS_LIST_TAIL, "dvodb", 0, NULL, "a string")) { 4413 psFree(md); 4414 exit(EXIT_FAILURE); 4415 } 4416 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 4417 psFree(md); 4418 exit(EXIT_FAILURE); 4419 } 4420 if (!psMetadataAddStr(md, PS_LIST_TAIL, "workdir", 0, NULL, "a string")) { 4421 psFree(md); 4422 exit(EXIT_FAILURE); 4423 } 4424 if (!psMetadataAddStr(md, PS_LIST_TAIL, "label", 0, NULL, "a string")) { 4425 psFree(md); 4426 exit(EXIT_FAILURE); 4427 } 4428 4429 object = flatcorrRunObjectFromMetadata(md); 4430 if (!object) { 4431 psFree(md); 4432 exit(EXIT_FAILURE); 4433 } 4434 4435 psFree(md); 4436 4437 psFree(object); 4438 exit(EXIT_FAILURE); 4439 } 4440 if (strncmp(object->dvodb, "a string", MAX_STRING_LENGTH)) { 4441 psFree(object); 4442 exit(EXIT_FAILURE); 4443 } 4444 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 4445 psFree(object); 4446 exit(EXIT_FAILURE); 4447 } 4448 if (strncmp(object->workdir, "a string", MAX_STRING_LENGTH)) { 4449 psFree(object); 4450 exit(EXIT_FAILURE); 4451 } 4452 if (strncmp(object->label, "a string", MAX_STRING_LENGTH)) { 4453 psFree(object); 4454 exit(EXIT_FAILURE); 4455 } 4456 4457 psFree(object); 4458 } 4459 4460 { 4461 psMetadata *md; 4462 flatcorrExpRow *object; 4463 4464 md = psMetadataAlloc(); 4465 psFree(md); 4466 exit(EXIT_FAILURE); 4467 } 4468 psFree(md); 4469 exit(EXIT_FAILURE); 4470 } 4471 if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) { 4472 psFree(md); 4473 exit(EXIT_FAILURE); 4474 } 4475 4476 object = flatcorrExpObjectFromMetadata(md); 4477 if (!object) { 4478 psFree(md); 4479 exit(EXIT_FAILURE); 4480 } 4481 4482 psFree(md); 4483 4484 psFree(object); 4485 exit(EXIT_FAILURE); 4486 } 4487 psFree(object); 4488 exit(EXIT_FAILURE); 4489 } 4490 if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) { 4491 psFree(object); 4492 exit(EXIT_FAILURE); 4493 } 4494 4495 psFree(object); 4496 } 4497 4404 4498 exit(EXIT_SUCCESS); 4405 4499 } -
trunk/ippdb/tests/selectrowsfits.c
r15569 r15576 1107 1107 } 1108 1108 1109 { 1110 psDB *dbh; 1111 psFits *fits; 1112 1113 dbh = psDBInit("localhost", "test", NULL, "test"); 1114 if (!dbh) { 1115 exit(EXIT_FAILURE); 1116 } 1117 1118 fits = psFitsOpen(TMP_FILENAME, "w"); 1119 if (!fits) { 1120 exit(EXIT_FAILURE); 1121 } 1122 1123 if (!flatcorrRunSelectRowsFits(dbh, fits, NULL, 1)) { 1124 exit(EXIT_FAILURE); 1125 } 1126 1127 psFree(fits); 1128 psDBCleanup(dbh); 1129 } 1130 1131 { 1132 psDB *dbh; 1133 psFits *fits; 1134 1135 dbh = psDBInit("localhost", "test", NULL, "test"); 1136 if (!dbh) { 1137 exit(EXIT_FAILURE); 1138 } 1139 1140 fits = psFitsOpen(TMP_FILENAME, "w"); 1141 if (!fits) { 1142 exit(EXIT_FAILURE); 1143 } 1144 1145 if (!flatcorrExpSelectRowsFits(dbh, fits, NULL, 1)) { 1146 exit(EXIT_FAILURE); 1147 } 1148 1149 psFree(fits); 1150 psDBCleanup(dbh); 1151 } 1152 1109 1153 exit(EXIT_SUCCESS); 1110 1154 }
Note:
See TracChangeset
for help on using the changeset viewer.
