use fw_arraytodbf with conditions

use fw_arraytodbf with conditions

Postby Silvio.Falconi » Sat Sep 17, 2022 10:35 am

I have an array previously built from a txt file, in this array as the first field there is a date field, I have to convert this array into a dbf file all records if the date field (dUltimaData) is greater than the last passed date

oTemp:= TDatabase():Open( , cPath+"LOTTO", "DBFCDX", .T. )
oTemp:gobottom()
dUltimaData:=oTemp:data


olotto2:= TDatabase():Open( , cPath+"STORICO", "DBFCDX", .T. )
SET DELETED ON
olotto2:setorder(0)
oLotto2:gotop()

//FW_ArrayToDBF( aData, cFieldList, bProgress, lOverWrite, lRecallDeleted, bTrigger )


oLotto2:fw_ArrayToDBF( aData,,bProgress) // how insert conditions ?

I need to create it because when I update the archive the old procedure deletes all the archive and re-insert all the records while it should only add the new records which then if the extraction is not updated is only one the records are only 11 and therefore the end user does not have to wait a long time to update the archive

I tried to create a new array with only the records need to me

oTemp:= TDatabase():Open( , cPath+"LOTTO", "DBFCDX", .T. )
oTemp:gobottom()
dUltimaData:=oTemp:data

For n= 1 to len(aData)
If ctod(aData[1][n]) > dUltimaData
AaDd(aNewData,{aData[1][n],;
aData[2][n],;
aData[3][n],;
aData[4][n],;
aData[5][n],;
aData[6][n],;
aData[7][n]})
Endif
Next

but make me error

Code: Select all  Expand view
Error occurred at: 17-09-2022, 12:56:24
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = A   {"07/01/1939","BA","58","22","47","49","69"} length: 7
     [   2] = N   8

 


wich is 8 ?
Last edited by Silvio.Falconi on Tue Sep 20, 2022 8:29 am, edited 2 times in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: use fw_arraytodbf with conditions

Postby nageswaragunupudi » Sun Sep 18, 2022 1:17 pm

Code: Select all  Expand view
For n= 1 to len(aData)
If ctod(aData[1][n]) > dUltimaData
AaDd(aNewData,{aData[1][n],;
aData[2][n],;
aData[3][n],;
aData[4][n],;
aData[5][n],;
aData[6][n],;
aData[7][n]})
Endif
Next
 

It should be aData[ n, nCol ] or aData[ n ][ nCol ] but not aData[ nCol ][ n ]
When in the for loop "n" exceeds 7, you get this error.
Regards

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

Re: use fw_arraytodbf with conditions

Postby nageswaragunupudi » Sun Sep 18, 2022 6:01 pm

Inserting new records:

For testing, I have used a small portion of the "storico.txt"

We already have some data in STORICO.DBF and now we will try to insert new records.

Image

Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local cText, aData, aNew, dMaxDate

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )

   // for purpose of testing we take a small portion of the Data
   ASIZE( aData, 24)
   //

   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   USE STORICO NEW VIA "DBFCDX" EXCLUSIVE
   XBROWSER ALIAS() SHOW RECID

   DBGOBOTTOM()
   dMaxDate := FIELD->DATA

   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )

   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil
 


Image
Regards

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

Re: use fw_arraytodbf with conditions

Postby Silvio.Falconi » Mon Sep 19, 2022 7:10 am

THANKS RAO
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: use fw_arraytodbf with conditions - RESOLVED

Postby Silvio.Falconi » Mon Sep 19, 2022 11:04 am

Rao,
on my test I have the dMaxDate "10/09/2022"
and on storico.txt I arrive until 2022/09/17
when I execute

aNew := {}
AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
oStorico:FW_ArrayToDbf( anew )

XBROWSER oStorico SHOW RECID

I not see any records

why ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: use fw_arraytodbf with conditions

Postby Silvio.Falconi » Tue Sep 20, 2022 8:17 am

nageswaragunupudi wrote:Inserting new records:

For testing, I have used a small portion of the "storico.txt"

We already have some data in STORICO.DBF and now we will try to insert new records.

Image

Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local cText, aData, aNew, dMaxDate

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )

   // for purpose of testing we take a small portion of the Data
   ASIZE( aData, 24)
   //

   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   USE STORICO NEW VIA "DBFCDX" EXCLUSIVE
   XBROWSER ALIAS() SHOW RECID

   DBGOBOTTOM()
   dMaxDate := FIELD->DATA

   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )

   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil
 


Image





Rao I have problem

give me a xbrowse empty

Please try this test
Code: Select all  Expand view


#include "fivewin.ch"

REQUEST DBFCDX


FUNCTION Main()

   // PUBLIC oApp

   // HB_LangSelect("IT")
   * HB_SetCodePage("ITWIN")

   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF


    Update()

   return nil

//-----------------------------------------------------//

function Update()

   local cText, aData,  aNew, dMaxDate, oLotto
   local aFields :=   { { "DATA" , "D", 8, 0 },;
                        { "RUOTA", "C", 2, 0 },;
                        { "N1"   , "N", 2, 0 },;
                        { "N2"   , "N", 2, 0 },;
                        { "N3"   , "N", 2, 0 },;
                        { "N4"   , "N", 2, 0 },;
                        { "N5"   , "N", 2, 0 }}

   cText    := HB_MEMOREAD( "storico.txt" )
   cText    := FW_ALLTRIM( cText )
   cText    := StrTran( cText, CRLF, Chr( 10 ) )

   aData    := HB_ATokens( cText, Chr( 10 ) )


   AEval( aData, { |c,i| aData[ i ] := HB_ATokens( c, Chr( 9 ) ) } )
   AEval( aData, { |a,i| a[ 1 ] := uCharToVal( a[ 1 ], "D" ) } )

   XBROWSER aData

    oLotto:= TDatabase():Open( , "LOTTO", "DBFCDX", .T. )
    oLotto:Gobottom()
    dMaxDate := oLotto:Data
    ?dMaxDate //TAKE LAST RECORD DATE

    //CREATE TEMP
   DBCREATE( "TEMP.DBF", aFields, "DBFCDX", .T., "Storico" )


   aNew     := {}
   AEval( aData, { |a| If( a[ 1 ] > dMaxDate, AAdd( aNew, a ), ) } )
   FW_ArrayToDbf( anew )


   GO TOP
   XBROWSER ALIAS() SHOW RECID
   CLOSE DATA

return nil
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Willi Quintana and 92 guests