Q140861: FIX: Default Value Not Evaluated Properly Using Stored Procs

Article: Q140861
Product(s): Microsoft FoxPro
Version(s): WINDOWS:3.0
Operating System(s): 
Keyword(s): kbbuglist kbfixlist
Last Modified: 24-MAR-2000

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual FoxPro for Windows, version 3.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

Under specific circumstances where two columns are calculating default values, a
stored procedure may not be executed rapidly enough resulting in default values
being inserted into a table's fields instead of the data generated by the stored
procedure.

CAUSE
=====

If the stored procedure that calculates the default value takes too long, a
default of 0 is used for numeric fields. This is a result of a timing issue, and
not a coding issue.

STATUS
======

Microsoft has confirmed this to be a problem in the Microsoft products listed at
the beginning of this article. This problem was corrected in Visual FoxPro 3.0b
for Windows.

MORE INFORMATION
================

The following code, when run using Visual FoxPro 3.0, demonstrates the behavior
noted in this article. After a few records, the program will fail with one of
several error messages. Using Visual FoxPro 3.0b, this code runs successfully.

Steps to Reproduce Problem
--------------------------

1. Place the following two functions into a program file called Bug.sp:

     FUNCTION spIncr
        PARAMETER cAliasName, cFname
        PRIVATE iNewVal
        lOldDel = SET ("DELETED")
        SET DELETED OFF
        SELECT MAX(&cFname) FROM (cAliasName) INTO ARRAY tmparr
        SET DELETED &lOldDel
        IF (_TALLY = 0)
          RETURN 1
        ENDIF
        iNewVal = tmparr(1) + 1
        RETURN iNewVal
     ENDFUNC

     FUNCTION spDefVal
        PARAMETER cAliasName, cFname, aDefRetVal
        PRIVATE aNewVal
        aNewVal = .NULL.
        ON Error *
        aNewVal = aDefRetVal
        aNewVal = &cAliasName..&cFname
        ON Error
        RETURN aNewVal
     ENDFUNC

2. Execute the following code from a second .prg file:

     SET SAFETY OFF
     CLOSE DATABASE ALL
     CREATE DATABASE 'bugreport.DBC'
     APPEND PROCEDURES FROM 'bug.sp'
     COMPILE DATABASE bugreport.DBC
     CREATE TABLE 'bug' (NR1 I NOT NULL Default spIncr("bug","nr1"), ;
                        NR2 I NOT NULL Default spDefVal("anytable", ;
                        "anyfield",0))
     ALTER TABLE 'bug' ADD PRIMARY KEY NR1 Tag NR1
     INDEX ON NR2 Tag NR2

     USE bug
     BROWSE NOWAIT
     FOR idat = 1 TO 200
        KEYBOARD "{CTRL+Y}" && Append blank
     NEXT

Additional query words: VFoxWin buglist3.00 fixlist3.00b fail

======================================================================
Keywords          :  kbbuglist kbfixlist
Technology        : kbVFPsearch kbAudDeveloper kbVFP300
Version           : WINDOWS:3.0
Issue type        : kbbug
Solution Type     : kbfix

=============================================================================