TARRAYDATA AND Eof()

Post Reply
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

TARRAYDATA AND Eof()

Post 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 ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: TARRAYDATA AND Eof()

Post 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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: TARRAYDATA AND Eof()

Post by vilian »

Thanks ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: TARRAYDATA AND Eof()

Post 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
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: TARRAYDATA AND Eof()

Post 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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
vilian
Posts: 795
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: TARRAYDATA AND Eof()

Post by vilian »

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
nnicanor
Posts: 296
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: TARRAYDATA AND Eof()

Post 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


 
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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: TARRAYDATA AND Eof()

Post 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] )
 
Regards

G. N. Rao.
Hyderabad, India
nnicanor
Posts: 296
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: TARRAYDATA AND Eof()

Post by nnicanor »

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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: TARRAYDATA AND Eof()

Post 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] )
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply