Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do try again if an insert fails?
Message
De
01/04/2003 11:29:06
 
 
À
01/04/2003 11:06:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00772428
Message ID:
00772441
Vues:
5
Steve

You can set up a dummy ON ERROR routine to trap an error and then restore the original error routine afterwards. eg:
* Save current ON ERROR routine
cOrgError = SET("ERROR")

* Set up dummy error trap
lError  =.F.
ON ERROR lError = .T.  && If an error occurs this will set lError to .T.

* Insert code here to test for
USE FILE EXCLUSIVE

* Restore original error routine
ON ERROR &cOrgError

* Now test your dummy error routine variable
IF !lError

  * Dummy error routine did not fire. All ok to continue

ELSE

  * Dummy error routine fired becuase lError is now .T.
  * Code to handle error condition

ENDIF
There are various ways to use this technique eg in a loop for x times or untill success, etc. In VFP8 you can be more sophisticated using the TRY...CATCH...FINALLY construct.

-

Use < pre > and < /pre > to highight code - no spaces.



>I have a bit of code that inserts a record into a table. The problem is that there is an external program, that i did not write, that requires exclusive use of that table. occasionally there is an error, when they bump heads.
>
>I would like to add some sort of trap that would test to see if the table is available at that moment, if it's not then try again several times before erroring out or succeeding.
>
>********************************
>Insert into 'i:\data\ecnc\data\bcexclusive.dbf' (fnction, forg_date, ;
> forg_time, fdate, ftime, fempno,;
> fjobno, foperno, fcompqty, fscrpqty, flead, fsetup, frework);
> values (cFunction, cdate, cOrg_Time,;
> cdate, cTime, cEmpNo,;
> cJobNo, cOpNo, nCompleted, 0, 'Y', cSetup, 'N')
>use in bcexclusive &&Close table. bcposting needs exclusive use
>*********************************
>
>Oh, by the way, how do i highlight my code above, for the post here on UT?
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform