[RB] Newbie warning !! A few questions
Charles Yeomans
yeomans at desuetude.com
Mon Aug 25 09:40:54 CDT 2003
On Monday, August 25, 2003, at 06:13 AM, Jan Erik Moström wrote:
> Hi
>
> Once every 6 months or so I start learning using Valentina and every
> time something happens so I have to wait another 6 months 8-) Well,
> it's
> time again and I need to clarify a few things. I'm making a simple
> database with 6 related tables in order to learn Valentina for future
> use.
>
>
> If I create a database and add a baseobject (class 'P') that represents
> people then this represents the whole table, right?
>
> If I want to treat a person as an object (and have several such objects
> available at the same time ... no, not a listing but for editing) then
> I
> need to create another class 'RealPerson'. When I need an instance of
> 'RealPerson' I should request if from 'P' (who either creates a new
> record or return an existing depending on the situtation), right?
>
> If I need to save the changes to a 'RealPerson' object, then I should
> call 'P' with this object as a parameter, right? ('P' looks up which
> record needs updateing and updates it)
>
> To do this, I need some way to uniqely identify the person in the 'P'
> table using some data in the 'RealPerson' object. Should I assign a
> unique identifier myself or is this one use for the VObjectPtr/RecID?
Use the recID value.
In general, what I have is an abstract PersistentObject class that has
a function ID() as Integer, and subroutines Retrieve(theID as Integer)
and Save() (and other methods, of course). Internally there is a
protected property recID as Integer. I have two events
MapCursorToObject(c as VCursor) and MapObjectToCursor(c as VCursor)
that I implement in subclasses. Here's some code.
Charles Yeomans
Sub Retrieve(theID as Integer)
Const methodName = "Retrieve"
dim c as VCursor
dim db as VDataBase
dim bo as boPersistentClass
dim query as DBQuery
If me.IsNull then
Return
End if
bo = boPersistentClass(me.manager.baseObject)
db = bo.DataBase
query = app.DB.NewQuery
query.AddAllFields bo
query.AddTable bo
query.WhereCondition = new WHERENodeEquals(bo.RecID, theID)
query.ReadOnly = true
c = query.Cursor
If c.FirstRecord then
me.recID = theID
me.lastUpdate = c.DoubleField(bo.lastChanged.name).value
me.pHasBeenDeleted = c.BooleanField(bo.HasBeenDeleted.name).value
MapCursorToObject c
End if
Retrieved //new event
c = nil
Exception oops
LogException oops, me.ClassName, methodName
End Sub
Sub Save()
Const methodName = "Save"
dim db as VDataBase
dim bo as boPersistentClass
dim query as DBQuery
dim c as VCursor
dim d as Date
If me.IsNull then
Return
End if
bo = me.manager.baseObject
db = bo.DataBase
If me.recID = 0 then
me.Create
End if
Saving //new event --provides a hook for setting object properties
query = app.DB.NewQuery
query.ReadOnly = false
query.AddAllFields bo
query.AddTable bo
query.WhereCondition = new WHERENodeEquals(bo.RecID, me.recID)
c = query.Cursor
MapObjectToCursor c
d = new Date
c.DoubleField(bo.lastChanged.name).value = d.TotalSeconds
c.BooleanField(bo.HasBeenDeleted.name).value = me.ToBeDeleted
me.pHasBeenDeleted = me.ToBeDeleted
If c.Update then
bo.Flush
Saved //new event -- provides a hook for saving associated objects
me.Manager.AnnounceUpdate me
c = nil
Else
Raise new ValentinaException(db)
End if
Exception oops
LogException oops, me.ClassName, methodName
End Sub
More information about the Valentina
mailing list