Board index » delphi » Key violation with an autoincrement field
John Herbster
![]() Delphi Developer |
Sun, 28 Apr 2002 03:00:00 GMT
|
John Herbster
![]() Delphi Developer |
Sun, 28 Apr 2002 03:00:00 GMT
Key violation with an autoincrement field
I gave Paradox autoincrement fields one more try for a log file that only
has one writer task. After running a while, I get a "Key violation" exception when the program Should I program the deletion fix in or should I give up on autoincrement TIA, for your ideas, John H |
Team
![]() Delphi Developer |
Sun, 28 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldYour table may be corrupt. You may want to verify and rebuild it using the table repair utility at www.borland.com/devsupport/bde/utilities.html. If you decide to use an integer field do not use a query. It is both slow and, in a multiuser environment, unsafe. Instead, use a single field single record table to hold the last used value and the following function to get the next value. function dgGetUniqueNumber(LastNumberTbl: TTable): LongInt; Bill -- |
John Herbste
![]() Delphi Developer |
Sun, 28 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldSteve, Thank you for trying. Please find my responses to your ideas below. Thanks, John H Steve Fischkoff wrote ... Quote> You shouldn't have to do this type of deletion unless something is autoincrement field. Quote> Is it possible that some other factor is creating a duplicate Quote> or a programming problem, ... routine are protected from reentrancy. Thanks again. |
John Herbste
![]() Delphi Developer |
Sun, 28 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldBill, Thanks for the ideas. My comments below. John H QuoteBill wrote: Your table may be corrupt. You may want to Quote> you decide to use an integer field do not use a query. It is And why is it unsafe? In a repeat loop, I have put a fetch max, Thanks for the function code, I will save and look at it. Regards. |
Steve Fischkoff (Tea
![]() Delphi Developer |
Mon, 29 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldOn Wed, 10 Nov 1999 15:50:52 -0600, "John Herbster" Quote<jo...@petronworld.com> wrote: wrong. First, what is the structure of the index which is giving you the key violation? Is it possible that some other factor is creating a duplicate key? The other thing that can happen (should only be rare!) is that the Paradox file loses track of the last autoincrement number used. This problem does fix with deletion of the last record. However, it is usually a sign of some other problem such as a network problem or a programming problem, especially if it happens often. Is there something else wrong that you might not think is related but might give a clue? Steve F (Team B) |
David Beardwoo
![]() Delphi Developer |
Mon, 29 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldit's "unsafe" because the value could change during/after the query before you use it. this could easily happen in a multi-user environment. since you're without a network i gather you're in a single user environment with only 1 process/thread so you're probably ok. (unless it's "unsafe" for another reason i haven't thought of). it's easier and safer just to use a single record table to store the value, dave |
John Herbste
![]() Delphi Developer |
Mon, 29 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldDavid Beardwood wrote Quote> it's "unsafe" because the value could change during/after the query attempt to post? My normal scheme would use that exception to increment the key and try again. So where is the problem? Infinite loop or corrupted table -- which? Thanks, John H |
Team
![]() Delphi Developer |
Mon, 29 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldSlow is relative and how slow depends on the size of the table. A select Max on the primary key still requires the primary index to be read across the network. It is unsafe in a multi-user environment because it is quite possible for two users to select max at the same time and get the same value. Whoever posts second will get a key violation error. Bill Bill Todd (TeamB) |
John Herbste
![]() Delphi Developer |
Tue, 30 Apr 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldBill Todd (TeamB) wrote ... Quote> Whoever posts second will get a key violation error. post. I understand getting a "Key violation" on an attempt to Post a record with what would be a duplicate key. So I do a cancel and change the key and try to Post again. But what what I was seeing was a corrupted table that would give the "Key violation" by any attempt execute the Append or Insert statements before any data was assigned or any Post was attempted. Thanks for trying to help explain things. I have developed the appropriate work-arounds for now. Regards, John H |
Gregg R. Zegarell
![]() Delphi Developer |
Mon, 06 May 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldso you don't think you're nuts, i have a table with exactly the same problem, which i fix in exactly the same way. repacking does not seem to help, even once i delete the last record. using 5.01, hoping 5.1 will fix it. i am going to try tutil. best, QuoteJohn Herbster wrote in message <80cos6$k...@forums.borland.com>... |
John Herbste
![]() Delphi Developer |
Tue, 07 May 2002 03:00:00 GMT
Re:Key violation with an autoincrement fieldGregg R. Zegarelli <g...@zegarelli.com> wrote in message Quote> so you don't think you're nuts, i have a table with exactly the same have been possible to attempt a second Append before the first Post. Let me know if this is your problem! I put reentrancy preventers and exception trapping around the log routines and kept the autoincrement index field as primary key. (I don't want logging problems to bring down the system.) I haven't had any problems yet, where as before they were every day. Regards, John H |
1. Key violation when append with autoincrement key field.
2. KEY VIOLATION on AUTOINCREMENT field ?!?
3. Paradox Autoincrement Fields Cause Key Violation -- Help!
4. Key Violation with autoincrement fields
5. Key Violation with Autoincrement Field
6. Key Violation with Paradox Autoincrement
7. Key violation with Paradox autoincrement
8. Key Violation with AutoIncrement