[V4RB] updating records ... where am i going wrong?
Ruslan Zasukhin
sunshine at public.kherson.ua
Mon May 12 21:56:20 CDT 2003
on 5/12/03 8:39 PM, Pedro fp at lists at pedro.net.au wrote:
> My moon table database has a field duration which is the difference in
> new moon time between the current & next moon phase. An important note
> is that the date & time data is as Julian Date Time numbers which are
> doubles that encapsulate both date & time for a given moment which
> means that time differences can be calculated by simple decimal
> subtraction. In my source data file the durations values are faulty so
> I added this method called after import ...
>
> dim i As integer, c As vCursor, b As boolean, nNew, nCur As double
> dim newPhase, newDuration As vDouble
>
> c = mDatabase.SQLselect( "SELECT phase1, duration FROM moon ORDER BY
> phase1" ) ' WHERE RecID > 0
>
> if c.recordCount > 0 then
> ' Assign cursor fields to variables.
> newPhase = c.doubleField( "phase1" )
> newDuration = c.doubleField( "duration" )
>
> for i = 1 to ( c.recordCount - 1 )
> c.currentPosition = i + 1 ' Go to the record ahead.
> nNew = newPhase.value ' Get the next new moon.
> c.currentPosition = i ' Go back to the current record.
> nCur = newPhase.value ' Get the current new moon.
> writeLog "nNew = " + str( nNew ) + ", nCur = " + str( nCur ) + ",
> duration = " + str( nNew - nCur )
> newDuration.value = nNew - nCur ' Set duration as the difference.
> next
>
> b = c.updateAll
> mDatabase.baseObject( "moon" ).flush
> else
> msgBox "Failed to get cursor for updating."
> end if
>
> The writeLog line shows me that the differences are being calculated
> but when the data loads to my listbox all the differences are zero. Any
> clues as to what I'm doing wrong?
You not correctly understand how works UpdateAll().
Think about UpdateAll() as standard SQL command:
UPDATE T set f1 = x WHERE RecID > 0
So ALL records get the same value.
UpdateAll must not be called after loop, but after SIGNLE set of fields
values.
Pedro, I think for you task you should simply use Update()
dim i As integer, c As vCursor, b As boolean, nNew, nCur As double
dim newPhase, newDuration As vDouble
c = mDatabase.SQLselect( "SELECT phase1, duration FROM moon ORDER BY
phase1" ) ' WHERE RecID > 0
if c.recordCount > 0 then
' Assign cursor fields to variables.
newPhase = c.doubleField( "phase1" )
newDuration = c.doubleField( "duration" )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ VERY GOOD :-)
for i = 1 to ( c.recordCount - 1 )
c.currentPosition = i + 1 ' Go to the record ahead.
nNew = newPhase.value ' Get the next new moon.
c.currentPosition = i ' Go back to the current record.
nCur = newPhase.value ' Get the current new moon.
newDuration.value = nNew - nCur ' Set duration as the difference.
c.Update()
next
mDatabase.baseObject( "moon" ).flush
else
msgBox "Failed to get cursor for updating."
end if
--
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://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------
More information about the Valentina
mailing list