Archives on the local network

Archives on the local network

Postby Silvio.Falconi » Wed Oct 03, 2018 10:35 am

I opened the customer management and I want to insert a customer and
insert the name the procedure checks me if there is a name because I entered a valid.
the name is not in the archive so the procedure also allows me to insert the other fields

Before saving I am distracted and answer the phone or I go to the bathroom or I take a coffee from the vending machine with my friend NagesRao or I seeing a beautifull girl or is arrived my friend Antonio Linares at my school...

when I return, I press the save button and the procedure saves the record

But there is an error because we realized that a lather user had entered a name and the procedure that in automatic the customer code according to the record number had assigned two codes exactly equal to my record and to that saved by the colleague in the office

this happened because my colleague and I opened the customer archive in share


how can we solve the problem?

I thought before saving I have to check if there is already that code but then I have to check that there is already that name


and this happens for all the archives. a total frazzle ... that's why I abandoned this system to work in the local network, at the programming level it wastes time to make these checks

How do you handle this problem?
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: 6782
Joined: Thu Oct 18, 2012 7:17 pm

Re: Archives on the local network

Postby Enrico Maria Giordano » Wed Oct 03, 2018 12:32 pm

Exactly as you said. You have to check for uniqueness and other conditions just before the record is created/saved. But this is not enough: you have to ensure that the whole operation (check + save) is not mixed with the same operation from another user. This is why lock is necessary. Probably (depending on your lock strategy) you will have to use a file lock for this. In rare cases, neither this is enough and a global semaphore lock is required.

As I said earlier, this is not easy at all.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8326
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Archives on the local network

Postby Silvio.Falconi » Wed Oct 03, 2018 1:44 pm

What do you mean by block you can give me an example
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: 6782
Joined: Thu Oct 18, 2012 7:17 pm

Re: Archives on the local network

Postby Enrico Maria Giordano » Wed Oct 03, 2018 2:13 pm

Something like (symplified):

Code: Select all  Expand view
FLOCK()

// Do your checking

// If checking is ok do your creation/saving

UNLOCK


So no user can execute the same operation at the same time.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8326
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Archives on the local network

Postby James Bott » Thu Oct 04, 2018 1:07 am

Silvio,

You really need to use database objects. Then you can just do:

Code: Select all  Expand view
oCustomer:= TCustomer():new()
oCustomer:blank()         // blanks all the fields
oCustomer:name:="Silvio"
...wait some time
oCustomer:save()
 

You build in a check in the save() method to prevent creating a duplicate record. Note that aliases and record locking are built-in, so you don't ever have to deal with them.

However, your example is not a good one. You should never use something like a name for an ID. Of course, there are multiple people with the same name so this is the issue. Each record should have it's own ID automatically generated by the class. That way each record has a unique ID even if the name is the same. You may still want to check the name to make sure it isn't the same person, maybe by checking their phone number or getting a decision by the user.

Another reason to use objects is that you can put other methods in the class, for instance to find a person's age.

msgInfo( oCustomer:age() )

Or something more complicated like sales amount over a time period.

oCustomer:salesAmount( dStart, dEnd )

There is no end to the great things you can do with objects.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 14 guests