![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||||
| |||||
|
|
I have a database with a 2 byte (in Pascal lingo, a 'word', in C/C++ lingo, a 'short') AUTOINCREMENT field. I've observed that once the counter reaches 32,768, it begins giving Status code 5 errors on every attempt to INSERT beyond that point. (Which makes sense and is expected, of course.) My question is, I also delete records earlier in the database that are no longer needed, and was wondering if there's a way of resetting the counter used for the AUTOINCREMENT field so I can begin INSERT'ing as usual? |
|
FYI-- I'm using the MKDE directly via BTRCALL API calls, I've tried it with v6.15 as well as the newer Pervasive SQL V8 SP1, and have not found a solution to this. |
|
Two other related questions-- is there a way to get the MKDE to treat the 2 byte field AUTOINCREMENT as unsigned, allowing for a maximum counter of 65535? |
|
And is there a way, if I end up ditching AUTOINCREMENT for this field, to quickly find gaps in manually generated fields? (Well, this would actually apply to AUTOINCREMENT as well, but if there's no way to reset the counter then the AUTOINCREMENT field won't work for what I'm doing.) |
|
(I've done extensive Google searches on this subject, both in these NG's and the web in general-- I haven't come across any viable solutions beyond expanding the field size (which is at best a temporary solution).) |
#2
| ||||
| ||||
|
|
There is no "counter" per se -- the database just checks for the current largest value, then adds one to it. |
|
The only way to change this behavior is to do it in code -- search for an available value, then force the field to that value, which will insert correctly. You can make this a bit quicker by using the following loop: for(i=0;i<32768;i++) if(Btrv(Operation 5 + 50,i)==4) break; Obviously pseudocode, but you get the idea. The GetKey bias (+50) does not retrieve the entire record, so it will run faster than a real GetEqual operation. For even faster operation, store your last position in a file somewhere, then loop to 32768 first, then back to the initial position in a second loop. |
|
Temporary? Even a 4-byte AutoInc field gives you 2 billion records. If you insert 1 record every second, it'll still take 63 years to fill up the data type. Of course, with the latest engines, you can use the 8-byte AutoInc. I won't do the math, but I'll bet that the data file will be purged (and possibly rebuilt) long before that happens. |
|
Another solution is to write a rebuild application -- one that reads records out of the old file and inserts them into a new file. Of course, if these are key values, then you'd also need to start renumbering foreign keys in other tables from the old value to the new value as you go along. It can be difficult and time-consuming, but not impossible. (I once wrote a purge/renumber function that hit 50+ files, which was loads of fun.) |
![]() |
| Thread Tools | |
| Display Modes | |
| |