Logo Search packages:      
Sourcecode: dballe version File versions

F77_INTEGER_FUNCTION() idba_prendilo ( INTEGER(handle)   ) 

Insert a new item in the database.

This function will fail if the database is open in data readonly mode, and it will refuse to overwrite existing values if the database is open in data add mode.

If the database is open in pseudoana reuse mode, the pseudoana values provided on input will be used to create a pseudoana record if it is missing, but will be ignored if it is already present. If it is open in pseudoana rewrite mode instead, the pseudoana values on input will be used to replace all the existing pseudoana values.

Parameters:
handle Handle to a DBALLE session
Returns:
The error indicator for the function

Definition at line 1815 of file simple.c.

References dba_error_consistency, DBA_RUN_OR_RETURN, DBA_VAR_X, DBA_VAR_Y, and DBA_VERBOSE_STREAM.

{
      GENPTR_INTEGER(handle)
      int ana_id, context_id;
      dba_record_cursor cur;
      dba_var var = NULL;

      if (STATE.perms & PERM_DATA_RO)
            return dba_error_consistency(
                  "idba_prendilo cannot be called with the database open in data readonly mode");

      if (dba_verbose_is_allowed(DBA_VERB_DB_INPUT))
      {
            dba_verbose(DBA_VERB_DB_INPUT,
                        "invoking dba_insert_or_replace(%d, <input>, %d, %d).  <input> is:\n",
                        *handle,
                        STATE.perms & PERM_DATA_WRITE ? 1 : 0,
                        STATE.perms & PERM_ANA_WRITE ? 1 : 0);
            dba_record_print(STATE.input, DBA_VERBOSE_STREAM);
      }

      DBA_RUN_OR_RETURN(dba_db_insert(
                        SESSION, STATE.input,
                        STATE.perms & PERM_DATA_WRITE ? 1 : 0,
                        STATE.perms & PERM_ANA_WRITE ? 1 : 0,
                        &ana_id, &context_id));

      /* Set the values in the output */
      DBA_RUN_OR_RETURN(dba_record_key_seti(STATE.output, DBA_KEY_ANA_ID, ana_id));
      DBA_RUN_OR_RETURN(dba_record_key_seti(STATE.output, DBA_KEY_CONTEXT_ID, context_id));

      /* Set context id and variable name on qcinput so that
       * attribute functions will refer to what has been written */
      DBA_RUN_OR_RETURN(dba_record_key_seti(STATE.qcinput, DBA_KEY_CONTEXT_ID, context_id));

      /* If there was only one variable in the input, we can pass it on as a
       * default for attribute handling routines; otherwise we unset to mark
       * the ambiguity */
      if ((cur = dba_record_iterate_first(STATE.input)) != NULL &&
                  dba_record_iterate_next(STATE.input, cur) == NULL)
            var = dba_record_cursor_variable(cur);
      
      if (var != NULL)
      {
            dba_varcode code = dba_var_code(var);
            char varname[8];
            snprintf(varname, 7, "B%02d%03d", DBA_VAR_X(code), DBA_VAR_Y(code));
            DBA_RUN_OR_RETURN(dba_record_key_setc(STATE.qcinput, DBA_KEY_VAR_RELATED, varname));
      }
      else
            DBA_RUN_OR_RETURN(dba_record_key_unset(STATE.qcinput, DBA_KEY_VAR_RELATED));

      /* Copy the input on the output, so that QC functions can find the data
       * they need */
      return dba_error_ok();
}


Generated by  Doxygen 1.6.0   Back to index