Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update conflict
Message
 
 
À
05/01/2001 22:12:48
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00459687
Message ID:
00460357
Vues:
13
Hi!

Don't generate ID key in the table using default value. Of course, this causes limitation - use only views to edit table.

Another approach that causes no limitation requires some improvement of the algorithm for new key generation and some add-ons to the new record updating command (tableupdate() ). If you have framework with your own class for data handling, this might be ideal way. If no generic way to update views, better make it, otehrwise you will need to repead the same code for many places.

The main idea is the same as VFP programmers usually use with remote views to SQL Server. With SQL Server there is ability to get value of last ID key generated during last insert command. This value than placed into view manually. You need to make the same in the VFP algorithm of generating new key for table. Say, assign last generated key to the public variable (gnIDENTITY or something like that) each time new key for table was generated. Than view updating will look like following:

select MyView
llNewRecord = '3' $ GETFLDSTATE(-1) OR '4' $ GETFLDSTATE(-1)
Tableupdate(.T.,.T.) && sample only, might be different for 5-th buffering mode
* after this command for new record ID key will be generated and placed in the variable gnIDENTITY
if llNewRecord && if new record inserted
* update ID key in the new record
replace MyView.ID with gnIDENTITY
tableupdate(.T.,.T.) && sample only, might be different for 5-th buffering mode
* for above tableupdate view's ID field should not be updatable.
* With SQL server this cause no fields to update really, so update command did not sent to server
* With VFP probably this cause no delays too.
* However, above command required to drop all flags from record so it no longer marked
* as modified
* Note that SETFLDSTATE command don't work because bug, it is described in HackFox book
endif

Note that this way you should use no automatic updates. For automatic updates - no other way than described before...

>Thanks for your reply.
>
>I set the key to be updateable. But when I save the record back to base table, the base table get a new primary key from default value. eg.
>
>view new append record
>
>id = 12
>
>after tableupdate()
>
>base table id = 13
>
>How to solve this?
>
>TIA.
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform