IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15569


Ignore:
Timestamp:
Nov 9, 2007, 3:55:36 PM (19 years ago)
Author:
jhoblitt
Message:

add calibration.md

Location:
trunk/ippdb
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippdb/Makefile.am

    r15421 r15569  
    5757    $(top_builddir)/docs/man/man3/magicNodeResultRow.3 \
    5858    $(top_builddir)/docs/man/man3/magicMaskRow.3 \
    59     $(top_builddir)/docs/man/man3/magicSkyfileMaskRow.3
     59    $(top_builddir)/docs/man/man3/magicSkyfileMaskRow.3 \
     60    $(top_builddir)/docs/man/man3/calDBRow.3 \
     61    $(top_builddir)/docs/man/man3/calRunRow.3
    6062
    6163
    62 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:
     64docs/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:
    6365        $(DOXYGEN)
    6466
  • trunk/ippdb/src/ippdb.c

    r15533 r15569  
    7979#define MAGICMASK_TABLE_NAME "magicMask"
    8080#define MAGICSKYFILEMASK_TABLE_NAME "magicSkyfileMask"
     81#define CALDB_TABLE_NAME "calDB"
     82#define CALRUN_TABLE_NAME "calRun"
    8183#define MAX_STRING_LENGTH 1024
    8284
     
    2204222044    return true;
    2204322045}
     22046static void calDBRowFree(calDBRow *object);
     22047
     22048calDBRow *calDBRowAlloc(psS64 cal_id, const char *catdir, const char *state)
     22049{
     22050    calDBRow        *_object;
     22051
     22052    _object = psAlloc(sizeof(calDBRow));
     22053    psMemSetDeallocator(_object, (psFreeFunc)calDBRowFree);
     22054
     22055    _object->cal_id = cal_id;
     22056    _object->catdir = psStringCopy(catdir);
     22057    _object->state = psStringCopy(state);
     22058
     22059    return _object;
     22060}
     22061
     22062static void calDBRowFree(calDBRow *object)
     22063{
     22064    psFree(object->catdir);
     22065    psFree(object->state);
     22066}
     22067
     22068bool calDBCreateTable(psDB *dbh)
     22069{
     22070    psMetadata *md = psMetadataAlloc();
     22071    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) {
     22072        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22073        psFree(md);
     22074        return false;
     22075    }
     22076    if (!psMetadataAdd(md, PS_LIST_TAIL, "catdir", PS_DATA_STRING, NULL, "64")) {
     22077        psError(PS_ERR_UNKNOWN, false, "failed to add item catdir");
     22078        psFree(md);
     22079        return false;
     22080    }
     22081    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, "64")) {
     22082        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22083        psFree(md);
     22084        return false;
     22085    }
     22086
     22087    bool status = psDBCreateTable(dbh, CALDB_TABLE_NAME, md);
     22088
     22089    psFree(md);
     22090
     22091    return status;
     22092}
     22093
     22094bool calDBDropTable(psDB *dbh)
     22095{
     22096    return psDBDropTable(dbh, CALDB_TABLE_NAME);
     22097}
     22098
     22099bool calDBInsert(psDB * dbh, psS64 cal_id, const char *catdir, const char *state)
     22100{
     22101    psMetadata *md = psMetadataAlloc();
     22102    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, NULL, cal_id)) {
     22103        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22104        psFree(md);
     22105        return false;
     22106    }
     22107    if (!psMetadataAdd(md, PS_LIST_TAIL, "catdir", PS_DATA_STRING, NULL, catdir)) {
     22108        psError(PS_ERR_UNKNOWN, false, "failed to add item catdir");
     22109        psFree(md);
     22110        return false;
     22111    }
     22112    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {
     22113        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22114        psFree(md);
     22115        return false;
     22116    }
     22117
     22118    bool status = psDBInsertOneRow(dbh, CALDB_TABLE_NAME, md);
     22119    psFree(md);
     22120
     22121    return status;
     22122}
     22123
     22124long long calDBDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     22125{
     22126    long long       deleted = 0;
     22127
     22128    long long count = psDBDeleteRows(dbh, CALDB_TABLE_NAME, where, limit);
     22129    if (count < 0) {
     22130        psError(PS_ERR_UNKNOWN, true, "failed to delete row from calDB");
     22131        return count;
     22132
     22133        deleted += count;
     22134    }
     22135
     22136    return deleted;
     22137}
     22138bool calDBInsertObject(psDB *dbh, calDBRow *object)
     22139{
     22140    return calDBInsert(dbh, object->cal_id, object->catdir, object->state);
     22141}
     22142
     22143bool calDBInsertObjects(psDB *dbh, psArray *objects)
     22144{
     22145    for (long i = 0; i < psArrayLength(objects); i++) {
     22146        if (!calDBInsertObject(dbh, objects->data[i])) {
     22147            return false;
     22148        }
     22149    }
     22150
     22151    return true;
     22152}
     22153
     22154bool calDBInsertFits(psDB *dbh, const psFits *fits)
     22155{
     22156    psArray         *rowSet;
     22157
     22158    // move to (the first?) extension named  CALDB_TABLE_NAME
     22159    if (!psFitsMoveExtName(fits, CALDB_TABLE_NAME)) {
     22160        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", CALDB_TABLE_NAME);
     22161        return false;
     22162    }
     22163
     22164    // check HDU type
     22165    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     22166        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     22167        return false;
     22168    }
     22169
     22170    // read fits table
     22171    rowSet = psFitsReadTable(fits);
     22172    if (!rowSet) {
     22173        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     22174        psFree(rowSet);
     22175        return false;
     22176    }
     22177
     22178    if (!psDBInsertRows(dbh, CALDB_TABLE_NAME, rowSet)) {
     22179        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     22180        psFree(rowSet);
     22181        return false;
     22182    }
     22183
     22184    psFree(rowSet);
     22185
     22186    return true;
     22187}
     22188
     22189bool calDBSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     22190{
     22191    psArray         *rowSet;
     22192
     22193    rowSet = psDBSelectRows(dbh, CALDB_TABLE_NAME, where, limit);
     22194    if (!rowSet) {
     22195        return false;
     22196    }
     22197
     22198    // output to fits
     22199    if (!psFitsWriteTable(fits, NULL, rowSet, CALDB_TABLE_NAME)) {
     22200        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     22201        psFree(rowSet);
     22202        return false;
     22203    }
     22204
     22205    psFree(rowSet);
     22206
     22207    return true;
     22208}
     22209
     22210psMetadata *calDBMetadataFromObject(const calDBRow *object)
     22211{
     22212    psMetadata *md = psMetadataAlloc();
     22213    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, NULL, object->cal_id)) {
     22214        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22215        psFree(md);
     22216        return false;
     22217    }
     22218    if (!psMetadataAdd(md, PS_LIST_TAIL, "catdir", PS_DATA_STRING, NULL, object->catdir)) {
     22219        psError(PS_ERR_UNKNOWN, false, "failed to add item catdir");
     22220        psFree(md);
     22221        return false;
     22222    }
     22223    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {
     22224        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22225        psFree(md);
     22226        return false;
     22227    }
     22228
     22229
     22230    return md;
     22231}
     22232
     22233calDBRow *calDBObjectFromMetadata(psMetadata *md)
     22234{
     22235
     22236bool status = false;
     22237    psS64 cal_id = psMetadataLookupS64(&status, md, "cal_id");
     22238    if (!status) {
     22239        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cal_id");
     22240        return false;
     22241    }
     22242    char* catdir = psMetadataLookupPtr(&status, md, "catdir");
     22243    if (!status) {
     22244        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item catdir");
     22245        return false;
     22246    }
     22247    char* state = psMetadataLookupPtr(&status, md, "state");
     22248    if (!status) {
     22249        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");
     22250        return false;
     22251    }
     22252
     22253    return calDBRowAlloc(cal_id, catdir, state);
     22254}
     22255psArray *calDBSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     22256{
     22257    psArray         *rowSet;
     22258    psArray         *returnSet;
     22259    psU64           i;
     22260
     22261    rowSet = psDBSelectRows(dbh, CALDB_TABLE_NAME, where, limit);
     22262    if (!rowSet) {
     22263        return NULL;
     22264    }
     22265
     22266    // convert psMetadata rows to row objects
     22267
     22268    returnSet = psArrayAllocEmpty(rowSet->n);
     22269
     22270    for (i = 0; i < rowSet->n; i++) {
     22271        calDBRow *object = calDBObjectFromMetadata(rowSet->data[i]);
     22272        psArrayAdd(returnSet, 0, object);
     22273        psFree(object);
     22274    }
     22275
     22276    psFree(rowSet);
     22277
     22278    return returnSet;
     22279}
     22280bool calDBDeleteObject(psDB *dbh, const calDBRow *object)
     22281{
     22282    psMetadata *where = calDBMetadataFromObject(object);
     22283    long long count = psDBDeleteRows(dbh, CALDB_TABLE_NAME, where, 0);
     22284    psFree(where);
     22285    if (count < 0) {
     22286        psError(PS_ERR_UNKNOWN, true, "failed to delete row from calDB");
     22287        return false;
     22288    }
     22289    if (count > 1) {
     22290        // XXX should this be a psAbort() instead?  It is possible that
     22291        // having an object match multiple rows was by design.
     22292        psError(PS_ERR_UNKNOWN, true, "calDBRow object matched more then one row.  Check your database schema");
     22293        return false;
     22294    }
     22295
     22296    return true;
     22297}
     22298long long calDBDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     22299{
     22300    long long       deleted = 0;
     22301
     22302    for (long long i = 0; i < objects->n; i++) {
     22303        calDBRow *object = objects->data[i];
     22304        psMetadata *where = calDBMetadataFromObject(object);
     22305        long long count = psDBDeleteRows(dbh, CALDB_TABLE_NAME, where, limit);
     22306        psFree(where);
     22307        if (count < 0) {
     22308            psError(PS_ERR_UNKNOWN, true, "failed to delete row from calDB");
     22309            return count;
     22310        }
     22311
     22312        deleted += count;
     22313    }
     22314
     22315    return deleted;
     22316}
     22317bool calDBPrintObjects(FILE *stream, psArray *objects, bool mdcf)
     22318{
     22319    PS_ASSERT_PTR_NON_NULL(objects, false);
     22320
     22321    psMetadata *output = psMetadataAlloc();
     22322    for (long i = 0; i < psArrayLength(objects); i++) {
     22323        psMetadata *md = calDBMetadataFromObject(objects->data[i]);
     22324        if (!psMetadataAddMetadata(
     22325            output,
     22326            PS_LIST_TAIL,
     22327            CALDB_TABLE_NAME,
     22328            PS_META_DUPLICATE_OK,
     22329            NULL,
     22330            md
     22331        )) {
     22332            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     22333            psFree(md);
     22334            psFree(output);
     22335            return false;
     22336        }
     22337        psFree(md);
     22338    }
     22339
     22340    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     22341        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     22342        psFree(output);
     22343    }
     22344    psFree(output);
     22345
     22346    return true;
     22347}
     22348bool calDBPrintObject(FILE *stream, calDBRow *object, bool mdcf)
     22349{
     22350    PS_ASSERT_PTR_NON_NULL(object, false);
     22351
     22352    psMetadata *md = calDBMetadataFromObject(object);
     22353
     22354    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     22355        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     22356        psFree(md);
     22357    }
     22358
     22359    psFree(md);
     22360
     22361    return true;
     22362}
     22363static void calRunRowFree(calRunRow *object);
     22364
     22365calRunRow *calRunRowAlloc(psS64 cal_id, const char *region, const char *last_step, const char *state)
     22366{
     22367    calRunRow       *_object;
     22368
     22369    _object = psAlloc(sizeof(calRunRow));
     22370    psMemSetDeallocator(_object, (psFreeFunc)calRunRowFree);
     22371
     22372    _object->cal_id = cal_id;
     22373    _object->region = psStringCopy(region);
     22374    _object->last_step = psStringCopy(last_step);
     22375    _object->state = psStringCopy(state);
     22376
     22377    return _object;
     22378}
     22379
     22380static void calRunRowFree(calRunRow *object)
     22381{
     22382    psFree(object->region);
     22383    psFree(object->last_step);
     22384    psFree(object->state);
     22385}
     22386
     22387bool calRunCreateTable(psDB *dbh)
     22388{
     22389    psMetadata *md = psMetadataAlloc();
     22390    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) {
     22391        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22392        psFree(md);
     22393        return false;
     22394    }
     22395    if (!psMetadataAdd(md, PS_LIST_TAIL, "region", PS_DATA_STRING, "success or failure", "64")) {
     22396        psError(PS_ERR_UNKNOWN, false, "failed to add item region");
     22397        psFree(md);
     22398        return false;
     22399    }
     22400    if (!psMetadataAdd(md, PS_LIST_TAIL, "last_step", PS_DATA_STRING, "fkey(cal_id) ref calDB(cal_id)", "64")) {
     22401        psError(PS_ERR_UNKNOWN, false, "failed to add item last_step");
     22402        psFree(md);
     22403        return false;
     22404    }
     22405    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, "64")) {
     22406        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22407        psFree(md);
     22408        return false;
     22409    }
     22410
     22411    bool status = psDBCreateTable(dbh, CALRUN_TABLE_NAME, md);
     22412
     22413    psFree(md);
     22414
     22415    return status;
     22416}
     22417
     22418bool calRunDropTable(psDB *dbh)
     22419{
     22420    return psDBDropTable(dbh, CALRUN_TABLE_NAME);
     22421}
     22422
     22423bool calRunInsert(psDB * dbh, psS64 cal_id, const char *region, const char *last_step, const char *state)
     22424{
     22425    psMetadata *md = psMetadataAlloc();
     22426    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, NULL, cal_id)) {
     22427        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22428        psFree(md);
     22429        return false;
     22430    }
     22431    if (!psMetadataAdd(md, PS_LIST_TAIL, "region", PS_DATA_STRING, NULL, region)) {
     22432        psError(PS_ERR_UNKNOWN, false, "failed to add item region");
     22433        psFree(md);
     22434        return false;
     22435    }
     22436    if (!psMetadataAdd(md, PS_LIST_TAIL, "last_step", PS_DATA_STRING, NULL, last_step)) {
     22437        psError(PS_ERR_UNKNOWN, false, "failed to add item last_step");
     22438        psFree(md);
     22439        return false;
     22440    }
     22441    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) {
     22442        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22443        psFree(md);
     22444        return false;
     22445    }
     22446
     22447    bool status = psDBInsertOneRow(dbh, CALRUN_TABLE_NAME, md);
     22448    psFree(md);
     22449
     22450    return status;
     22451}
     22452
     22453long long calRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     22454{
     22455    long long       deleted = 0;
     22456
     22457    long long count = psDBDeleteRows(dbh, CALRUN_TABLE_NAME, where, limit);
     22458    if (count < 0) {
     22459        psError(PS_ERR_UNKNOWN, true, "failed to delete row from calRun");
     22460        return count;
     22461
     22462        deleted += count;
     22463    }
     22464
     22465    return deleted;
     22466}
     22467bool calRunInsertObject(psDB *dbh, calRunRow *object)
     22468{
     22469    return calRunInsert(dbh, object->cal_id, object->region, object->last_step, object->state);
     22470}
     22471
     22472bool calRunInsertObjects(psDB *dbh, psArray *objects)
     22473{
     22474    for (long i = 0; i < psArrayLength(objects); i++) {
     22475        if (!calRunInsertObject(dbh, objects->data[i])) {
     22476            return false;
     22477        }
     22478    }
     22479
     22480    return true;
     22481}
     22482
     22483bool calRunInsertFits(psDB *dbh, const psFits *fits)
     22484{
     22485    psArray         *rowSet;
     22486
     22487    // move to (the first?) extension named  CALRUN_TABLE_NAME
     22488    if (!psFitsMoveExtName(fits, CALRUN_TABLE_NAME)) {
     22489        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", CALRUN_TABLE_NAME);
     22490        return false;
     22491    }
     22492
     22493    // check HDU type
     22494    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     22495        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     22496        return false;
     22497    }
     22498
     22499    // read fits table
     22500    rowSet = psFitsReadTable(fits);
     22501    if (!rowSet) {
     22502        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     22503        psFree(rowSet);
     22504        return false;
     22505    }
     22506
     22507    if (!psDBInsertRows(dbh, CALRUN_TABLE_NAME, rowSet)) {
     22508        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     22509        psFree(rowSet);
     22510        return false;
     22511    }
     22512
     22513    psFree(rowSet);
     22514
     22515    return true;
     22516}
     22517
     22518bool calRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     22519{
     22520    psArray         *rowSet;
     22521
     22522    rowSet = psDBSelectRows(dbh, CALRUN_TABLE_NAME, where, limit);
     22523    if (!rowSet) {
     22524        return false;
     22525    }
     22526
     22527    // output to fits
     22528    if (!psFitsWriteTable(fits, NULL, rowSet, CALRUN_TABLE_NAME)) {
     22529        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     22530        psFree(rowSet);
     22531        return false;
     22532    }
     22533
     22534    psFree(rowSet);
     22535
     22536    return true;
     22537}
     22538
     22539psMetadata *calRunMetadataFromObject(const calRunRow *object)
     22540{
     22541    psMetadata *md = psMetadataAlloc();
     22542    if (!psMetadataAdd(md, PS_LIST_TAIL, "cal_id", PS_DATA_S64, NULL, object->cal_id)) {
     22543        psError(PS_ERR_UNKNOWN, false, "failed to add item cal_id");
     22544        psFree(md);
     22545        return false;
     22546    }
     22547    if (!psMetadataAdd(md, PS_LIST_TAIL, "region", PS_DATA_STRING, NULL, object->region)) {
     22548        psError(PS_ERR_UNKNOWN, false, "failed to add item region");
     22549        psFree(md);
     22550        return false;
     22551    }
     22552    if (!psMetadataAdd(md, PS_LIST_TAIL, "last_step", PS_DATA_STRING, NULL, object->last_step)) {
     22553        psError(PS_ERR_UNKNOWN, false, "failed to add item last_step");
     22554        psFree(md);
     22555        return false;
     22556    }
     22557    if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) {
     22558        psError(PS_ERR_UNKNOWN, false, "failed to add item state");
     22559        psFree(md);
     22560        return false;
     22561    }
     22562
     22563
     22564    return md;
     22565}
     22566
     22567calRunRow *calRunObjectFromMetadata(psMetadata *md)
     22568{
     22569
     22570bool status = false;
     22571    psS64 cal_id = psMetadataLookupS64(&status, md, "cal_id");
     22572    if (!status) {
     22573        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cal_id");
     22574        return false;
     22575    }
     22576    char* region = psMetadataLookupPtr(&status, md, "region");
     22577    if (!status) {
     22578        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item region");
     22579        return false;
     22580    }
     22581    char* last_step = psMetadataLookupPtr(&status, md, "last_step");
     22582    if (!status) {
     22583        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item last_step");
     22584        return false;
     22585    }
     22586    char* state = psMetadataLookupPtr(&status, md, "state");
     22587    if (!status) {
     22588        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state");
     22589        return false;
     22590    }
     22591
     22592    return calRunRowAlloc(cal_id, region, last_step, state);
     22593}
     22594psArray *calRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     22595{
     22596    psArray         *rowSet;
     22597    psArray         *returnSet;
     22598    psU64           i;
     22599
     22600    rowSet = psDBSelectRows(dbh, CALRUN_TABLE_NAME, where, limit);
     22601    if (!rowSet) {
     22602        return NULL;
     22603    }
     22604
     22605    // convert psMetadata rows to row objects
     22606
     22607    returnSet = psArrayAllocEmpty(rowSet->n);
     22608
     22609    for (i = 0; i < rowSet->n; i++) {
     22610        calRunRow *object = calRunObjectFromMetadata(rowSet->data[i]);
     22611        psArrayAdd(returnSet, 0, object);
     22612        psFree(object);
     22613    }
     22614
     22615    psFree(rowSet);
     22616
     22617    return returnSet;
     22618}
     22619bool calRunDeleteObject(psDB *dbh, const calRunRow *object)
     22620{
     22621    psMetadata *where = calRunMetadataFromObject(object);
     22622    long long count = psDBDeleteRows(dbh, CALRUN_TABLE_NAME, where, 0);
     22623    psFree(where);
     22624    if (count < 0) {
     22625        psError(PS_ERR_UNKNOWN, true, "failed to delete row from calRun");
     22626        return false;
     22627    }
     22628    if (count > 1) {
     22629        // XXX should this be a psAbort() instead?  It is possible that
     22630        // having an object match multiple rows was by design.
     22631        psError(PS_ERR_UNKNOWN, true, "calRunRow object matched more then one row.  Check your database schema");
     22632        return false;
     22633    }
     22634
     22635    return true;
     22636}
     22637long long calRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     22638{
     22639    long long       deleted = 0;
     22640
     22641    for (long long i = 0; i < objects->n; i++) {
     22642        calRunRow *object = objects->data[i];
     22643        psMetadata *where = calRunMetadataFromObject(object);
     22644        long long count = psDBDeleteRows(dbh, CALRUN_TABLE_NAME, where, limit);
     22645        psFree(where);
     22646        if (count < 0) {
     22647            psError(PS_ERR_UNKNOWN, true, "failed to delete row from calRun");
     22648            return count;
     22649        }
     22650
     22651        deleted += count;
     22652    }
     22653
     22654    return deleted;
     22655}
     22656bool calRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)
     22657{
     22658    PS_ASSERT_PTR_NON_NULL(objects, false);
     22659
     22660    psMetadata *output = psMetadataAlloc();
     22661    for (long i = 0; i < psArrayLength(objects); i++) {
     22662        psMetadata *md = calRunMetadataFromObject(objects->data[i]);
     22663        if (!psMetadataAddMetadata(
     22664            output,
     22665            PS_LIST_TAIL,
     22666            CALRUN_TABLE_NAME,
     22667            PS_META_DUPLICATE_OK,
     22668            NULL,
     22669            md
     22670        )) {
     22671            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     22672            psFree(md);
     22673            psFree(output);
     22674            return false;
     22675        }
     22676        psFree(md);
     22677    }
     22678
     22679    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     22680        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     22681        psFree(output);
     22682    }
     22683    psFree(output);
     22684
     22685    return true;
     22686}
     22687bool calRunPrintObject(FILE *stream, calRunRow *object, bool mdcf)
     22688{
     22689    PS_ASSERT_PTR_NON_NULL(object, false);
     22690
     22691    psMetadata *md = calRunMetadataFromObject(object);
     22692
     22693    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     22694        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     22695        psFree(md);
     22696    }
     22697
     22698    psFree(md);
     22699
     22700    return true;
     22701}
  • trunk/ippdb/src/ippdb.h

    r15533 r15569  
    1070010700    bool            mdcf                ///< format as mdconfig or simple
    1070110701);
     10702/** calDBRow data structure
     10703 *
     10704 * Structure for representing a single row of calDB table data.
     10705 */
     10706
     10707typedef struct {
     10708    psS64           cal_id;
     10709    char            *catdir;
     10710    char            *state;
     10711} calDBRow;
     10712
     10713/** Creates a new calDBRow object
     10714 *
     10715 *  @return A new calDBRow object or NULL on failure.
     10716 */
     10717
     10718calDBRow *calDBRowAlloc(
     10719    psS64           cal_id,
     10720    const char      *catdir,
     10721    const char      *state
     10722);
     10723
     10724/** Creates a new calDB table
     10725 *
     10726 * @return true on success
     10727 */
     10728
     10729bool calDBCreateTable(
     10730    psDB            *dbh                ///< Database handle
     10731);
     10732
     10733/** Deletes a calDB table
     10734 *
     10735 * @return true on success
     10736 */
     10737
     10738bool calDBDropTable(
     10739    psDB            *dbh                ///< Database handle
     10740);
     10741
     10742/** Insert a single row into a table
     10743 *
     10744 * This function constructs and inserts a single row based on it's parameters.
     10745 *
     10746 * @return true on success
     10747 */
     10748
     10749bool calDBInsert(
     10750    psDB            *dbh,               ///< Database handle
     10751    psS64           cal_id,
     10752    const char      *catdir,
     10753    const char      *state
     10754);
     10755
     10756/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     10757 *
     10758 * @return A The number of rows removed or a negative value on error
     10759 */
     10760
     10761long long calDBDelete(
     10762    psDB            *dbh,               ///< Database handle
     10763    const psMetadata *where,            ///< Row match criteria
     10764    unsigned long long limit            ///< Maximum number of elements to delete
     10765);
     10766
     10767/** Insert a single calDBRow object into a table
     10768 *
     10769 * This function constructs and inserts a single row based on it's parameters.
     10770 *
     10771 * @return true on success
     10772 */
     10773
     10774bool calDBInsertObject(
     10775    psDB            *dbh,               ///< Database handle
     10776    calDBRow        *object             ///< calDBRow object
     10777);
     10778
     10779/** Insert an array of calDBRow object into a table
     10780 *
     10781 * This function constructs and inserts multiple rows based on it's parameters.
     10782 *
     10783 * @return true on success
     10784 */
     10785
     10786bool calDBInsertObjects(
     10787    psDB            *dbh,               ///< Database handle
     10788    psArray         *objects            ///< array of calDBRow objects
     10789);
     10790
     10791/** Insert data from a binary FITS table calDBRow into the database
     10792 *
     10793 * This function expects a psFits object with a FITS table as the first
     10794 * extension.  The table must have at least one row of data in it, that is of
     10795 * the appropriate format (number of columns and their type).  All other
     10796 * extensions are ignored.
     10797 *
     10798 * @return true on success
     10799 */
     10800
     10801bool calDBInsertFits(
     10802    psDB            *dbh,               ///< Database handle
     10803    const psFits    *fits               ///< psFits object
     10804);
     10805
     10806/** Selects up to limit from the database and returns them in a binary FITS table
     10807 *
     10808 * This function assumes an empty psFits object and will create a FITS table
     10809 * as the first extension.
     10810 *
     10811 *  See psDBSelectRows() for documentation on the format of where.
     10812 *
     10813 * @return true on success
     10814 */
     10815
     10816bool calDBSelectRowsFits(
     10817    psDB            *dbh,               ///< Database handle
     10818    psFits          *fits,              ///< psFits object
     10819    const psMetadata *where,            ///< Row match criteria
     10820    unsigned long long limit            ///< Maximum number of elements to return
     10821);
     10822
     10823/** Convert a calDBRow into an equivalent psMetadata
     10824 *
     10825 * @return A psMetadata pointer or NULL on error
     10826 */
     10827
     10828psMetadata *calDBMetadataFromObject(
     10829    const calDBRow  *object             ///< fooRow to convert into a psMetadata
     10830);
     10831
     10832/** Convert a psMetadata into an equivalent fooRow
     10833 *
     10834 * @return A calDBRow pointer or NULL on error
     10835 */
     10836
     10837calDBRow *calDBObjectFromMetadata(
     10838    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     10839);
     10840/** Selects up to limit rows from the database and returns as calDBRow objects in a psArray
     10841 *
     10842 *  See psDBSelectRows() for documentation on the format of where.
     10843 *
     10844 * @return A psArray pointer or NULL on error
     10845 */
     10846
     10847psArray *calDBSelectRowObjects(
     10848    psDB            *dbh,               ///< Database handle
     10849    const psMetadata *where,            ///< Row match criteria
     10850    unsigned long long limit            ///< Maximum number of elements to return
     10851);
     10852/** Deletes a row from the database coresponding to an calDB
     10853 *
     10854 *  Note that a 'where' search psMetadata is constructed from each object and
     10855 *  used to find rows to delete.
     10856 *
     10857 * @return A The number of rows removed or a negative value on error
     10858 */
     10859
     10860bool calDBDeleteObject(
     10861    psDB            *dbh,               ///< Database handle
     10862    const calDBRow *object    ///< Object to delete
     10863);
     10864/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     10865 *
     10866 *  Note that a 'where' search psMetadata is constructed from each object and
     10867 *  used to find rows to delete.
     10868 *
     10869 * @return A The number of rows removed or a negative value on error
     10870 */
     10871
     10872long long calDBDeleteRowObjects(
     10873    psDB            *dbh,               ///< Database handle
     10874    const psArray   *objects,           ///< Array of objects to delete
     10875    unsigned long long limit            ///< Maximum number of elements to delete
     10876);
     10877/** Formats and prints an array of calDBRow objects
     10878 *
     10879 * When mdcf is set the formated output is in psMetadataConfig
     10880 * format, otherwise it is in a simple tabular format.
     10881 *
     10882 * @return true on success
     10883 */
     10884
     10885bool calDBPrintObjects(
     10886    FILE            *stream,            ///< a stream
     10887    psArray         *objects,           ///< An array of calDBRow objects
     10888    bool            mdcf                ///< format as mdconfig or simple
     10889);
     10890/** Formats and prints an calDBRow object
     10891 *
     10892 * When mdcf is set the formated output is in psMetadataConfig
     10893 * format, otherwise it is in a simple tabular format.
     10894 *
     10895 * @return true on success
     10896 */
     10897
     10898bool calDBPrintObject(
     10899    FILE            *stream,            ///< a stream
     10900    calDBRow *object,    ///< an calDBRow object
     10901    bool            mdcf                ///< format as mdconfig or simple
     10902);
     10903/** calRunRow data structure
     10904 *
     10905 * Structure for representing a single row of calRun table data.
     10906 */
     10907
     10908typedef struct {
     10909    psS64           cal_id;
     10910    char            *region;
     10911    char            *last_step;
     10912    char            *state;
     10913} calRunRow;
     10914
     10915/** Creates a new calRunRow object
     10916 *
     10917 *  @return A new calRunRow object or NULL on failure.
     10918 */
     10919
     10920calRunRow *calRunRowAlloc(
     10921    psS64           cal_id,
     10922    const char      *region,
     10923    const char      *last_step,
     10924    const char      *state
     10925);
     10926
     10927/** Creates a new calRun table
     10928 *
     10929 * @return true on success
     10930 */
     10931
     10932bool calRunCreateTable(
     10933    psDB            *dbh                ///< Database handle
     10934);
     10935
     10936/** Deletes a calRun table
     10937 *
     10938 * @return true on success
     10939 */
     10940
     10941bool calRunDropTable(
     10942    psDB            *dbh                ///< Database handle
     10943);
     10944
     10945/** Insert a single row into a table
     10946 *
     10947 * This function constructs and inserts a single row based on it's parameters.
     10948 *
     10949 * @return true on success
     10950 */
     10951
     10952bool calRunInsert(
     10953    psDB            *dbh,               ///< Database handle
     10954    psS64           cal_id,
     10955    const char      *region,
     10956    const char      *last_step,
     10957    const char      *state
     10958);
     10959
     10960/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     10961 *
     10962 * @return A The number of rows removed or a negative value on error
     10963 */
     10964
     10965long long calRunDelete(
     10966    psDB            *dbh,               ///< Database handle
     10967    const psMetadata *where,            ///< Row match criteria
     10968    unsigned long long limit            ///< Maximum number of elements to delete
     10969);
     10970
     10971/** Insert a single calRunRow object into a table
     10972 *
     10973 * This function constructs and inserts a single row based on it's parameters.
     10974 *
     10975 * @return true on success
     10976 */
     10977
     10978bool calRunInsertObject(
     10979    psDB            *dbh,               ///< Database handle
     10980    calRunRow       *object             ///< calRunRow object
     10981);
     10982
     10983/** Insert an array of calRunRow object into a table
     10984 *
     10985 * This function constructs and inserts multiple rows based on it's parameters.
     10986 *
     10987 * @return true on success
     10988 */
     10989
     10990bool calRunInsertObjects(
     10991    psDB            *dbh,               ///< Database handle
     10992    psArray         *objects            ///< array of calRunRow objects
     10993);
     10994
     10995/** Insert data from a binary FITS table calRunRow into the database
     10996 *
     10997 * This function expects a psFits object with a FITS table as the first
     10998 * extension.  The table must have at least one row of data in it, that is of
     10999 * the appropriate format (number of columns and their type).  All other
     11000 * extensions are ignored.
     11001 *
     11002 * @return true on success
     11003 */
     11004
     11005bool calRunInsertFits(
     11006    psDB            *dbh,               ///< Database handle
     11007    const psFits    *fits               ///< psFits object
     11008);
     11009
     11010/** Selects up to limit from the database and returns them in a binary FITS table
     11011 *
     11012 * This function assumes an empty psFits object and will create a FITS table
     11013 * as the first extension.
     11014 *
     11015 *  See psDBSelectRows() for documentation on the format of where.
     11016 *
     11017 * @return true on success
     11018 */
     11019
     11020bool calRunSelectRowsFits(
     11021    psDB            *dbh,               ///< Database handle
     11022    psFits          *fits,              ///< psFits object
     11023    const psMetadata *where,            ///< Row match criteria
     11024    unsigned long long limit            ///< Maximum number of elements to return
     11025);
     11026
     11027/** Convert a calRunRow into an equivalent psMetadata
     11028 *
     11029 * @return A psMetadata pointer or NULL on error
     11030 */
     11031
     11032psMetadata *calRunMetadataFromObject(
     11033    const calRunRow *object             ///< fooRow to convert into a psMetadata
     11034);
     11035
     11036/** Convert a psMetadata into an equivalent fooRow
     11037 *
     11038 * @return A calRunRow pointer or NULL on error
     11039 */
     11040
     11041calRunRow *calRunObjectFromMetadata(
     11042    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     11043);
     11044/** Selects up to limit rows from the database and returns as calRunRow objects in a psArray
     11045 *
     11046 *  See psDBSelectRows() for documentation on the format of where.
     11047 *
     11048 * @return A psArray pointer or NULL on error
     11049 */
     11050
     11051psArray *calRunSelectRowObjects(
     11052    psDB            *dbh,               ///< Database handle
     11053    const psMetadata *where,            ///< Row match criteria
     11054    unsigned long long limit            ///< Maximum number of elements to return
     11055);
     11056/** Deletes a row from the database coresponding to an calRun
     11057 *
     11058 *  Note that a 'where' search psMetadata is constructed from each object and
     11059 *  used to find rows to delete.
     11060 *
     11061 * @return A The number of rows removed or a negative value on error
     11062 */
     11063
     11064bool calRunDeleteObject(
     11065    psDB            *dbh,               ///< Database handle
     11066    const calRunRow *object    ///< Object to delete
     11067);
     11068/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     11069 *
     11070 *  Note that a 'where' search psMetadata is constructed from each object and
     11071 *  used to find rows to delete.
     11072 *
     11073 * @return A The number of rows removed or a negative value on error
     11074 */
     11075
     11076long long calRunDeleteRowObjects(
     11077    psDB            *dbh,               ///< Database handle
     11078    const psArray   *objects,           ///< Array of objects to delete
     11079    unsigned long long limit            ///< Maximum number of elements to delete
     11080);
     11081/** Formats and prints an array of calRunRow objects
     11082 *
     11083 * When mdcf is set the formated output is in psMetadataConfig
     11084 * format, otherwise it is in a simple tabular format.
     11085 *
     11086 * @return true on success
     11087 */
     11088
     11089bool calRunPrintObjects(
     11090    FILE            *stream,            ///< a stream
     11091    psArray         *objects,           ///< An array of calRunRow objects
     11092    bool            mdcf                ///< format as mdconfig or simple
     11093);
     11094/** Formats and prints an calRunRow object
     11095 *
     11096 * When mdcf is set the formated output is in psMetadataConfig
     11097 * format, otherwise it is in a simple tabular format.
     11098 *
     11099 * @return true on success
     11100 */
     11101
     11102bool calRunPrintObject(
     11103    FILE            *stream,            ///< a stream
     11104    calRunRow *object,    ///< an calRunRow object
     11105    bool            mdcf                ///< format as mdconfig or simple
     11106);
    1070211107
    1070311108/// @}
     
    1070711112#endif
    1070811113
    10709 #endif // MAGICSKYFILEMASK_DB_H
     11114#endif // CALRUN_DB_H
  • trunk/ippdb/tests/alloc.c

    r15533 r15569  
    24322432    }
    24332433
     2434    {
     2435        calDBRow        *object;
     2436
     2437        object = calDBRowAlloc(-64, "a string", "a string"    );
     2438
     2439        if (!object) {
     2440            exit(EXIT_FAILURE);
     2441        }
     2442
     2443        if (!object->cal_id == -64) {
     2444            psFree(object);
     2445            exit(EXIT_FAILURE);
     2446        }
     2447        if (strncmp(object->catdir, "a string", MAX_STRING_LENGTH)) {
     2448            psFree(object);
     2449            exit(EXIT_FAILURE);
     2450        }
     2451        if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {
     2452            psFree(object);
     2453            exit(EXIT_FAILURE);
     2454        }
     2455
     2456        psFree(object);
     2457    }
     2458
     2459    {
     2460        calRunRow       *object;
     2461
     2462        object = calRunRowAlloc(-64, "a string", "a string", "a string"    );
     2463
     2464        if (!object) {
     2465            exit(EXIT_FAILURE);
     2466        }
     2467
     2468        if (!object->cal_id == -64) {
     2469            psFree(object);
     2470            exit(EXIT_FAILURE);
     2471        }
     2472        if (strncmp(object->region, "a string", MAX_STRING_LENGTH)) {
     2473            psFree(object);
     2474            exit(EXIT_FAILURE);
     2475        }
     2476        if (strncmp(object->last_step, "a string", MAX_STRING_LENGTH)) {
     2477            psFree(object);
     2478            exit(EXIT_FAILURE);
     2479        }
     2480        if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {
     2481            psFree(object);
     2482            exit(EXIT_FAILURE);
     2483        }
     2484
     2485        psFree(object);
     2486    }
     2487
    24342488    exit(EXIT_SUCCESS);
    24352489}
  • trunk/ippdb/tests/createtable.c

    r15421 r15569  
    725725    }
    726726
     727    {
     728        psDB            *dbh;
     729
     730        dbh = psDBInit("localhost", "test", NULL, "test");
     731        if (!dbh) {
     732            exit(EXIT_FAILURE);
     733        }
     734
     735        if(!calDBCreateTable(dbh)) {
     736            exit(EXIT_FAILURE);
     737        }
     738
     739        psDBCleanup(dbh);
     740    }
     741
     742    {
     743        psDB            *dbh;
     744
     745        dbh = psDBInit("localhost", "test", NULL, "test");
     746        if (!dbh) {
     747            exit(EXIT_FAILURE);
     748        }
     749
     750        if(!calRunCreateTable(dbh)) {
     751            exit(EXIT_FAILURE);
     752        }
     753
     754        psDBCleanup(dbh);
     755    }
     756
    727757    exit(EXIT_SUCCESS);
    728758}
  • trunk/ippdb/tests/dbcleanup.c

    r15421 r15569  
    5959    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS magicMask");
    6060    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS magicSkyfileMask");
     61    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calDB");
     62    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calRun");
    6163
    6264    psDBCleanup(dbh);
  • trunk/ippdb/tests/dbsetup.c

    r15421 r15569  
    157157    magicSkyfileMaskCreateTable(dbh);
    158158
     159    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calDB");
     160    calDBCreateTable(dbh);
     161
     162    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS calRun");
     163    calRunCreateTable(dbh);
     164
    159165    psDBCleanup(dbh);
    160166
  • trunk/ippdb/tests/droptable.c

    r15421 r15569  
    725725    }
    726726
     727    {
     728        psDB            *dbh;
     729
     730        dbh = psDBInit("localhost", "test", NULL, "test");
     731        if (!dbh) {
     732            exit(EXIT_FAILURE);
     733        }
     734
     735        if (!calDBDropTable(dbh)) {
     736            exit(EXIT_FAILURE);
     737        }
     738
     739        psDBCleanup(dbh);
     740    }
     741
     742    {
     743        psDB            *dbh;
     744
     745        dbh = psDBInit("localhost", "test", NULL, "test");
     746        if (!dbh) {
     747            exit(EXIT_FAILURE);
     748        }
     749
     750        if (!calRunDropTable(dbh)) {
     751            exit(EXIT_FAILURE);
     752        }
     753
     754        psDBCleanup(dbh);
     755    }
     756
    727757    exit(EXIT_SUCCESS);
    728758}
  • trunk/ippdb/tests/insert.c

    r15530 r15569  
    725725    }
    726726
     727    {
     728        psDB            *dbh;
     729
     730        dbh = psDBInit("localhost", "test", NULL, "test");
     731        if (!dbh) {
     732            exit(EXIT_FAILURE);
     733        }
     734
     735        if (!calDBInsert(dbh, -64, "a string", "a string")) {
     736            exit(EXIT_FAILURE);
     737        }
     738
     739        psDBCleanup(dbh);
     740    }
     741
     742    {
     743        psDB            *dbh;
     744
     745        dbh = psDBInit("localhost", "test", NULL, "test");
     746        if (!dbh) {
     747            exit(EXIT_FAILURE);
     748        }
     749
     750        if (!calRunInsert(dbh, -64, "a string", "a string", "a string")) {
     751            exit(EXIT_FAILURE);
     752        }
     753
     754        psDBCleanup(dbh);
     755    }
     756
    727757    exit(EXIT_SUCCESS);
    728758}
  • trunk/ippdb/tests/insertfits.c

    r15421 r15569  
    12571257    }
    12581258
     1259    {
     1260        psDB            *dbh;
     1261        psFits          *fits;
     1262
     1263        dbh = psDBInit("localhost", "test", NULL, "test");
     1264        if (!dbh) {
     1265            exit(EXIT_FAILURE);
     1266        }
     1267
     1268        // open a temp
     1269        fits = psFitsOpen(TMP_FILENAME, "r");
     1270        if (!fits) {
     1271            exit(EXIT_FAILURE);
     1272        }
     1273
     1274        if (!calDBInsertFits(dbh, fits)) {
     1275            exit(EXIT_FAILURE);
     1276        }
     1277
     1278        if (!psFitsClose(fits)) {
     1279            exit(EXIT_FAILURE);
     1280        }
     1281
     1282        psDBCleanup(dbh);
     1283    }
     1284
     1285    {
     1286        psDB            *dbh;
     1287        psFits          *fits;
     1288
     1289        dbh = psDBInit("localhost", "test", NULL, "test");
     1290        if (!dbh) {
     1291            exit(EXIT_FAILURE);
     1292        }
     1293
     1294        // open a temp
     1295        fits = psFitsOpen(TMP_FILENAME, "r");
     1296        if (!fits) {
     1297            exit(EXIT_FAILURE);
     1298        }
     1299
     1300        if (!calRunInsertFits(dbh, fits)) {
     1301            exit(EXIT_FAILURE);
     1302        }
     1303
     1304        if (!psFitsClose(fits)) {
     1305            exit(EXIT_FAILURE);
     1306        }
     1307
     1308        psDBCleanup(dbh);
     1309    }
     1310
    12591311    exit(EXIT_SUCCESS);
    12601312}
  • trunk/ippdb/tests/insertobject.c

    r15530 r15569  
    10611061    }
    10621062
     1063    {
     1064        psDB            *dbh;
     1065        calDBRow        *object;
     1066
     1067        dbh = psDBInit("localhost", "test", NULL, "test");
     1068        if (!dbh) {
     1069            exit(EXIT_FAILURE);
     1070        }
     1071
     1072        object = calDBRowAlloc(-64, "a string", "a string");
     1073        if (!object) {
     1074            exit(EXIT_FAILURE);
     1075        }
     1076
     1077        if (!calDBInsertObject(dbh, object)) {
     1078            exit(EXIT_FAILURE);
     1079        }
     1080
     1081        psFree(object);
     1082        psDBCleanup(dbh);
     1083    }
     1084
     1085    {
     1086        psDB            *dbh;
     1087        calRunRow       *object;
     1088
     1089        dbh = psDBInit("localhost", "test", NULL, "test");
     1090        if (!dbh) {
     1091            exit(EXIT_FAILURE);
     1092        }
     1093
     1094        object = calRunRowAlloc(-64, "a string", "a string", "a string");
     1095        if (!object) {
     1096            exit(EXIT_FAILURE);
     1097        }
     1098
     1099        if (!calRunInsertObject(dbh, object)) {
     1100            exit(EXIT_FAILURE);
     1101        }
     1102
     1103        psFree(object);
     1104        psDBCleanup(dbh);
     1105    }
     1106
    10631107    exit(EXIT_SUCCESS);
    10641108}
  • trunk/ippdb/tests/metadatafromobject.c

    r15533 r15569  
    27372737    }
    27382738
     2739    {
     2740        psMetadata      *md;
     2741        calDBRow        *object;
     2742        bool            status;
     2743
     2744        object = calDBRowAlloc(-64, "a string", "a string");
     2745        if (!object) {
     2746            exit(EXIT_FAILURE);
     2747        }
     2748
     2749        md = calDBMetadataFromObject(object);
     2750        if (!md) {
     2751            exit(EXIT_FAILURE);
     2752        }
     2753
     2754        psFree(object);
     2755
     2756            psFree(md);
     2757            exit(EXIT_FAILURE);
     2758        }
     2759        if (strncmp(psMetadataLookupPtr(&status, md, "catdir"), "a string", MAX_STRING_LENGTH)) {
     2760            psFree(md);
     2761            exit(EXIT_FAILURE);
     2762        }
     2763        if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) {
     2764            psFree(md);
     2765            exit(EXIT_FAILURE);
     2766        }
     2767
     2768        psFree(md);
     2769    }
     2770
     2771    {
     2772        psMetadata      *md;
     2773        calRunRow       *object;
     2774        bool            status;
     2775
     2776        object = calRunRowAlloc(-64, "a string", "a string", "a string");
     2777        if (!object) {
     2778            exit(EXIT_FAILURE);
     2779        }
     2780
     2781        md = calRunMetadataFromObject(object);
     2782        if (!md) {
     2783            exit(EXIT_FAILURE);
     2784        }
     2785
     2786        psFree(object);
     2787
     2788            psFree(md);
     2789            exit(EXIT_FAILURE);
     2790        }
     2791        if (strncmp(psMetadataLookupPtr(&status, md, "region"), "a string", MAX_STRING_LENGTH)) {
     2792            psFree(md);
     2793            exit(EXIT_FAILURE);
     2794        }
     2795        if (strncmp(psMetadataLookupPtr(&status, md, "last_step"), "a string", MAX_STRING_LENGTH)) {
     2796            psFree(md);
     2797            exit(EXIT_FAILURE);
     2798        }
     2799        if (strncmp(psMetadataLookupPtr(&status, md, "state"), "a string", MAX_STRING_LENGTH)) {
     2800            psFree(md);
     2801            exit(EXIT_FAILURE);
     2802        }
     2803
     2804        psFree(md);
     2805    }
     2806
    27392807    exit(EXIT_SUCCESS);
    27402808}
  • trunk/ippdb/tests/objectfrommetadata.c

    r15533 r15569  
    43144314    }
    43154315
     4316    {
     4317        psMetadata      *md;
     4318        calDBRow        *object;
     4319
     4320        md = psMetadataAlloc();
     4321            psFree(md);
     4322            exit(EXIT_FAILURE);
     4323        }
     4324        if (!psMetadataAddStr(md, PS_LIST_TAIL, "catdir", 0, NULL, "a string")) {
     4325            psFree(md);
     4326            exit(EXIT_FAILURE);
     4327        }
     4328        if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) {
     4329            psFree(md);
     4330            exit(EXIT_FAILURE);
     4331        }
     4332
     4333        object = calDBObjectFromMetadata(md);
     4334        if (!object) {
     4335            psFree(md);
     4336            exit(EXIT_FAILURE);
     4337        }
     4338
     4339        psFree(md);
     4340
     4341            psFree(object);
     4342            exit(EXIT_FAILURE);
     4343        }
     4344        if (strncmp(object->catdir, "a string", MAX_STRING_LENGTH)) {
     4345            psFree(object);
     4346            exit(EXIT_FAILURE);
     4347        }
     4348        if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {
     4349            psFree(object);
     4350            exit(EXIT_FAILURE);
     4351        }
     4352
     4353        psFree(object);
     4354    }
     4355
     4356    {
     4357        psMetadata      *md;
     4358        calRunRow       *object;
     4359
     4360        md = psMetadataAlloc();
     4361            psFree(md);
     4362            exit(EXIT_FAILURE);
     4363        }
     4364        if (!psMetadataAddStr(md, PS_LIST_TAIL, "region", 0, NULL, "a string")) {
     4365            psFree(md);
     4366            exit(EXIT_FAILURE);
     4367        }
     4368        if (!psMetadataAddStr(md, PS_LIST_TAIL, "last_step", 0, NULL, "a string")) {
     4369            psFree(md);
     4370            exit(EXIT_FAILURE);
     4371        }
     4372        if (!psMetadataAddStr(md, PS_LIST_TAIL, "state", 0, NULL, "a string")) {
     4373            psFree(md);
     4374            exit(EXIT_FAILURE);
     4375        }
     4376
     4377        object = calRunObjectFromMetadata(md);
     4378        if (!object) {
     4379            psFree(md);
     4380            exit(EXIT_FAILURE);
     4381        }
     4382
     4383        psFree(md);
     4384
     4385            psFree(object);
     4386            exit(EXIT_FAILURE);
     4387        }
     4388        if (strncmp(object->region, "a string", MAX_STRING_LENGTH)) {
     4389            psFree(object);
     4390            exit(EXIT_FAILURE);
     4391        }
     4392        if (strncmp(object->last_step, "a string", MAX_STRING_LENGTH)) {
     4393            psFree(object);
     4394            exit(EXIT_FAILURE);
     4395        }
     4396        if (strncmp(object->state, "a string", MAX_STRING_LENGTH)) {
     4397            psFree(object);
     4398            exit(EXIT_FAILURE);
     4399        }
     4400
     4401        psFree(object);
     4402    }
     4403
    43164404    exit(EXIT_SUCCESS);
    43174405}
  • trunk/ippdb/tests/selectrowsfits.c

    r15421 r15569  
    10631063    }
    10641064
     1065    {
     1066        psDB            *dbh;
     1067        psFits          *fits;
     1068
     1069        dbh = psDBInit("localhost", "test", NULL, "test");
     1070        if (!dbh) {
     1071            exit(EXIT_FAILURE);
     1072        }
     1073
     1074        fits = psFitsOpen(TMP_FILENAME, "w");
     1075        if (!fits) {
     1076            exit(EXIT_FAILURE);
     1077        }
     1078
     1079        if (!calDBSelectRowsFits(dbh, fits, NULL, 1)) {
     1080            exit(EXIT_FAILURE);
     1081        }
     1082
     1083        psFree(fits);
     1084        psDBCleanup(dbh);
     1085    }
     1086
     1087    {
     1088        psDB            *dbh;
     1089        psFits          *fits;
     1090
     1091        dbh = psDBInit("localhost", "test", NULL, "test");
     1092        if (!dbh) {
     1093            exit(EXIT_FAILURE);
     1094        }
     1095
     1096        fits = psFitsOpen(TMP_FILENAME, "w");
     1097        if (!fits) {
     1098            exit(EXIT_FAILURE);
     1099        }
     1100
     1101        if (!calRunSelectRowsFits(dbh, fits, NULL, 1)) {
     1102            exit(EXIT_FAILURE);
     1103        }
     1104
     1105        psFree(fits);
     1106        psDBCleanup(dbh);
     1107    }
     1108
    10651109    exit(EXIT_SUCCESS);
    10661110}
Note: See TracChangeset for help on using the changeset viewer.