TARRAYDATA AND Eof()

TARRAYDATA AND Eof()

Postby vilian » Wed Jul 24, 2019 12:24 pm

I'm trying to do this:

Code: Select all  Expand view

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
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: TARRAYDATA AND Eof()

Postby nageswaragunupudi » Wed Jul 24, 2019 1:17 pm

You are right.
As a workaround, please do this way
Code: Select all  Expand view

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TARRAYDATA AND Eof()

Postby vilian » Wed Jul 24, 2019 1:26 pm

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

Re: TARRAYDATA AND Eof()

Postby vilian » Wed Jul 24, 2019 1:33 pm

It's working, but the last item of the aData is not processed!
I have to change to this:
Code: Select all  Expand view

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
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: TARRAYDATA AND Eof()

Postby nageswaragunupudi » Wed Jul 24, 2019 2:06 pm

Please try
Code: Select all  Expand view

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

Re: TARRAYDATA AND Eof()

Postby vilian » Wed Jul 24, 2019 2: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
User avatar
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: TARRAYDATA AND Eof()

Postby nnicanor » Mon Oct 21, 2019 5:36 am

Hi,

EOF() is not working

Code: Select all  Expand view


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

Re: TARRAYDATA AND Eof()

Postby nageswaragunupudi » Mon Oct 21, 2019 2:11 pm

1) Eof() works in FWH1909.

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

Code: Select all  Expand view

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  Expand view
#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  Expand view

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TARRAYDATA AND Eof()

Postby nnicanor » Thu Oct 24, 2019 4: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
nnicanor
 
Posts: 302
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: TARRAYDATA AND Eof()

Postby nageswaragunupudi » Thu Oct 24, 2019 4: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: Select all  Expand view

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: russimicro and 45 guests