FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TARRAYDATA AND Eof()
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 12:24 PM
I'm trying to do this:

Code (fw): Select all Collapse
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 ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 01:17 PM
You are right.
As a workaround, please do this way
Code (fw): Select all Collapse
do while oPed:nAt < oPen:KeyCount()
  <do your work>
  oPed:Skip( 1 )
enddo
Regards



G. N. Rao.

Hyderabad, India
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 01:26 PM

Thanks ;)

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 01:33 PM
It's working, but the last item of the aData is not processed!
I have to change to this:
Code (fw): Select all Collapse
nReg := 0
do while nReg < oPen:KeyCount()
  <do your work>
   nReg++  
   oPed:Skip( 1 )
enddo
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 02:06 PM
Please try
Code (fw): Select all Collapse
do while .t.
  <do your work>
  if oPed:nAt < oPed:KeyCount()
     oPed:Skip( 1 )
  else
    EXIT
  endif
enddo
Regards



G. N. Rao.

Hyderabad, India
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: TARRAYDATA AND Eof()
Posted: Wed Jul 24, 2019 02:09 PM

Thank you. It's working now ;)
Will you fix it in the current version of FWH and publish a new build ?

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 302
Joined: Fri Apr 23, 2010 04:30 AM
Re: TARRAYDATA AND Eof()
Posted: Mon Oct 21, 2019 05:36 AM
Hi,

EOF() is not working

Code (fw): Select all Collapse
    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
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TARRAYDATA AND Eof()
Posted: Mon Oct 21, 2019 02:11 PM
1) Eof() works in FWH1909.

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

Code (fw): Select all Collapse
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 (fw): Select all Collapse
#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




You can directly read data from mysql/mariadb server into TArrayData using any of the following syntax:
Code (fw): Select all Collapse
oData := TArrayData():New( oCn, cTableName, [cWhere] )
//OR
oData := TArrayData():New( oCn, cSql, [aParams] )
Regards



G. N. Rao.

Hyderabad, India
Posts: 302
Joined: Fri Apr 23, 2010 04:30 AM
Re: TARRAYDATA AND Eof()
Posted: Thu Oct 24, 2019 04:04 PM

Thanks but correct syntax is fromQuery() instead New()

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

Regards

Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TARRAYDATA AND Eof()
Posted: Thu Oct 24, 2019 04:57 PM
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 (fw): Select all Collapse
 :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] )
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion