DeleteObject

DeleteObject read in an object an marks it for deletion, the object remains within the database until CommitTransaction is called, this operation can be undone by calling RestoreObjectbefore commiting the transaction if an incorrect object is found.
unsigned __int64 DeleteObject (
   unsigned int tableID,
   __int64 objectID = 0,
   CODBPP::Object *object = NULL
);
unsigned __int64 DeleteObject (
   unsigned int tableID,
   CODBPP::Mode operation,
   CODBPP::Object *object = NULL,
   unsigned int index = 0,
   const void *key = NULL,
   unsigned int *matchingRow = NULL
);

Parameters

tableIDthe table ID defining the table's handle.
objectIDthe object ID defining the object's handle when using the shorthand version.
operationvalid operations only.
objectfor the returned object addresses.
indexthe index value, 0 for object ID hash index, 1 for the first defined index.
keythe key value used in any find comparison.
matchingRowused to identify which row of a sub-table field, within the current object has the matching multi-entry index value.

Return Values

If the method succeeds, the return value is zero else see error codes for more details.

Remarks

  • Once DeleteObject has deleted an object, all the index values held by that object can be reused by any other object during the transaction, except for the objectID which is not reusable.
  • If the objectID is zero (0), then DeleteObject will try and delete the last object successfully read by ReadObject.
  • DeleteObject will not delete an added object, use RestoreObject RestoreObject to delete and added object.
  • DeleteObject will attempt to lock twenty times longer if the object is above the transaction’s high water mark, if the object is below the mark than DeleteObject will return an error if unable to gain object lock.
  • DeleteObject will allow the operation of NO_WAIT and SHORT_WAIT if the object is known to be locked and there is little need to wait the entire timeout period before returning CODBPP::UNABLE_TO_LOCK_OBJECT.
Example Use
  • C++
#include "ODBPP.h"

int wmain(int argc, wchar_t* argv[])
{
   unsigned __int64 error, result;
   const char16_t *message, *userName = u"UserName";
   CODBPP database;
   CODBPP::Object object;
   struct FixedObject{
      int First;
      double Second;
   } *fixedObject;
   if((error = database.BeginTransaction()) == NO_ERROR){
      if((error = database.OpenTable(1)) == NO_ERROR){
         if((result = database.DeleteObject(
                   1,CODBPP::EQUALTO,&object,1,userName)) == NO_ERROR){
            fixedObject = (struct FixedObject*)object.fixed;
            if(fixedObject->First == 123 && fixedObject->Second == 0)
               error = database.CommitTransaction();
            else error = database.AbortTransaction();
         }
         else if(ERROR_MASK(result) == CODBPP::NOT_FOUND_INDEX_KEY)
             MessageBox(u"User not found");
         else error = result;
      }
   }
   if(error && database.GetErrorMessage(&message) == NO_ERROR)
      MessageBox(message);
   database.EndTransaction();
   return NO_ERROR;
}

Also See

AddObject, NewObject, ReadObject, RewriteObject, RestoreObject
Listen All
Comments (0)
Characters left: 2500
 
Ekky Software Homepage T-Accounts Online ObjectDatabase++ TScript Ekky Software Homepage T-Accounts Onlinee ObjectDatabase++ TScript