Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TableUpdate() & Tablerevert()
Message
De
31/12/1997 17:27:45
Nancy Folsom
Pixel Dust Industries
Washington, États-Unis
 
 
À
31/12/1997 16:32:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00068701
Message ID:
00068717
Vues:
31
Oh, I *like* PeekTableUpdate()!!!!
Seriously, what I do is set my ON ERROR just before I do the update, that on error will "fix" the problem, if there is one, issue retry, and then once tableupdate succeeds, sets the ON ERROR back to what it was before.

This is an example (and it's ONLY an example!). I have a table that I needed a quick-and-dirty incrementing primary key. I did NOT want to have to have a system look up table, AND I wanted to mess around with ON ERROR. So what I do is find the largest key in the table, then try to add a record with that key plus 1, if there's an error because it's a duplicate, then it just keeps incrementing. There's a whole of stuff missing here to make it bullet proof, and I wouldn't even *recommend* it as a normal thing to do, but it illustrates the concept (I hope!):

IF .NOT. this.readonly
LOCAL colderror, nRec, lSuc
*
nRec = RECNO( 'theTable' )
SET ORDER TO primaryKeyIndex IN theTable
GO BOTTOM IN theTable
ni = TheTable.id + 1
GO nRec IN theTable
*
colderror = ON( 'ERROR' )
ON ERROR DO Add_inMyTable WITH ni

INSERT INTO theTable (id) VALUES ( ni )
BEGIN TRANSACTION
lSuc = TableUpdate( .T., .F., 'theTable' )
IF lSuc
END TRANSACTION
ELSE
ROLLBACK
ENDIF

ON ERROR &cOldError
= this.activatecell( this.activerow, 1 )
= this.refresh()
ENDIF

PROCEDURE Add_inMyTable
LPARAMETER n_I
n_I = IIF( n_I = 9999, 0, n_I + 1 ) && this isn't good if I've got 10,000 records, of course!
RETRY
RETURN

>I have a question regarding the tableupdate() command. I was wondering if there was a way, programmatically, to check if a tableupdate() would succeed without it actually doing the update. Something along the lines of a PeekTableUpdate(). The reason for my question is that I have two tables that get updated at the same time and I would like my code to be more elegent in the case of one tableupdate() succeeding and the other one fails. Any suggestions would be helpful.
>
>Mark A. Struck
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform