Problem with tdatabase

Problem with tdatabase

Postby Silvio.Falconi » Sat Dec 04, 2021 12:44 pm

.
Last edited by Silvio.Falconi on Mon Feb 06, 2023 8:50 am, 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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby Jack » Sun Dec 05, 2021 4:45 pm

Silvio,
When i have to add a record in a network, befor i add the record, i open an empty tabel in exclusive mode , and add the record in the main shared table .

After the add, i close the empty table .

If the empty table could not be open in exclusive, the reason is that an another user try to add a record and i go in a loop to wait that the table could be open .

Good luck,


Philippe
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Problem with tdatabase

Postby Otto » Sun Dec 05, 2021 5:14 pm

Hello Jack,
Interesting, but what do you do if the other user does not finish his work, for example he goes out of the office for lunch?
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: Problem with tdatabase

Postby Jack » Mon Dec 06, 2021 8:46 am

Otto,
When the user push the Add button, the process takes 1 or 2 seconds .

After that, you can go for lunch .

Philippe .
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Problem with tdatabase

Postby Silvio.Falconi » Mon Dec 06, 2021 9:53 am

Jack wrote:Otto,
When the user push the Add button, the process takes 1 or 2 seconds .

After that, you can go for lunch .

Philippe .


>When the user push the Add button, the process takes 1 or 2 seconds .
the process cannot take 1 or 2 seconds

the user open the edit dialog and the code is 00001
then the user go to lunch leaving everything open
when he return back he realizes he has not saved and presses "Save"
but when he was having lunch from another terminal someone else entered the code 00001 and saved it
now in the archive there are two records with the same code
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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby TimStone » Mon Dec 06, 2021 11:41 pm

Three options:

1). Open the file, lock it, append the record, add the code to the field, save the record, unlock it. This happens in milliseconds and no other user on the network will have access.

2) Fill the data with blanks in variables, edit the variables with all the data, then in your Save method, lock the file, append the record, calculate and put the number in the buffer, then save the full record, and unlock the file.

3). MY PREFERRED METHOD: Your goal is to have unique, sequential, numbers. I have a "counters" file. When I want to add a record, I open the file, get the proper value ( there are fields for each file ), increment it by one, then save the new value. Locking applies. Again, it takes milliseconds to do this, and with hundreds of thousands of records written each year, my clients have NEVER encountered a problem. Some locations have up to 20 workstations sharing data in a network. The values are assigned to variables in the .prg and applied to records as approrpiate.I use a 10 digit counter for each file. Also, I have a function that allows them to set new values for a counter in case they want to start a fresh location each yeear. IT WORKS, and that is what I find most important.
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: Problem with tdatabase

Postby Silvio.Falconi » Tue Dec 07, 2021 8:02 am

TimStone wrote:Three options:

1). Open the file, lock it, append the record, add the code to the field, save the record, unlock it. This happens in milliseconds and no other user on the network will have access.

2) Fill the data with blanks in variables, edit the variables with all the data, then in your Save method, lock the file, append the record, calculate and put the number in the buffer, then save the full record, and unlock the file.

3). MY PREFERRED METHOD: Your goal is to have unique, sequential, numbers. I have a "counters" file. When I want to add a record, I open the file, get the proper value ( there are fields for each file ), increment it by one, then save the new value. Locking applies. Again, it takes milliseconds to do this, and with hundreds of thousands of records written each year, my clients have NEVER encountered a problem. Some locations have up to 20 workstations sharing data in a network. The values are assigned to variables in the .prg and applied to records as approrpiate.I use a 10 digit counter for each file. Also, I have a function that allows them to set new values for a counter in case they want to start a fresh location each yeear. IT WORKS, and that is what I find most important.


but you don't use Tdata and Tincremental of James ?
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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby Otto » Tue Dec 07, 2021 8:14 am

Hello Silvio,
I think you have to post a little more source code and maybe make a flowchart so that we can better understand what you want to do exactly.
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: Problem with tdatabase

Postby Silvio.Falconi » Tue Dec 07, 2021 8:31 am

.
Last edited by Silvio.Falconi on Mon Feb 06, 2023 8:49 am, 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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby James Bott » Sat Dec 18, 2021 8:14 pm

You need to use relational databases like this:

ITEMS.DBF
ITEMID <---primary key (auto incrementing)
DESCRIPTION
CATAGORYID
BRANDID

CATAGORY.DBF
CATAGORYID <--- primary key (auto incrementing)
CATAGORYNAME

BRAND.DBF
BRANDID <--- primary key (auto incrementing)
BRANDNAME
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

Re: Problem with tdatabase

Postby Silvio.Falconi » Sun Dec 19, 2021 11:26 am

.
Last edited by Silvio.Falconi on Mon Feb 06, 2023 8:49 am, 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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby Giovany Vecchi » Sun Dec 19, 2021 3:31 pm

Hello everybody.
I use tAds that I authored, which has the same logic as tDataBase. The best way I found to resolve these types of conflicts were:
1- For sequential numbers never to be chosen by the user.
2- Auto increment or any sequential number always after rLock()
In practice I use a table of traffic lights called SEMAFORO.ADT. In it I have several fixed records with the fields:
1- L_UPDATE > True = In Use / False = Not In Use
2- C_FIELD_ACTION > Field of a sequential type table or action of a procedure.
3-DESCRIPTION > Description of the record (which field table or reference function for the action)
4-VAL_SEQUENCE > Current value of the sequence of numbers.

Example:
Code: Select all  Expand view  RUN
oDb_Semaforo:GoTo(120) //Registration with the clients registration sequence
oDb_Semaforo:rLock(8) //Method rLock 8 (Represents 8 seconds corresponding to the routine. if it exceeds the lock attempts it returns .F.)
nClienteCodigo := oDb_Semaforo:SetValSequence(-1)
? nClienteCodigo
 


Code: Select all  Expand view  RUN
Method SetValSequence(f_nValor,f_nRecno,f_lUnlock) Class DB_SEMAFORO
    Local nValorRetorno := 0
   
    Default f_lUnlock := .T.
    If !Hb_isNil(f_nRecno)
        ::GoTo(f_nRecno)
    EndIf
    ::rLock()
    if f_nValor == -1 // add +1
        nValorRetorno := ::VarPut("VALOR_ATUA",1,"+")
    Else
        nValorRetorno := ::VarPut("VALOR_ATUA",f_nValor)
    EndIf
   
    If f_lUnlock
        ::Commit(.T.)
    Else
        ::Commit()  
    EndIf
RETURN nValorRetorno
 


Code: Select all  Expand view  RUN
METHOD Lock(f_nRecno) Class TAds
    Local lLockRecno := .F., iForTentativa := 0

    Default f_nRecno := (::cAlias)->(Recno())

    If (::cAlias)->(Recno()) != f_nRecno
        (::cAlias)->(DbGoTo(f_nRecno))
        ::OnSkip()
    EndIf

    For iForTentativa := 1 To 5
        (::cAlias)->(AdsRefreshRecord())
        If (::cAlias)->(DbRLock())
            lLockRecno := .T.
            Exit
        Else
            SysWait(.2)
        EndIf
    Next

RETURN lLockRecno
 
User avatar
Giovany Vecchi
 
Posts: 223
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

Re: Problem with tdatabase

Postby Silvio.Falconi » Sun Dec 19, 2021 5:50 pm

.
Last edited by Silvio.Falconi on Mon Feb 06, 2023 8:48 am, 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: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem with tdatabase

Postby James Bott » Sun Dec 19, 2021 9:32 pm

Silvio,

If I understand correctly, you are converting an exclusive use app written in Clipper to a multi-user application written in Fivewin?

I am not sure you can convert this to multi-user without some major design changes too.

I see some inconsistencies with the current database example. It seems that you are combining the first and second categories descriptions into the same field. This creates problems such as you cannot find all the records with SAMSUNG. For example, one record contains SAMSUNG in the DESCRATM field and CODCATM2 is blank and another record containing SAMSUNG has CONDCATM2 as 00025. Is the program depending on the user to make the right decisions on what to enter in the description field and the CODCATM2 field? The only way you can find all SAMSUNG products is to do an instring search of all the records in the database. Maybe you never need to do that?

What is the CODCATM2 field used for?

Also, you have a record without a CODCATM2 value that has the DESCRIPTION "COMABLEILI SAMSUNG." Why doesn't this have a CODCATM2 number?

How do you determine the description? How does your code decide when the record needs CODCATM2 and when it doesn't? Or, is the user deciding.

Note that all these kinds of issues would be resolved by using three related databases instead of one database. Users would be selecting data from lists (comboboxes) instead of manually entering them.

By the way, this is not a problem with TDatabase or TData--this is an application design issue due to converting from single user to multi-user.
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

Re: Problem with tdatabase

Postby Silvio.Falconi » Sun Dec 19, 2021 11:10 pm

James Bott wrote:Silvio,

If I understand correctly, you are converting an exclusive use app written in Clipper to a multi-user application written in Fivewin?

I am not sure you can convert this to multi-user without some major design changes too.

I see some inconsistencies with the current database example. It seems that you are combining the first and second categories descriptions into the same field. This creates problems such as you cannot find all the records with SAMSUNG. For example, one record contains SAMSUNG in the DESCRATM field and CODCATM2 is blank and another record containing SAMSUNG has CONDCATM2 as 00025. Is the program depending on the user to make the right decisions on what to enter in the description field and the CODCATM2 field? The only way you can find all SAMSUNG products is to do an instring search of all the records in the database. Maybe you never need to do that?

What is the CODCATM2 field used for?

Also, you have a record without a CODCATM2 value that has the DESCRIPTION "COMABLEILI SAMSUNG." Why doesn't this have a CODCATM2 number?

How do you determine the description? How does your code decide when the record needs CODCATM2 and when it doesn't? Or, is the user deciding.

Note that all these kinds of issues would be resolved by using three related databases instead of one database. Users would be selecting data from lists (comboboxes) instead of manually entering them.

By the way, this is not a problem with TDatabase or TData--this is an application design issue due to converting from single user to multi-user.


as I have explained to you in private (and I have been trying to explain it for a month but no one understands or pretends it) codcatm1 is the code that determines the main category or top level and it is a main category when codcatm2 is empty. when the user wants to insert only a main category he does not insert the subcategories in the xbrowse for example 00007 games is a first level category, "games" is the description

It is a simple thing I not understood why we go around

the problem as I wrote to you in private mail is in the editsetup function of your creation that I want to avoid publishing in this forum,

U save the code ("nextid") as counter related to the archive (area) in an external dbf archive and since the archive is the same I had to modify the call to that editsetup function in order to create a counter for the subcategories as well
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: 7063
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests