Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

db2k problem 1

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
I am having a problem with an autoincrement field in db2k. Here's the scenarios:

Scenario 1:
1. I created a .dbf with 4 normal and 1 autoincrement field.
2. I then appended a .csv file to it.
3. The autoinc field seemed to work as each record was appended having an incremental value starting with 1.
4. I amnually appended a record, closed the database, and reopened it.
5. The new record was at the end as it should be but the value of the autoinc field was 1.

Scenario 2:
Since #1 failed, I tried:
1. Created a table with no autoinc field
2. Append the .csv file
3. modified the table to have autoinc field
4. They all had incrementing values. Good so far.
5. Closed and reopened the table
6. Appended a record
7. Autoinc field value was 1

Scenario 3:
(This is what started the whole thing)
1. Created a table with autoincrement field.
2. Wrote a web site that performs queries, updated, deletes, and adds
3. queries, updates, and deletes work fine
4. Appended new records using the beginappend() method
5. Appended record's autoincrement field value is 1
6. Tried to perform a query that should have found this new record but it didn't

Anyone know what's up? Are all these problems related??

Jerry Scannell
JScannell1@Home
 
I don't have dB2K (cheap boss), but have you gone to and asked the developer for help. You may want to check out their newsgroups (or something like that) for assistance.

The only (generic) workaround I can think of is to:

1) get current number of records (before appending) and store that number in a variable,

2) add 1 to that number in that variable

3) put that new number from the variable into the field.

Hopefully, something here helps.
--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Miggy D,
Thanks for the idea. One thing, though: In order to make sure you don't get duplicate numbers, you can't merely take the number of records and add 1. That wouldn't take into account deleting a couple of records. The next 2 adds would end up being duplicate numbers.

The one workaround I tried that seemed to work, but it is really a jury-rig - is to perform a select of the entire file, go to the last() record and read it's number. Add 1 to it and use for the append. That would assure of never getting a duplicate but will eventually add significant time to the process.
Jerry Scannell
JScannell1@Home
 
Glad to have sparked something. My thinking on it was to have you use the RECCOUNT() [this command is from dBASE iii+--don't know if it was being carried over to VI] at the beginning of what ever procedures you were going to use to ADD.

But, I'm glad you were able to figuer out something.

See ya.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Oops, I see your point. You're right, I hadn't contemplated a deleteing procedure. I quickly did some pseudo coding and saw what you mean.

If you wanted to, you could probably create a sort of "Clean the Database" procedure. And, after it deletes certain records, it could "fix" the numbers in the field by comparing it to the record's sequence number.

(before deleting)
Rec. No. AutoNum Fname
1 1 Bobby
2 2 Grege
3 3 Cindy
....
50 50 Marsha


(after deleting)
Rec. No. AutoNum Fname
1 1 Bobby
2 <--NG--> [red]3[/red] Cindy
3 <--NG--> [red]50[/red] Marsha


(resequencing AutoNum)
Rec. No. AutoNum Fname
1 1 Bobby
2 <-OK-> [red]2[/red] Cindy
3 <-OK-> [red]3[/red] Marsha


Just remember, it's only a suggestion.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top