Icon View Incident Report

Serious Serious
Reported By: James Relyea
Reported On: 11/17/2009
For: Version 2.03 Build 6
# 3104 Executing UPDATE Statements Against Tables with Nested Foreign Key Constraints Can Cause AV

I am getting frequent Access Violations in the Unicode server 2.03B5. The bad script is below. It breaks at the same point each time it's ran, and I don't know how to get around it. With my other stored procs that resuse the same cursor variable, I had to comment out sections in 1, close the cursor and release the variable values in others.

SCRIPT
BEGIN
declare cur cursor without return for selCur;
declare sql statement;
declare sqlUpdate statement;

declare idGuid guid ;
declare intOldId int;

--update the corp ids
prepare selCur from 'SELECT     tCorps.idCorpID, tCorps.zzCorpId
FROM         tCorps INNER JOIN
                      tCorps_tContacts_XRef ON tCorps.zzCorpId = tCorps_tContacts_XRef.zzCorpId';

start transaction on tables tCorps_tContacts_XRef;
begin                  
   open cur;
   fetch first from cur (idCorpID,zzCorpId) into idGuid,intOldId;
   while not eof(cur) do
      prepare sqlUpdate from 'update tCorps_tContacts_XRef set idCorpId=? where zzCorpId=?';
      execute sqlUpdate using idGuid,intOldId;
      fetch next from cur (idCorpID,zzCorpId) into idGuid,intOldId;
   end while;
--corp ids updated

--update the dept ids
   close cur;
   unprepare selCur;
   unprepare sqlUpdate;
   prepare selCur from 'SELECT     tDepts.idDeptId, tDepts.zzCorpDeptId
FROM         tCorps_tContacts_XRef INNER JOIN
                      tDepts ON tCorps_tContacts_XRef.zzDeptId = tDepts.zzCorpDeptId';

   open cur;
   fetch first from cur (idDeptId,zzCorpDeptId) into idGuid,intOldId;
   while not eof(cur) do
      prepare sqlUpdate from 'update tCorps_tContacts_XRef set idDeptId=? where zzDeptId=?';
      execute sqlUpdate using idGuid,intOldId;
      fetch next from cur (idDeptId,zzCorpDeptId) into idGuid,intOldId;
   end while;
--deptd ids updated

--update the contact ids
   close cur;
   unprepare selCur;
   unprepare sqlUpdate;
   prepare selCur from 'SELECT     tContacts.idContactId, tContacts.zzContactId
FROM         tCorps_tContacts_XRef INNER JOIN
                      tContacts ON tCorps_tContacts_XRef.zzContactId = tContacts.zzContactId';

   open cur;
   fetch first from cur (idContactId,zzContactId) into idGuid,intOldId;
   while not eof(cur) do
      prepare sqlUpdate from 'update tCorps_tContacts_XRef set idContactId=? where zzContactId=?';
      execute sqlUpdate using idGuid,intOldId;
      fetch next from cur (idContactId,zzContactId) into idGuid,intOldId;
   end while;
--contact ids updated

commit;

exception
   rollback;
   raise;
end;

END



Comments Comments
The problem had to do with EDB not handling the transaction flags properly for tables that were opened up as part of foreign-key relationships that were nested several layers deep. This would cause certain tables to be closed before they should have been, and cause the second UPDATE to AV.


Resolution Resolution
Fixed Problem on 11/19/2009 in version 2.03 build 7


Products Affected Products Affected
ElevateDB Additional Software and Utilities
ElevateDB DAC Client-Server
ElevateDB DAC Client-Server with Source
ElevateDB DAC Standard
ElevateDB DAC Standard with Source
ElevateDB DAC Trial
ElevateDB LCL Standard with Source
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image