[Valentina][VSDK] M:M problems

Ruslan Zasukhin sunshine at public.kherson.ua
Mon Jan 20 10:31:20 CST 2003


on 1/20/03 4:47 AM, Eric Forget at forgete at cafederic.com wrote:

> And now I'm trying to add a person to a group:
> 
> void
> CDatabase::AddPersonToGroup(UInt32 personIndex, UInt32 groupIndex)
> {
>   if (GotoPerson(personIndex) and GotoGroup(groupIndex)) {
>   
>       char        query[] = "SELECT * FROM GroupPerson WHERE Group.RecID =
> GroupPtr and Person.RecID = PersonPtr";
>       VDK_Cursor  cursor(this);
>       int         count;
>       
>       
>       cursor.ExecuteSQL(query);
>       
>       count = cursor.GetRecordCount();
>       if (count == 0) {
>       
>           // Add a new record in the mGroupPerson table...
>       }
>   }
> }
> 
> The count variable always return 0.
> 
> Also, how do you get an FBL_ArraySet with all the person of a certain group?

Hi Eric,

I will give you several notes.

1) your Table classes are good.


2) 
    CDatabase::AddPersonToGroup(UInt32 personIndex, UInt32 groupIndex)

In fact you send here RecID of records, yes?
Then more correct use FBL_REC_ID type

    CDatabase::AddPersonToGroup( FBL_REC_ID personRecID,
                                 FBL_REC_ID groupRecID)


3) You should not create cursor as stack variable. I just did not check if
this way works correctly. And please use the next way to build cursor:

    VDK_Cursor* c = this->SqlSelect( query );

If you need it only in this function you can use auto_ptr<> or other guards
to destroy cursor automatically.


4) I do not understand very good logic of your function.
As Far as I see You ALREADY have record of Person and Group, and you want
simply link then in table GroupPerson. Yes?

Then I'd write it as:

void CDatabase::AddPersonToGroup(
    FBL_REC_ID personRecID,
    FBL_REC_ID groupRecID)
{
    mGroupPerson.mPersonPtr = personRecID;
    mGroupPerson.mGroupPtr  = groupRecID;

    mGroupPerson.AddRecord();
}


That is all.


5) It seems you try to check that table mGroupPerson do not have such pair
before do add. But then you can do this in the more simple way.

Create BaseObject method -- virtual field in table mGroupPerson, that is
join of both fields and make unique index for it. Now in above my function,
AddRecord() will throw exception in case such pair exists. You may need add
try-catch block to cacth it.

Very simple and much more effective. Payment for this -- third index on
table mGroupPerson on disk. Actually it is possible to do 2 searches on
fields mGroups and mPerson, get 2 BitSet from searches, and do
Intersection() to get result.

Even hard to say what is faster. Because both ways affect speed of Add().
First way with require additional time on adding of pair<> to index,
But it is faster on search of index (because one search on index is faster
of 2 searches on 2 indexes). But first way with third index, require less
work from you, and in fact it put more work on database, and I think this is
good, when logic is stored in db instead of your code.


-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://listserv.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------



More information about the Valentina mailing list