PRB: Record Pointer Moves to EOF After INSERT - SQL FailsLast reviewed: April 30, 1996Article ID: Q130083 |
The information in this article applies to:
SYMPTOMSThe record pointer moves to the End of File marker (EOF) instead of remaining on the current record after an INSERT - SQL command fails.
CAUSEThe INSERT - SQL command failed because a field or row level validation rule was violated.
WORKAROUNDTo work around this behavior, run the following code to initialize a variable to store the record pointer position before the INSERT. If the INSERT fails, the variable can be used to restore the record pointer to its previous position using the ON ERROR routine. Create a new program named Ins_Trap: ***Begin Program Ins_Trap*** ON ERROR DO error_hand WITH ERROR() && When an error occurs the error_hand && procedure is called and passed && the error number using the ERROR() && function.CLOSE ALL CREATE DATABASE ins_dbc && Creates a new database. ** The following command adds a table with a row level rule: * CREATE TABLE ins_tbl (cfname C(20), clname C(20), CHECK cfname <> clname) * * The following two lines of code populate the empty table. * DO Insert_Proc WITH "FirstName","LastName" DO Insert_Proc WITH "Another", "Name" * * The next line causes the validation rule to fail: * DO Insert_Proc WITH "Name", "Name" ON ERROR WAIT WINDOW 'Done' PROCEDURE Insert_Proc PARAMETERS cFirst_Name, cLast_Name get_recno = RECNO() INSERT INTO ins_tbl VALUES (cFirst_Name,cLast_Name)ENDPROC PROCEDURE error_hand PARAMETERS error_num * * If a row or field level rule has been violated an error 1581, 1582 or * 1583 is returned. If this rule is violated, the record pointer is * moved to its previous position based on the value stored in the * variable get_recno. * IF error_num = 1581 OR error_num = 1582 OR error_num = 1583 GO get_recno ENDIFENDPROC *** End Program Ins_Trap *** Save and execute the INS_TRAP.PRG program.
STATUSThis behavior is by design.
MORE INFORMATION
Steps to Reproduce BehaviorIn the Command window, type the following commands:
CREATE DATABASE ins_dbc &&Creates a new databaseCREATE TABLE ins_tbl (cfname C(20), clname C(20), CHECK cfname <> clname) INSERT INTO ins_tbl VALUES("John", "Doe") INSERT INTO ins_tbl VALUES("Doe", "Doe") When the last INSERT INTO command fails, the record pointer is positioned at EOF (End of File).
|
Additional reference words: 3.00 VFoxWin
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |