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 RestoreObject
before commiting the transaction if an incorrect object is found.
unsigned int DeleteObject (
unsigned int tableID,
__int64 objectID = 0,
CODBPP::Object *object = NULL
);
unsigned int DeleteObject (
unsigned int tableID,
CODBPP::Mode operation,
CODBPP::Object *object = NULL,
unsigned int index = 0,
const void *key = NULL,
unsigned int *matchingRow = NULL
);
Parameters
| tableID |
The table ID defining the table's handle. |
| objectID |
The object ID defining the object's handle when using the shorthand version. |
| operation |
Valid operations only |
| object |
For the returned object addresses. |
| index |
The index value, 0 for object ID hash index, 1 for the first defined index |
| key |
The key value used in any find comparison. |
| matchingRow |
Used 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 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
CODBPP::Object object;
struct FixedObject{
int First;
double Second;
} *fixedObject;
char16_t *userName = _T"UserName";
unsigned int error;
if((error = database.BeginTransaction()) == NO_ERROR){
if((error = database.OpenTable(1)) == NO_ERROR){
if((error = 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 == (0x10000 | CODBPP::NOT_FOUND_INDEX_KEY)){
MessageBox(_T"Object not found");
error = NO_ERROR;
}
}
}
}
if(error && database.GetErrorMessage(&message) == NO_ERROR)
MessageBox(message);
database.EndTransaction();
Also See
AddObject, NewObject,
ReadObject, RestoreObject,
RewriteObject, SearchIndex
Copyright © 2003-2008, Ekky Software Pty. Ltd.