FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Database - 17.07 - Problems
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Database - 17.07 - Problems
Posted: Tue Sep 05, 2017 09:43 PM

James,

Sorry but I just don't have the time to do that right now. Norberto tried that code and it failed. I would likely have the same result. So far this problem has cost me 3 weeks ... and my clients are not happy.

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
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 12:37 PM

Mr. Rao,

Unfortunately, I too have the same error as before, if I modify the Close method and keep the destructor...

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 02:30 PM

Diego,

Please check your code for closing a database object, then calling it after. I think this is the problem. Before when you closed an object it still existed, now it is destroyed. So, before it didn't necessarily cause an error, but now it does.

As I mentioned in a previous message, you can place a oDBF:=nil after each close method, one at a time, to find which one is causing the error. You have to do this using TDatabase 17.06 or earlier.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 02:40 PM

James,

I do not understand well... if I use Tdatabase 17:06 or earlier, there is no destructor and there has never occurred an error...

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 04:09 PM

Diego,

If you study the code in this link:

viewtopic.php?f=3t=34468start=45#p205269

You will see the kinds of things that can happen with ver 17.06 and earlier. They may not trigger error messages, but there are things happening that shouldn't be. Because of this I do believe you have some code in your program that is incorrect and this is what is causing the error in 17.07. It may be that your program is still working fine, but new code you write might not be working and may not show an error.

So, you have two choices, never upgrade to current FWH code, or change your app code to prevent errors with the new TDatabase class.

The same things will happen whether you are using TData or TDatabase.

Questions?

James

&&

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 04:34 PM

James and all,
using FWH 17.04 with TDatabase 17.04, new Close method, closing a database object, then calling it after, several times, no error.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 04:46 PM
Diego,

>using FWH 17.04 with TDatabase 17.04, new Close method, closing a database object, then calling it after, several times, no error.

I'm not sure I understand what you mean.

Are you saying that you edited ver 17.04 TDatabase.prg and replaced the Close() method with the one from TDatabase 17.07?

Also, remember that no error doesn't mean that something hasn't gone wrong.

Note that if you are using TData then it overrides the Close() method of TDatabase.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 04:53 PM
James Bott wrote:
Are you saying that you edited ver 17.04 TDatabase.prg and replaced the Close() method with the one from TDatabase 17.07?


Yes.

James Bott wrote:
Also, remember that no error doesn't mean that something hasn't gone wrong.

Note that if you are using TData then it overrides the Close() method of TDatabase.
James


I used TDatabase 17.04 with new Close method
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 05:03 PM
Diego,

I have added more comments and messages to the sample code Nages provided. Perhaps this will make things more clear.

Code (fw): Select all Collapse
   oStates  := TDatabase():New(nil, cStatesFile)
   oStates:use()
   ? oStates:Used(), oStates:FieldGet( 1 ) // --> .T., "WA"
   // do some work and close the object
   oStates:Close()  // dbf is closed but the object is still there
   //oStates:=nil     // Adding this solves the problem.
   //oStates:GoTop() // errors out, any version  

   msgInfo(oStates:nArea,"oStates:nArea")   // 1
   msgINfo(oStates:used(),"oStates:used()") // .f.

   oCust    := TDataBase():Open( nil, cCustFile, "DBFCDX" )
   ? oCust:Used(), oCust:FieldGet( 1 ) // --> .T., "Homer" // this is OK
   
   msgInfo(oCust:nArea,"oCust:nArea") // Returns 1

   oStates:GoTop()  // oStates is now using the workarea of oCust. No error.
   // This is wrong
   ? oStates:Used(), oStates:FieldGet( 1 ) // --> .T., "Homer"  // This is from the oCust database
   oStates:Close()  // Problem: This closes oCust

   ? oCust:Used() // --> .F., though we did not call oCust:Close()
   msgInfo(oStates:used(),"oStates:used()") // returns false since oCust is closed


Note that just because you don't get an error message doesn't mean that something isn't wrong. For instance you may be getting data from a different database object. This kind of thing is very hard to find.

