Page 1 of 1

Problem with tdatabase

Posted: Sat Dec 04, 2021 12:44 pm
by Silvio.Falconi
.

Re: Problem with tdatabase

Posted: Sun Dec 05, 2021 4:45 pm
by Jack
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

Re: Problem with tdatabase

Posted: Sun Dec 05, 2021 5:14 pm
by Otto
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

Re: Problem with tdatabase

Posted: Mon Dec 06, 2021 8:46 am
by Jack
Otto,
When the user push the Add button, the process takes 1 or 2 seconds .

After that, you can go for lunch .

Philippe .

Re: Problem with tdatabase

Posted: Mon Dec 06, 2021 9:53 am
by Silvio.Falconi
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

Re: Problem with tdatabase

Posted: Mon Dec 06, 2021 11:41 pm
by TimStone
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.

Re: Problem with tdatabase

Posted: Tue Dec 07, 2021 8:02 am
by Silvio.Falconi
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 ?

Re: Problem with tdatabase

Posted: Tue Dec 07, 2021 8:14 am
by Otto
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

Re: Problem with tdatabase

Posted: Tue Dec 07, 2021 8:31 am
by Silvio.Falconi
.

Re: Problem with tdatabase

Posted: Sat Dec 18, 2021 8:14 pm
by James Bott
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

Re: Problem with tdatabase

Posted: Sun Dec 19, 2021 11:26 am
by Silvio.Falconi
.

Re: Problem with tdatabase

Posted: Sun Dec 19, 2021 3:31 pm
by Giovany Vecchi
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

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

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

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
 

Re: Problem with tdatabase

Posted: Sun Dec 19, 2021 5:50 pm
by Silvio.Falconi
.

Re: Problem with tdatabase

Posted: Sun Dec 19, 2021 9:32 pm
by James Bott
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.

Re: Problem with tdatabase

Posted: Sun Dec 19, 2021 11:10 pm
by Silvio.Falconi
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