[Valentina][VSDK] M:M problems
Eric Forget
forgete at cafederic.com
Mon Jan 20 11:52:57 CST 2003
Hi Ruslan,
> 2)
> CDatabase::AddPersonToGroup(UInt32 personIndex, UInt32 groupIndex)
>
> In fact you send here RecID of records, yes?
In fact, these indices are NSTableView ones adjusted to be 1 based. I need
to do some conversion between both and it is here it is done. I keep the
FBL_REC_ID encapsulated in CDatabase, by design.
> 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.
Ok, but from my testing it seems to work well. It is cleaner, throw safe
with a lot less code. You should make sure it works!
> 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.
Since I receive NSTableView index (sorted) then to get the personRecID I
need to do the conversion:
bool
CDatabase::GotoGroup(UInt32 index)
{
bool rval;
if ((index > 0) and (index <= mGroupArray->GetCount())) {
FBL_REC_ID recID = (*mGroupArray)(index);
if (mGroup.GetRecID() != recID) {
mGroup.GoToRecord(recID);
}
rval = true;
} else {
rval = false;
}
return rval;
}
Now I can use the mGroup.RecID. Is there an easier way? The point is that I
need the group the bee sorted by its name field...
> 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.
This seems to be a good idea. However, how do I create a such a virtual
field this is a join? I search in the doc but found nothing...
Thanks for your help,
Éric
___________________________________________________________________
Eric Forget Cafederic
ForgetE at cafederic.com <http://www.cafederic.com/>
Fingerprint <86D5 38F5 E1FD 5D9C 71C3 BAA3 797E 70A4 6210 C684>
More information about the Valentina
mailing list