Closing the object doesn't destroy it and we need to destroy it to prevent these kinds of issues.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 05:17 PM

James,

I am trying only my test, which first opens a dialog with a single TDatabase object, closes it, opens a dialog with a dbf, then closes it.
Trying several times, even at random, no error.

Using MsgInfo msgInfo(oStates:nArea,"oStates:nArea"), adapted to my test, after closing the database (oDB:End()) I get zero.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 05:36 PM

Diego,

Like I showed in my code above, you don't have to get an error for things to be going wrong. Did you look at the code? Notice that oSales is showing data from oCust under those circumstances--and there are no errors.

Just using the new Close method from 17.07 isn't going to solve these kinds of problems. You have to destroy the object.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 06:07 PM
Diego,

Try this simple test. Compile it with ver 17.06 or before. You will see that oStates is showing a field from oCust. And there are no errors.

Then uncomment this line:

oStates:=nil

And now there will be an error. This is why we need to destroy the object.

James

Code (fw): Select all Collapse
/*
Purpose  : Very simple test showing how not destroying a database object
           can cause bad things to happen.
Program  : 
Author   : James Bott, <!-- e --><a href="mailto:jbott@compuserve.com">jbott@compuserve.com</a><!-- e -->
Date     :  09/06/2017 11:04:49 AM
Language : Fivewin/xHarbour
Updated  : 
Notes    :

*/

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oStates, oCust
   local cStatesFile:="c:\fwh\samples\states.dbf"
   local cCustFile:="c:\fwh\samples\customer.dbf"

   rddsetdefault( "DBFCDX" )
   memory(-1)

   oStates  := TDatabase():New(nil, cStatesFile)
   oStates:use()
   
   MsgInfo( oStates:FieldGet(1),"oStates:FieldGet(1)")  // "WA"
   
   oStates:Close()  // dbf is closed but the object is still there
   //oStates:=nil     // Adding this destroys the object
   //oStates:GoTop() // errors out, any version  

   oCust := TDataBase():New( nil, cCustFile, "DBFCDX" )
   oCust:use()
   
   msgInfo(oCust:FieldGet( 1 ),"oCustFieldGet(1)" ) // "Homer" // this is OK
   
   oStates:GoTop()  // oStates is now using the workarea of oCust. No error.

   // This is wrong
   msgInfo(oStates:FieldGet(1),"oStates:FieldGet(1)") // "Homer" Wrong

   oStates:Close()  // Problem: This closes oCust

   oCust:Close()

return nil

// EOF
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 06:40 PM

James,

I'm sorry but at the line
>> oStates:GoTop() // oStates is now using the workarea of oCust. No error.

I get an error DBCMD/2001 Workarea non in use: DBGOTOP

I'm using TDatabase 17.04 with old Close Method

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 07:29 PM
Diego,

Well, I am using FWH 16.02 so there must have been some changes to your version. Here is the Close() method of 16.02:

Code (fw): Select all Collapse
   METHOD Close()             INLINE ( ::nArea )->( DbCloseArea() ), If( ::oCn == nil,,::oCn:Close() ) // FWH 13.03


And in much earlier versions it was just:

Code (fw): Select all Collapse
METHOD Close()             INLINE ( ::nArea )->( DbCloseArea() )


Sill all objects should be destroyed when you are done with them. So, the easiest way is to build it into the class as Nages has done in 17.07. Otherwise, you have to remember to set them to nil each time you End() them (or in the case of TDatabase, Close() them). Note that now in TDatabase 17.07, you can use End() instead of Close(). Using End() is consistent with how you end all other objects.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Database - 17.07 - Problems
Posted: Wed Sep 06, 2017 07:58 PM

Diego,

I just looked at the Close() method in TDatabase ver 17.06 and it is the same as in ver 16.02 so I am at a loss as to why you would get an error here when I don't. Unless your 17.04 version is different than 17.06?

Perhaps you had uncommented the oStates:=nil line, then got an error?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10