Deleting Properties and Records

You can delete individual properties from a record using CeWriteRecordProps, or delete all properties in the record using the function CeDeleteRecord.

Listing 4.12 shows how to delete the "propCompanyTel" property from the first database record (which is the current record when the database is opened). The propDelete CEPROPVAL is initialized with the property id of the property to delete. CEDB_PROPDELETE is used for wFlags, and this indicates that the property is to be deleted. Next, the record's object identifier must be obtained, since this is required by CeWriteRecordProps when manipulating an existing record. The easiest way to do this is to call CeSeekDatabase to seek the current record, and this returns the current record's object identifier.

CeWriteRecordProps can then be called, passing in the record's object identifier, the number of properties to delete (1 in this case), and a pointer to the CEPROPVAL structure describing the properties to delete.

Listing 4.12. Deletes a property value
void Listing4_12()
{
  HANDLE hDB = Listing4_4(); // open database
  if(hDB != INVALID_HANDLE_VALUE)
  {
    CEPROPVAL propDelete;
    CEOID oidRec;
    DWORD dwIndex;
    propDelete.propid = propCompanyTel;
    propDelete.wFlags = CEDB_PROPDELETE;
    propDelete.val.lpwstr = NULL;
    oidRec = CeSeekDatabase(hDB,
      CEDB_SEEK_CURRENT, 0, &dwIndex);
    if(CeWriteRecordProps(hDB,
      oidRec,
        1, // number of properties to delete
        &propDelete))
      cout ≪ _T("Property deleted") ≪ endl;
    else
      cout ≪ _T("Could not delete property")
           ≪ endl;
    Listing4_5(hDB); // close database
  }
}

An entire record can be deleted by calling CeDeleteRecord. This too needs the record's object identifier. Listing 4.13 obtains the object identifier for the first record in the database (which is the current record when the database is opened), and passes this to CeDeleteRecord.

Listing 4.13. Deletes entire record
void Listing4_13()
{
  HANDLE hDB = Listing4_4(); // open database
  if(hDB != INVALID_HANDLE_VALUE)
  {
    CEOID oidRec;
    DWORD dwIndex;
    oidRec = CeSeekDatabase(hDB,
       CEDB_SEEK_CURRENT, 0, &dwIndex);
    if(CeDeleteRecord(hDB, oidRec))
       cout ≪ _T("Record deleted") ≪ endl;
    else
       cout ≪ _T("Could not delete record")
            ≪ endl;
    Listing4_5(hDB); // close database
  }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.171.202