incomplete understanding of kFBL_CASCADE (or FBL_DeletionControl)

Arthur Clemens aclemens at xs4all.nl
Fri Oct 24 23:49:52 CDT 2003


I am trying to set up a new database for a dictionary.
My new database setup has a hierarchical setup. I have a Record, that 
'holds' the table RecordSection (more sections per record possible), 
and that holds in part 'Word', 'Translation', and so on.
If I delete an entry in the Record table, child entries in 
RecordSection should get deleted too (and eventually Word, Translation, 
but I haven't got that far yet). I can't get it to work, and the code 
examples are sparse.

First, should kFBL_CASCADE work with MacOS X (VSDK Framework)?
If so, I am doing something not right.

Let me show the code, maybe someone can point me out where I am wrong. 
For simplicity I am having all code in header files.

// ----------------------------------------------------------
// Record table class
// ----------------------------------------------------------

class boRecord : public VDK_BaseObject
{
public:
     VDK_Date		mfCreationDate;
     VDK_Date		mfModificationDate;
public:
     boRecord() :
     VDK_BaseObject( "Record" ),
     mfCreationDate( "Creation date" ),
     mfModificationDate( "Modification date" )
     { }
     FBL_EXP virtual FBL_REC_ID AddRecord() {
         this->SetBlank(); // Clear memory buffer of the BaseObject
         // ... some things like setting creation date
         VDK_BaseObject::AddRecord();
         Flush(); // from cache to disk
     }
};

// ----------------------------------------------------------
// RecordSection table class
// ----------------------------------------------------------

class boRecordSection : public VDK_BaseObject
{
public:
     VDK_ObjectPtr mfParentPtr; // pointer to boRecord

public:
     boRecordSection(FBL_REC_ID inRecordId) :
         VDK_BaseObject( "Record section" ),
         mfParentPtr( "Parent", inRecordId, kFBL_CASCADE )
     { }

     void AddRecord(FBL_REC_ID inParentID) {
         this->SetBlank(); // Clear memory buffer of the BaseObject
         // doesn't work, crashes: // mfParentPtr = new VDK_ObjectPtr( 
"RecordPtr", inParentID, kFBL_CASCADE );
         mfParentPtr = inParentID;
         // ... some things like filling Grammar fields (Grammar will be 
a child of boRecordSection)
         VDK_BaseObject::AddRecord();
         Flush(); // from cache to disk
     }
};

// ----------------------------------------------------------
// DatabaseDefinition class
// ----------------------------------------------------------

class DatabaseDefinition : public VDK_DataBase
{
public:
     boRecord* mRecord;
     boRecordSection* mRecordSection;
public:
     DatabaseDefinition() {
         mRecord = new boRecord();
         FBL_REC_ID recordId = mRecord->GetRecID();
         mRecordSection = new boRecordSection(recordId);
         // old: // mRecordSection = new boRecordSection();
     }
     ~DatabaseDefinition() { }
     boRecord* getRecordCountTable() {
         return mRecord;
     }
     void addRecordSectionToRecord(FBL_REC_ID inRecordID) {
         mRecordSection->AddRecord(inRecordID);
     }
     void AddRecord() {
         std::cout << "DatabaseDefinition AddRecord" << endl;
         mRecord->AddRecord();
         FBL_REC_ID newRecordId = mRecord->GetRecID();
         // test: add 3 record sections as children of the new record
         this->addRecordSectionToRecord(newRecordId);
         this->addRecordSectionToRecord(newRecordId);
         this->addRecordSectionToRecord(newRecordId);
         // test: delete the record
         mRecord->DeleteRecord();
         // test: the children should get deleted too
         std::cout << "number of records in Record = " << 
mRecord->GetRecordCount() << endl;
         std::cout << "number of records in RecordSection = " << 
mRecordSection->GetRecordCount() << endl;
         // ... but they don't
     }
};

The last method has the test code where results are going wrong. 
Instead of deleting the record sections I am deleting the record only:
number of records in Record = 0
number of records in RecordSection = 3



Arthur Clemens


More information about the Valentina mailing list