Logo Search packages:      
Sourcecode: dballe version File versions

F77_INTEGER_FUNCTION() idba_preparati ( INTEGER(dbahandle)  ,
INTEGER(handle)  ,
CHARACTER(anaflag)  ,
CHARACTER(dataflag)  ,
TRAIL(attrflag)   
)

Starts a session with dballe.

You can call idba_preparati() many times and get more handles. This allows to perform many operations on the database at the same time.

idba_preparati() has three extra parameters that can be used to limit write operations on the database, as a limited protection against programming errors.

Note that some combinations of parameters are illegal, such as anaflag=read and dataflag=add (when adding a new data, it's sometimes necessary to insert new pseudoana records), or dataflag=rewrite and qcflag=read (when deleting data, their attributes are deleted as well).

Parameters:
dbahandle The main DB-ALLe connection handle
Return values:
handle The session handle returned by the function
Parameters:
anaflag Controls access to pseudoana records and can have these values:
  • "read" pseudoana records cannot be inserted.
  • "write" it is possible to insert and delete pseudoana records.
dataflag Controls access to observed data and can have these values:
  • "read" data cannot be modified in any way.
  • "add" data can be added to the database, but existing data cannot be modified. Deletions are disabled. This is used to insert new data in the database while preserving the data that was already present in it.
  • "write" data can freely be added, overwritten and deleted.
qcflag Controls access to data attributes and can have these values:
  • "read" attributes cannot be modified in any way.
  • "add" attributes can can be added to the database, but existing attributes cannot be modified. Deletion of attributes is disabled. This is used to insert new attribute in the database while preserving the attributes that were already present in it.
  • "write" attributes can freely be added, overwritten and deleted.
Returns:
The error indication for the function.

Definition at line 314 of file simple.c.

References dba_error_consistency, DBA_RUN_OR_GOTO, and DBA_RUN_OR_RETURN.

{
      GENPTR_INTEGER(dbahandle)
      GENPTR_INTEGER(handle)
      GENPTR_CHARACTER(anaflag)
      GENPTR_CHARACTER(dataflag)
      GENPTR_CHARACTER(attrflag)
      dba_err err;

      /* Check here to warn users of the introduction of idba_presentati */
      /*
      if (session == NULL)
            return dba_error_consistency("idba_presentati should be called before idba_preparati");
      */

      /* Allocate and initialize a new handle */
      DBA_RUN_OR_RETURN(fdba_handle_alloc_simple(handle));

      STATE.session = *dbahandle;
      STATE.perms = 0;
      STATE.input = NULL;
      STATE.output = NULL;
      STATE.qcinput = NULL;
      STATE.qcoutput = NULL;
      STATE.ana_cur = NULL;
      STATE.query_cur = NULL;

      if (check_flag("read",  anaflag,  anaflag_length))
            STATE.perms |= PERM_ANA_RO;
      if (check_flag("write", anaflag,  anaflag_length))
            STATE.perms |= PERM_ANA_WRITE;
      if (check_flag("read",  dataflag, dataflag_length))
            STATE.perms |= PERM_DATA_RO;
      if (check_flag("add",   dataflag, dataflag_length))
            STATE.perms |= PERM_DATA_ADD;
      if (check_flag("write", dataflag, dataflag_length))
            STATE.perms |= PERM_DATA_WRITE;
      if (check_flag("read",  attrflag,   attrflag_length))
            STATE.perms |= PERM_ATTR_RO;
      if (check_flag("add",   attrflag,   attrflag_length))
            STATE.perms |= PERM_ATTR_ADD;
      if (check_flag("write", attrflag,   attrflag_length))
            STATE.perms |= PERM_ATTR_WRITE;

      if ((STATE.perms & (PERM_ANA_RO | PERM_ANA_WRITE)) == 0)
            return dba_error_consistency("pseudoana should be opened in either 'read' or 'write' mode");
      if ((STATE.perms & (PERM_DATA_RO | PERM_DATA_ADD | PERM_DATA_WRITE)) == 0)
            return dba_error_consistency("data should be opened in one of 'read', 'add' or 'write' mode");
      if ((STATE.perms & (PERM_ATTR_RO | PERM_ATTR_ADD | PERM_ATTR_WRITE)) == 0)
            return dba_error_consistency("attr should be opened in one of 'read', 'add' or 'write' mode");

      if (STATE.perms & PERM_ANA_RO && STATE.perms & PERM_DATA_WRITE)
            return dba_error_consistency("when data is 'write' ana must also be set to 'write', because deleting data can potentially also delete pseudoana");
      if (STATE.perms & PERM_ATTR_RO && STATE.perms & PERM_DATA_WRITE)
            return dba_error_consistency("when data is 'write' attr must also be set to 'write', because deleting data also delete its attributes");
      
      /* Allocate the records */
      DBA_RUN_OR_GOTO(fail, dba_record_create(&(STATE.input)));
      DBA_RUN_OR_GOTO(fail, dba_record_create(&(STATE.output)));
      DBA_RUN_OR_GOTO(fail, dba_record_create(&(STATE.qcinput)));
      DBA_RUN_OR_GOTO(fail, dba_record_create(&(STATE.qcoutput)));

      return dba_error_ok();

fail:
      if (STATE.qcoutput != NULL)
            dba_record_delete(STATE.qcoutput);
      if (STATE.qcinput != NULL)
            dba_record_delete(STATE.qcinput);
      if (STATE.output != NULL)
            dba_record_delete(STATE.output);
      if (STATE.input != NULL)
            dba_record_delete(STATE.input);

      fdba_handle_release_simple(*handle);

      return err;
}


Generated by  Doxygen 1.6.0   Back to index