Problem to save with tdatabase - Resolved!

Problem to save with tdatabase - Resolved!

Postby Silvio.Falconi » Fri May 24, 2019 5:17 pm

I have an array aDataBase

and save it in this mode

Code: Select all  Expand view

oTariffeBase:= TDatabase():Open( , cDir+"Tariffe", "DBFCDX", .T. )
       oTariffeBase:gotop()


    For n=1 to Len(aDataBase)
        ctipo:="E"   //Elemento
        ntipotar:="N"

               cIdelemento := alltrim(aDataBase[n][2])
               celemento   := alltrim(aDataBase[n][3])
               csettore    := alltrim(aDataBase[n][4])
               ngiorni     := aDataBase[n][5]
               ncosto      := aDataBase[n][6]
               lbloccato   := aDataBase[n][7]
               cidlistino  := alltrim(aDataBase[n][8])
               nTotale     := aDataBase[n][6]


               oTariffeBase:append()

                     IF oTariffeBase:RLock()
                        oTariffeBase:tipo       :=  ctipo
                        oTariffeBase:idElemento :=  cIdelemento
                        oTariffeBase:elemento   :=  celemento
                        oTariffeBase:settore    :=  csettore
                        oTariffeBase:giorni     :=  ngiorni
                        oTariffeBase:costo      :=  ncosto
                        oTariffeBase:tipotar    :=  ntipotar
                        oTariffeBase:totale     :=  nTotale
                        oTariffeBase:idlistino  :=  cidlistino
                        oTariffeBase:bloccato   :=  lbloccato
                        oTariffeBase:save(.t.)
                       ENDIF



              next


But it create only record blank why ?
Last edited by Silvio.Falconi on Sat May 25, 2019 9:01 pm, edited 1 time 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: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem to save with tdatabase

Postby ukoenig » Sat May 25, 2019 8:09 pm

Silvio,

this test shows the logic
NO rlock, unlock and append for every record needed

Code: Select all  Expand view

STATIC FUNCTION SAVE_ARRAY( oCust )
LOCAL  aData[3][3]

aData[1][1] := "A 1"
aData[1][2] := "B 1"
aData[1][3] := CTOD("01/01/2019")

aData[2][1] := "A 2"
aData[2][2] := "B 2"
aData[2][3] := CTOD("02/01/2019")

aData[3][1] := "A 3"
aData[3][2] := "B 3"
aData[3][3] := CTOD("03/01/2019")

oCust:Append( "Last, First, HireDate", aData ) // 3 records apended

RETURN( NIL )
 


Image

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Problem to save with tdatabase

Postby Silvio.Falconi » Sat May 25, 2019 8:40 pm

thanks run ok
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: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem to save with tdatabase - Resolved!

Postby nageswaragunupudi » Sun May 26, 2019 11:39 am

This example shows the 4 ways of appending data
Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDbf

   DBCREATE( "TESTAPND", { { "CODE", "C", 3, 0 }, { "NAME", "C", 15, 0 } }, "DBFCDX" )

   oDbf  := TDatabase():Open( nil, "TESTAPND", "DBFCDX", .T. )

//METHOD-1:
   oDbf:Append( "CODE,NAME", { "SUN", "Sunday" } )
   XBROWSER oDbf

//METHOD-2:
   oDbf:Append( "CODE,NAME", { { "MON", "Monday"  }, ;
                               { "TUE", "Tuesday" }  } )
   XBROWSER oDbf

//METHOD-3:
   oDbf:Append()  // appends blank record
   oDbf:Load()    // this line not required in FWH1905
   oDbf:Code   := "WED"
   oDbf:Name   := "Wednesday"
   oDbf:Save()    // do NOT use Locks/Unlocks

   XBROWSER oDbf

//METHOD-4:
   oDbf:Blank()  // Most commonly used
   oDbf:Code   := "THU"
   oDbf:Name   := "Thursday"
   oDbf:Save()

   XBROWSER oDbf

   oDbf:Close()

return nil
 
Regards

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

Re: Problem to save with tdatabase - Resolved!

Postby Silvio.Falconi » Sun May 26, 2019 12:08 pm

Thanks Rao, probably tdata class works differently as I wrote above
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: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem to save with tdatabase - Resolved!

Postby nageswaragunupudi » Sun May 26, 2019 12:59 pm

Silvio.Falconi wrote:Thanks Rao, probably tdata class works differently as I wrote above


Method-4 works for TData also. That is the most used method by TData users, not the method you wrote.
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 110 guests