IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 13, 2008, 5:41:31 PM (18 years ago)
Author:
bills
Message:

Implemented the commands to manage the data store

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pstamptool.c

    r16361 r16471  
    3333static bool adddatastoreMode(pxConfig *config);
    3434static bool datastoreMode(pxConfig *config);
     35static bool moddatastoreMode(pxConfig *config);
    3536static bool addReqMode(pxConfig *config);
    3637static bool pendingReqMode(pxConfig *config);
     
    6263        MODECASE(PSTAMPTOOL_MODE_ADDDATASTORE, adddatastoreMode);
    6364        MODECASE(PSTAMPTOOL_MODE_DATASTORE, datastoreMode);
     65        MODECASE(PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreMode);
    6466        MODECASE(PSTAMPTOOL_MODE_ADDREQ, addReqMode);
    6567        MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode);
     
    9294static bool adddatastoreMode(pxConfig *config)
    9395{
    94     psError(PS_ERR_UNKNOWN, true, "-adddatastore not implemented yet");
    95     return false;
    96 #ifdef notyet
    9796    PS_ASSERT_PTR_NON_NULL(config, false);
    9897
    9998    bool status = false;
    100     psString camera = psMetadataLookupStr(&status, config->args, "-inst");
    101     if (!status) {
    102         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
    103         return false;
    104     }
    105     if (!camera) {
    106         psError(PS_ERR_UNKNOWN, true, "-inst is required");
    107         return false;
    108     }
    109 
    110     psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
    111     if (!status) {
    112         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
    113         return false;
    114     }
    115     if (!telescope) {
    116         psError(PS_ERR_UNKNOWN, true, "-telescope is required");
    117         return false;
    118     }
    119 
    12099    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    121100    if (!status) {
     
    128107    }
    129108
    130     if (!pzDataStoreInsert(config->dbh,
    131             camera,
    132             telescope,
    133             uri
     109    psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
     110
     111    if (!pstampDataStoreInsert(config->dbh,
     112            0,
     113            uri,
     114            lastFileset
    134115        )) {
    135116        psError(PS_ERR_UNKNOWN, false, "database error");
     
    138119
    139120    return true;
    140 #endif // notyet
    141121}
    142122
    143123static bool datastoreMode(pxConfig *config)
    144124{
    145     psError(PS_ERR_UNKNOWN, true, "-datastore not implemented yet");
    146     return false;
    147 
    148 #ifdef notyet
    149     PS_ASSERT_PTR_NON_NULL(config, false);
    150 
    151     if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pzDataStore")) {
     125    PS_ASSERT_PTR_NON_NULL(config, false);
     126
     127    if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pstampDataStore")) {
    152128        psError(PS_ERR_UNKNOWN, false, "database error");
    153129        return false;
     
    176152
    177153    // negative simple so the default is true
    178     if (!ippdbPrintMetadatas(stdout, output, "pzDataStore", !simple)) {
     154    if (!ippdbPrintMetadatas(stdout, output, "pstampDataStore", !simple)) {
    179155        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    180156        psFree(output);
     
    185161
    186162    return true;
    187 #endif // notyet
     163}
     164static bool moddatastoreMode(pxConfig *config)
     165{
     166    bool    status;
     167
     168    PS_ASSERT_PTR_NON_NULL(config, false);
     169
     170    psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
     171    if (!status) {
     172        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
     173        return false;
     174    }
     175    if (!ds_id) {
     176        psError(PS_ERR_UNKNOWN, true, "-ds_id is required");
     177        return false;
     178    }
     179    psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
     180    if (!status) {
     181        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -last_fileset");
     182        return false;
     183    }
     184    if (!lastFileset) {
     185        psError(PS_ERR_UNKNOWN, true, "-last_fileset is required");
     186        return false;
     187    }
     188
     189    char *query ="UPDATE pstampDataStore"
     190                 " SET lastFileset = '%s'"
     191                 " WHERE ds_id = '%s'";
     192
     193    if (!p_psDBRunQuery(config->dbh, query, lastFileset, ds_id)) {
     194        psError(PS_ERR_UNKNOWN, false, "database error");
     195        psFree(query);
     196        return false;
     197    }
     198
     199    psU64 affected = psDBAffectedRows(config->dbh);
     200    if (affected != 1) {
     201        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
     202                                        PRIu64 " rows were modified", affected);
     203        return false;
     204    }
     205
     206    return true;
    188207}
    189208
     
    204223    }
    205224
     225    // Data Store ID is optional
     226    psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
     227    if (!status) {
     228        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
     229        return false;
     230    }
     231    if (!ds_id) {
     232        ds_id = "0";
     233    }
     234
    206235    char *query ="INSERT INTO pstampRequest"
    207                  " (state, uri)"
    208                  " VALUES( 'new', '%s')";
    209 
    210     if (!p_psDBRunQuery(config->dbh, query, uri)) {
     236                 " (state, uri, ds_id)"
     237                 " VALUES( 'new', '%s', %s)";
     238
     239    if (!p_psDBRunQuery(config->dbh, query, uri, ds_id)) {
    211240        psError(PS_ERR_UNKNOWN, false, "database error");
    212241        psFree(query);
     
    595624        return false;
    596625    }
    597     psString jobStatus = psMetadataLookupStr(&status, config->args, "-status");
    598     if (!status) {
    599         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -status");
    600         return false;
    601     }
    602 
    603     psString statusStr = NULL;
    604     if (!jobStatus) {
    605         statusStr = psStringCopy("");
     626    psString jobResult = psMetadataLookupStr(&status, config->args, "-result");
     627    if (!status) {
     628        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -result");
     629        return false;
     630    }
     631
     632    psString resultStr = NULL;
     633    if (!jobResult) {
     634        resultStr = psStringCopy("");
    606635    } else {
    607         psStringAppend(&statusStr, ", status = '%s'", jobStatus);
     636        psStringAppend(&resultStr, ", result = '%s'", jobResult);
    608637    }
    609638       
     
    615644                 " WHERE job_id = '%s'";
    616645
    617     if (!p_psDBRunQuery(config->dbh, query, state, statusStr, job_id)) {
    618         psError(PS_ERR_UNKNOWN, false, "database error");
    619         psFree(query);
    620         return false;
    621     }
    622     psFree(statusStr);
     646    if (!p_psDBRunQuery(config->dbh, query, state, resultStr, job_id)) {
     647        psError(PS_ERR_UNKNOWN, false, "database error");
     648        psFree(query);
     649        return false;
     650    }
     651    psFree(resultStr);
    623652
    624653    psU64 affected = psDBAffectedRows(config->dbh);
Note: See TracChangeset for help on using the changeset viewer.