Subject | Exception encountered during Drop Table encountered on subsequent operations |
---|---|
Author | Jeff Gaiche |
Post date | 2008-04-04T22:01:53Z |
Hello everyone,
We are encountering behavior which was not expected after a failed attempt to drop a table. When an exception occurs during a "drop table", it appears that that exception is re-raised on subsequent operations...even if they are not related to the table responsible for the original exception.
Here is a contrived scenario that might occur within our application:
#1. "Drop Table TABLE1" <----Assume this fails because a view exists referencing a column in this table
#2. "Insert Into TESTTABLE2 (SEQ) VALUES(12345)" <----This should execute...but...we receive the same exception that we received in #1
Can someone tell me if this is expected behavior and if so..what has to be done after #1 before subsequent database operations can execute ? We are using IBO 4.8.7 and FireBird 2.0.3.
I realize that changing meta data as part of a user data operation is not good practice (and we avoid this when possible)...but...my reality is that it does happen in our application in some areas.
Below is a code snippet from a test that I put together to demonstrate the behavior as well as the output produced .
I appreciate any help or advice offered -- Jeff Gaiche
procedure TForm1.Button1Click(Sender: TObject);
var
q: TIBOQuery;
table: TIBOTable;
begin
q:=nil; table:=nil;
try
q:=TIBOQuery.Create(nil);
q.IB_Connection:=IBODatabase1;
table:=TIBOTable.Create(nil);
table.TableName:='TESTTABLE1';
table.IB_Connection:=IBODatabase1;
//Create Tables and View Needed For Test
q.SQL.Text:='CREATE TABLE TESTTABLE1('+
'STUDENTSEQ Integer, '+
'LASTNAME Varchar(20) ) ';
q.ExecSQL;
q.SQL.Text:='CREATE TABLE TESTTABLE2('+
'STUDENTSEQ Integer, '+
'LASTNAME Varchar(20) ) ';
q.ExecSQL;
//Create a view on TESTTABLE1 so the "Drop Table" will fail
q.SQL.Text:='Create View TESTTABLE1VIEW as select LASTNAME from TESTTABLE1';
q.ExecSql;
//Begin Test
memo1.Lines.Add('About to call table.DeleteTable for TESTTABLE1');
try table.DeleteTable;
except
on e: exception do
memo1.Lines.Add('(This is Expected) Exception Deleting TESTTABLE1 :'+e.Message);
end;
q.SQL.Text:='Insert Into TESTTABLE2 (STUDENTSEQ, LASTNAME) VALUES(12345, ''BLAHBLAH'')';
memo1.Lines.Add('About to insert 12345, BLAHBLAH into TESTTABLE2');
try q.ExecSQL;
except
on e: exception do
memo1.Lines.Add('Exception Inserting into TESTTABLE2 :'+e.Message);
end;
finally q.Free; table.Free end
end;
-------test output------
About to call table.DeleteTable for TESTTABLE1
(This is Expected) Exception Deleting TESTTABLE1 :ISC ERROR CODE:335544351
ISC ERROR MESSAGE:
unsuccessful metadata update
cannot delete
COLUMN LASTNAME
there are 1 dependencies
About to insert 12345, BLAHBLAH into TESTTABLE2
Exception Inserting into TESTTABLE2 :ISC ERROR CODE:335544351
ISC ERROR MESSAGE:
unsuccessful metadata update
cannot delete
COLUMN LASTNAME
there are 1 dependencies
We are encountering behavior which was not expected after a failed attempt to drop a table. When an exception occurs during a "drop table", it appears that that exception is re-raised on subsequent operations...even if they are not related to the table responsible for the original exception.
Here is a contrived scenario that might occur within our application:
#1. "Drop Table TABLE1" <----Assume this fails because a view exists referencing a column in this table
#2. "Insert Into TESTTABLE2 (SEQ) VALUES(12345)" <----This should execute...but...we receive the same exception that we received in #1
Can someone tell me if this is expected behavior and if so..what has to be done after #1 before subsequent database operations can execute ? We are using IBO 4.8.7 and FireBird 2.0.3.
I realize that changing meta data as part of a user data operation is not good practice (and we avoid this when possible)...but...my reality is that it does happen in our application in some areas.
Below is a code snippet from a test that I put together to demonstrate the behavior as well as the output produced .
I appreciate any help or advice offered -- Jeff Gaiche
procedure TForm1.Button1Click(Sender: TObject);
var
q: TIBOQuery;
table: TIBOTable;
begin
q:=nil; table:=nil;
try
q:=TIBOQuery.Create(nil);
q.IB_Connection:=IBODatabase1;
table:=TIBOTable.Create(nil);
table.TableName:='TESTTABLE1';
table.IB_Connection:=IBODatabase1;
//Create Tables and View Needed For Test
q.SQL.Text:='CREATE TABLE TESTTABLE1('+
'STUDENTSEQ Integer, '+
'LASTNAME Varchar(20) ) ';
q.ExecSQL;
q.SQL.Text:='CREATE TABLE TESTTABLE2('+
'STUDENTSEQ Integer, '+
'LASTNAME Varchar(20) ) ';
q.ExecSQL;
//Create a view on TESTTABLE1 so the "Drop Table" will fail
q.SQL.Text:='Create View TESTTABLE1VIEW as select LASTNAME from TESTTABLE1';
q.ExecSql;
//Begin Test
memo1.Lines.Add('About to call table.DeleteTable for TESTTABLE1');
try table.DeleteTable;
except
on e: exception do
memo1.Lines.Add('(This is Expected) Exception Deleting TESTTABLE1 :'+e.Message);
end;
q.SQL.Text:='Insert Into TESTTABLE2 (STUDENTSEQ, LASTNAME) VALUES(12345, ''BLAHBLAH'')';
memo1.Lines.Add('About to insert 12345, BLAHBLAH into TESTTABLE2');
try q.ExecSQL;
except
on e: exception do
memo1.Lines.Add('Exception Inserting into TESTTABLE2 :'+e.Message);
end;
finally q.Free; table.Free end
end;
-------test output------
About to call table.DeleteTable for TESTTABLE1
(This is Expected) Exception Deleting TESTTABLE1 :ISC ERROR CODE:335544351
ISC ERROR MESSAGE:
unsuccessful metadata update
cannot delete
COLUMN LASTNAME
there are 1 dependencies
About to insert 12345, BLAHBLAH into TESTTABLE2
Exception Inserting into TESTTABLE2 :ISC ERROR CODE:335544351
ISC ERROR MESSAGE:
unsuccessful metadata update
cannot delete
COLUMN LASTNAME
there are 1 dependencies