ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8


6 - Record Movements

Adding data to an ebm database is a matter of copying strings into each field of a specified (new or old) record:
  • Create a new CFMRecord object.
  • Use CFMRecord::PutField() to place a string in each field.
  • Use CFMRecord::Add() to place the record in the database
  • If DB_OUT_OF_MEMORY, ask for more memory, and try again
The wrapper function in the source is called RecordAdd(), and is passed an array of strings, one per field entry. The resulting record is added onto the end of the database, so it could also be called 'RecordAppend'.
  DBErr RecordAdd(const ebo_name_t *fileName,char**field)
  {
    CFMRecord record(&m_fMgr);
    DBErr error=record.New();
    if ( DB_OK!=error )
      return error;
    int totalField=m_fMgr.GetNumFields();
    for (int fieldNo=0;fieldNo<totalField;fieldNo++)
    {
      // for each field, add the equivalent string from
      // the array passed in
      if (record.PutField(fieldNo,(U8*)field[fieldNo])) // failed?
      {
        GUI_NeedFileSpace( fileName ); // ask OS & retry
        if ( 0 != (error=record.PutField(fieldNo,(U8*)field[fieldNo])) )
          return error;
      }
    }
    // see if we can add record, and deal with OS if not able to
    if ( DB_OUT_OF_MEMORY==record.Add() )
    {
      GUI_NeedFileSpace( fileName );
      error=record.Add();
      if ( DB_OUT_OF_MEMORY==error )
        return error;
    }
    return record.Close();
  }


Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice