database object

database object

Postby Otto » Wed Nov 14, 2012 8:23 pm

To all,
I think Modified() with method blank() does not work correctly.
In this case modified() checks always agains record number 1.
Best Retards,
Otto

Code: Select all  Expand view
METHOD Modified() CLASS TDataBase

   local n

   if ::lBuffer
      for n := 1 to ( ::nArea )->( FCount() )
         if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
            return .t.
         endif
      next
   endif

return .f.
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby Otto » Thu Nov 15, 2012 10:11 am

As this is my personal knowledge base, too I post my work around here:

Regards,
Otto

Code: Select all  Expand view
::oKBuch := TData():New( , "datawin\kasse" )
    ::oKBuch:use()
    ::oKBuch:blank()

    aBufferBlank := AClone( ::oKBuch:abuffer )
   

// if you set default values
    ::oKBuch:datum := date()
       
    aBufferBlank[ 2 ] := ::oKBuch:Beleg
    aBufferBlank[ 9 ] := ::oKBuch:datum



    lreturn := ModifiedBlank( oSelf:oKBuch:nArea,aBufferBlank, oSelf:oKBuch:aBuffer )


static function ModifiedBlank( nArea,aBufferBlank, aBuffer )

   local n
       
      for n := 1 to ( nArea )->( FCount() )
     
         if ! aBuffer[ n ] == aBufferBlank[ n ]
         msginfo(aBuffer[ n ])
            return .t.
         endif
      next

return .f.

//----------------------------------------------------------------------------//
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby Antonio Linares » Thu Nov 15, 2012 11:17 am

Otto,

Method Blank() does not change the record number, so method Modified() should work fine.

Maybe the database is being displayed on a browse and the browse is changing the record number ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: database object

Postby Otto » Thu Nov 15, 2012 11:31 am

Hello Antionio,
I am sorry.
I use TDATA from James and for compatibility reason still a database.prg with this

METHOD Blank( nRecNo ) INLINE ( ::nArea )->( nRecNo := RecNo(),;
DBGoBottom(), ;
DBSkip( 1 ), ;
::Load(),;
DBGoTo( nRecNo ) )

I try to check the new method in database.prg.
Best regards,
Otto

I
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby Otto » Thu Nov 15, 2012 11:53 am

Hello Antonio,
I check again the "method modified".
What I do not understand is how can ( ::cAlias )->( FieldGet( n ) ) read a record which does not exist in the database yet.
Best regards,
Otto


METHOD Modified() CLASS TDataBase

local n

if ::lBuffer
for n := 1 to ( ::nArea )->( FCount() )
if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
return .t.
endif
next
endif

return .f.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby Otto » Thu Nov 15, 2012 4:19 pm

Hello Antonio,

::FieldGet( 1 ) would Show the right value.

( ::cAlias )->( FieldGet( n ) ) Shows the value of the first row.

Can you please help me.
Best regards,
Otto

METHOD Modified() CLASS TDataFWH

local n

logfile("log.txt",{ ::recno(), "modified" } )

logfile("log.txt",{ "FieldGet", ::FieldGet( 1 ) } )


for n := 1 to Len( ::aFldNames )

if ! ( ::cAlias )->( FieldGet( n ) ) == ::aBuffer[ n ]
msginfo(( ::cAlias )->( FieldGet( n ) ))
msginfo(::aBuffer[ n ])
return .t.
endif
next
return .f.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby Otto » Thu Nov 15, 2012 4:53 pm

Hello Antonio,
if I check immediately afte assigning ::abuffer in METHOD Blank()
( ::cAlias )->( FieldGet( 1 ) ) returns the value of the first record in the database.
Are you sure modified is working if you add a record using blank()
Best regards,
Otto


Code: Select all  Expand view
METHOD Blank() CLASS TDataFWH

   
   if ::lBuffer
      AEval( ::aBuffer, { |u,i| ::aBuffer[ i ] := uValBlank( u ) } )
   endif


    logfile("log.txt",{ ::recno(), "*** Blank"  } )
 
    logfile("log.txt",{ "::FieldGet  ->", ::FieldGet( 1 )  } )
 
    logfile("log.txt",{ "FieldGet  ->", ( ::cAlias )->( FieldGet( 1 ) )  }  )
 
    logfile("log.txt",{ "aBuffer  ->", ::aBuffer[ 1 ]   }  )

    logfile("log.txt",{ ::recno(), "*** Ende"  } )
 
return .f.

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


15.11.2012 05:42:12: 1 *** Blank
15.11.2012 05:42:12: ::FieldGet ->
15.11.2012 05:42:12: FieldGet -> Gute Anreise
15.11.2012 05:42:12: aBuffer ->
15.11.2012 05:42:12: 1 *** Ende
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby TimStone » Thu Nov 15, 2012 6:18 pm

Otto,

I'm also using tData. Are you using tRecord also ? When using an xbrowse, and editing a particular row, I have the values in a tRecord. Thus I never have a problem with saves.

I've used it for many years ( and James did make some revisions along the way ), and have no problems.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: database object

Postby Otto » Thu Nov 15, 2012 6:43 pm

Tim,
here is a test which shows the wrong behavior.
Click on the button without inserting something into the get field and method modified returns true.
Best regards,
Otto

Code: Select all  Expand view
function testTdata()
   LOCAL oDlg, oGet
   LOCAL oKBuch

   oKBuch := TData():New( ,  "clientes" )
    oKBuch:use()
    oKBuch:blank()

         DEFINE DIALOG oDlg ;
           TITLE "TGet from " ;
            FROM 10, 10 ;
              TO 500, 800 ;
           PIXEL



        @ 10,20 ;
         SAY "Text..:" ;
          OF oDlg ;
       PIXEL

       @ 20,160 ;
         GET oGet ;
         VAR oKBuch:nombre ;
          OF oDlg ;
       PIXEL ;
        SIZE 160, 10

 
       @ 40,20 ;
      BUTTON "Modified Yes/no" ;
      ACTION ( iif ( oKBuch:Modified() = .T., Msginfo( "geändert" ), MsgInfo("nicht geändert"  ) ) ) ;
          OF oDlg ;
       PIXEL


   ACTIVATE DIALOG oDlg CENTERED
   
 
return nil

//------------------------------------------------------------------------//
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby TimStone » Fri Nov 16, 2012 12:36 am

Otto,

As James explained it to me, blank simply empties the buffers. You didn't add a record ( obj:append( ) ) so you wouldn't have a record number.

tRecord may resolve your problems because it will track a record number and always make sure you write to it.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: database object

Postby Otto » Fri Nov 16, 2012 7:36 am

:append()

Hello Tim,
thank you for your explanation.
As in the moment of opening a dialog to insert a new record you never know if a user finishes entering you can’t append a record.
If he breaks off you have to delete the record in the database.
To delete records in a database concerning data which is responsible for calculating taxes is prohibited from law here.
Therefore you only :append a record if you really want to.

There should be a DATA inside Tdatabase.prg showing that you enter data in a blank record.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: database object

Postby TimStone » Fri Nov 16, 2012 10:02 pm

tRecord will do that for you. Create a new tRecord object, and issue blank( ). That gives you clear data. Because there is no record number, when you go to save it, it will do the append( ) at that time.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: database object

Postby Otto » Fri Nov 16, 2012 10:18 pm

Hello Tim,
thank you. I will look into the TRecord object.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 110 guests