Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-numbering problem
Message
De
24/02/2009 08:06:56
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01383631
Message ID:
01383723
Vues:
55
>>>>Please, tell me, what you mean under "renumbering records" ? This question tears me apart and I even can't sleep :)
>>>>Are you really going to change RECNO() ? Or you are speaking about a simple REPLACE...ALL ?
>>>
>>>Well, I needed to change the sequence number (it's an integer field in my table). So, for each FK I needed a sequence from 1 to the number of records for this FK. I also needed to figure out how would I change the number to not mess up the original numbering (at the end, I didn't take this into consideration, so I may have some surprises tomorrow).
>>>
>>>Anyway, while you were sleeping I already implemented quite simple algorithm and ran it in production.
>>>
>>>So, you may go to sleep or are you starting your work day already? If yes, all the best to you and good luck!
>>
>>What I have done in similar cases is to get all the records into a cursor, and then process the cursor with a SCAN. For each record in the cursor, go to the record in the original table.
>>
>>This way, you avoid the potential problem that renumbering affects the SCAN loop.
>
>Yes, that's exactly how did I do it. I selected all duplicates in the cursor and then processed it. However, I probably didn't preserve the original sequence number and the number (especially 1 - primary) was important.

The renumbering I did was precisely intended to keep the original numbering. Records were automatically assigned numbers 10, 20, 30... so that the user could move one record between other records. At some moment, the user could decide to renumber. For example, after moving record #30 between #10 and #20 (the user assigns a number like 15), the number would be 10, 15, 20 - and a "renumber" option would again assign increments of 10, preserving the sequence of course.

So, in this case, I think you should select into a cursor, with an ORDER BY clause of course - and then process the records in sequence with a SCAN - locating the record in the original table by primary key, and assigning the new number.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform