C H A P T E R 3
Working with Records
Deleting a Record
The sample code in Listing
The sample code then calls its DeleteRecord routine and passes to it the node reference (nodeRef) obtained by calling its MyOpenDirNode routine.
The DeleteRecord routine calls dsDataNodeAllocateString to allocate a data node (recName) containing the string “testuser” as the name of the record that is to be deleted and another data node (recType) specifying kDSStdRecordTypeUsers as the record type of the record that is to be deleted. It then calls dsOpenRecord to open the record that is to be deleted and calls dsDeleteRecord to delete the record.
To reclaim memory associated with recType and recName, the DeleteRecord routine calls dsDataNodeDeAllocate.
The dsDeleteRecord function implicitly closes any record that it deletes. If dsDeleteRecord returns an error, indicating that the record was not deleted, the DeleteRecord routine in Listing
Listing
void main ( )
{
long dirStatus = eDSNoErr; tDirNodeReference nodeRef = NULL; dirStatus = dsOpenDirService( &gDirRef ); if ( dirStatus == eDSNoErr )
{
dirStatus = MyOpenDirNode( &nodeRef ); if ( dirStatus == eDSNoErr )
{
DeleteRecord( nodeRef ); dsCloseDirNode( nodeRef );
}
}
if ( gDirRef != NULL )
{
dirStatus = dsCloseDirService( gDirRef );
}
}
void DeleteRecord ( const tDirNodeReference nodeRef )
{
long dirStatus = eDSNoErr; tRecordReference recRef = NULL; tDataNodePtr recName = NULL; tDataNodePtr recType = NULL;
recName = dsDataNodeAllocateString( gDirRef, "testuser" ); if ( recName != NULL )
{
recType = dsDataNodeAllocateString( gDirRef, kDSStdRecordTypeUsers ); if ( recType != NULL )
{
Deleting a Record | 41 |