Page 1 of 1

TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 12:24 pm
by vilian
I'm trying to do this:

Code: Select all

aData := oQry:GetRows()
oPed  := TArrayData():New( Aclone(aData), oQry:aStructure )
DO WHILE .NOT. oPed:Eof()
      oPed:Skip()
ENDDO
But oPed:Eof() never is returning .T.
Do you know why ?

Re: TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 1:17 pm
by nageswaragunupudi
You are right.
As a workaround, please do this way

Code: Select all

do while oPed:nAt < oPen:KeyCount()
  <do your work>
  oPed:Skip( 1 )
enddo
 

Re: TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 1:26 pm
by vilian
Thanks ;)

Re: TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 1:33 pm
by vilian
It's working, but the last item of the aData is not processed!
I have to change to this:

Code: Select all

nReg := 0
do while nReg < oPen:KeyCount()
  <do your work>
   nReg++  
   oPed:Skip( 1 )
enddo

Re: TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 2:06 pm
by nageswaragunupudi
Please try

Code: Select all

do while .t.
  <do your work>
  if oPed:nAt < oPed:KeyCount()
     oPed:Skip( 1 )
  else
    EXIT
  endif
enddo
 

Re: TARRAYDATA AND Eof()

Posted: Wed Jul 24, 2019 2:09 pm
by vilian
Thank you. It's working now ;)
Will you fix it in the current version of FWH and publish a new build ?

Re: TARRAYDATA AND Eof()

Posted: Mon Oct 21, 2019 5:36 am
by nnicanor
Hi,

EOF() is not working

Code: Select all


    cSql :="Select id, tc, concep, valdeb, descue, valcre,detalle,vence from unicuota where tc='CM' and matric="+ClipValue2Sql( mmm:matric )

   oRs := oCn:RowSet( cSql )

   aData := oRs:GetRows()

   oRs2:= TArrayData():New( AClone(aData) , oRs:aStructure )

   oRs2:GOtop()

   While .t. //  !oRs2:Eof() Commented because don't return .t. and while don't stop 

      cSql2:=cSql2+"update unicuota set valdeb="+ClipValue2Sql( oRs2:valdeb )+",descue="+ClipValue2Sql( oRs2:descue )+" where id="+ ClipValue2Sql( oRs2:id )+";"+CRLF

      if oRs2:nAt = oRs2:KeyCount() // Temporal solution to exit while at end 

         EXIT

      Else

         oRs2:Skip(1)

      Endif

   End


 

Re: TARRAYDATA AND Eof()

Posted: Mon Oct 21, 2019 2:11 pm
by nageswaragunupudi
1) Eof() works in FWH1909.

2) You can also use the method Eval() in FWH1909, instead of writing do while loop.

Code: Select all

oData:Eval( { |Self| ::state := "NY" } )
 

3) From your sample, I understand that you want to read a batch of records from the table, Edit, Modify, Delete. Append all in the memory only and finally, if decide to save, save all the changes at once or discard all changes.

This process is extremely simplified in FWH1909. You can read a query directly into TArrayData object without first reading into a RowSet,

Please build and test this sample:

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn, oData, oRs

   oCn   := FW_DemoDB()

   oData := TArrayData():New( oCn, "SELECT id, first, state, age from customer WHERE state = 'NY'" )

   // Edit/Modify/Delete/Append
   XBROWSER oData FASTEDIT

   if MsgYesNo( "Save Changes?" )
      oData:SaveData()
      ? "Changes saved"
   else
      ? "Changes ignored"
   endif

   // Check the changes
   oRs   := oCn:RowSet( "SELECT id, first, state, age from customer WHERE state = 'NY'" )
   XBROWSER oRs

return nil
 
Image

You can directly read data from mysql/mariadb server into TArrayData using any of the following syntax:

Code: Select all

oData := TArrayData():New( oCn, cTableName, [cWhere] )
//OR
oData := TArrayData():New( oCn, cSql, [aParams] )
 

Re: TARRAYDATA AND Eof()

Posted: Thu Oct 24, 2019 4:04 pm
by nnicanor
Thanks but correct syntax is fromQuery() instead New()

oData:= TarrayData():fromQuery( oCn, "Select ....", aParams )

Regards

Re: TARRAYDATA AND Eof()

Posted: Thu Oct 24, 2019 4:57 pm
by nageswaragunupudi
We advise not to call :fromQuery(...) directly. Please always use New() and let the New() method decide which constructor to call.

New() method can be called with these parameters:

Code: Select all

 :New( aData, [aStruct] )  // for simple arrays
 :New( [cAlias], [bFor], [bWhile], [nNext], [nRec], [lRest] ) // DBF
 :New( oCn, cTable, cWhere ) // MariaDb connection object for MySql
 :New( oCn, cSql, [aParams] )