Friday, July 18, 2008

Thinking Outside the Box

As many of you know, right now I am working on a project with a lot of legacy FoxPro code. This week some team members decided to add a primary key to several of our old Fox tables. They chose an auto incrementing integer field for the primary key. Since they thought this change would be fairly harmless, they made it right on production data without running it through testing first.

A few hours into the work day (data changes are made after hours) people started getting “Field ID is ReadOnly” (2088) errors. The problem was discussed during our morning SCRUM and immediately the developers were ready to drop the field. You see there is SCATTER MEMVAR MEMO and GATHER MEMVAR MEMO code all over the place in the application and no one wanted to find each one and modify it to bypass the new ID field. I figured that we could handle it through the error handler using code like this:

IF e_no = 2088 AND 'ID'$UPPER(er_mess)
on error do err_prg with ;
error(), ;
program(), ;
lineno(), ;
message(), ;

Releasing the id variable and retrying the command fixes the problem and if anyone
was relying on a different value they were hosed anyway. So, good code in one spot to fix not so good code in many places.

During the writing of this blog entry, I looked up error 2088 in the help file and stumbled on SET AUTOINCERROR that I probably read about at one time when it didn’t apply to me and promptly forgot about. That would have been a much easier fix but less fun to blog about.


At 7/25/2008 10:29 AM, Blogger Andrew MacNeill said...

Heh! I had a similar problem two years ago where the president at my client said (on his 25 year old system) - "put a primary key on everything".

We weren't using incremental keys but it was using a cursor adapter. Needless to say, a few testing iterations later...everything finally calmed down.

But good tip about the SET AUTOINCERROR! Yet another one of those commands you forget if you don't use!


Post a Comment

<< Home