-------------------------------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - CONVERTE ALL CHARACTERS WHEN CONVERTING CHARACTER FIELDS TO NUMERIC FIELDS
                                 January 2025
                 -------------------------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9, for some update table commands,
     it will convert up to 18 characters when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.

     The bug only occurs in vfp 9.0.0.3504 (SP1) or later, it does not occur in vfp6, vfp7, vfp8 and vfp 9.0.0.2412.

     The bug occurs in the following update table commands:
     ALTER TABLE - SQL command
     APPEND command
     GATHER command
     MODIFY STRUCTURE command
     UPDATE - SQL command

     There is a test program:

     *PROC testaltertable

     CLOSE DATABASES ALL
     CLOSE TABLES ALL

     SELECT 0
     CREATE TABLE ("testaltertable.dbf") (fld1 c(30))
     USE

     SELECT 0
     USE ("testaltertable.dbf") ALIAS testaltertable EXCLUSIVE
     APPE BLANK
     REPL fld1 WITH SPACE(15)+"123456.78"
     ?fld1
     WAIT

     ALTER TABLE ("testaltertable.dbf") ALTER fld1 N(20,2)
     ?fld1 && Displays 123.00, the data has been lost.
     WAIT
     USE

     RETURN

     * END OF PROC TESTALTERTABLE.


2. CAUSE:

     In VFP 9.0.0.3504 (SP1) or later, it will convert up to 18 characters when converting Character or Varchar fields
     to Numeric, Float, Double or Integer fields, for example,
     fld1 = SPACE(15)+"123456.78"
     it will convert SPACE(15)+"123" to a Numeric field,
     so fld1 = 123.00

     In VFP Advanced, it will convert all characters (up to 255 characters) when converting Character or Varchar fields
     to Numeric, Float, Double or Integer fields, for example,
     fld1 = SPACE(15)+"123456.78"
     it will convert SPACE(15)+"123456.78" to a Numeric field,
     so fld1 = 123456.78
     so there is no the bug.

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label597f85 ::
             pushd 0FFh                                                      ;0x00597f85 :        68ff000000
             mov eax , ebx                                                   ;0x00597f8a :        8bc3
             call Fun75ee1b                                                  ;0x00597f8c :        e88a6e1c00
             mov  eax , dword ptr [ ebx + 8 ]                                ;0x00597f91 :        8b4308
             cmp eax , esi                                                   ;0x00597f94 :        3bc6
             jb Label597f9a                                                  ;0x00597f96 :        7202


     ;
     ;                 --------------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CONVERTE ALL CHARACTERS WHEN CONVERTING CHARACTER FIELDS TO NUMERIC FIELDS
     ;                                December 2024
     ;                 --------------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, for some update table commands,
     ; it will convert up to 18 characters when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ; In VFP Advanced, for some update table commands,
     ; it will convert all characters (up to 255 characters) when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ;
     ; 2024/12/20, by ccb
     ;

             cmp dword ptr vfpa_sys9179_data,00h
             jne Label597f9a


             mov eax , esi                                                   ;0x00597f98 :        8bc6

     Label597f9a ::
             mov  dword ptr [ ebx + 8 ] , eax                                ;0x00597f9a :        894308

     Label597f9d ::
             mov  eax , dword ptr [ ebx + 8 ]                                ;0x00597f9d :        8b4308
             cmp eax , esi                                                   ;0x00597fa0 :        3bc6
             mov ecx , eax                                                   ;0x00597fa2 :        8bc8
             jb Label597fa8                                                  ;0x00597fa4 :        7202


     ;
     ;                 --------------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CONVERTE ALL CHARACTERS WHEN CONVERTING CHARACTER FIELDS TO NUMERIC FIELDS
     ;                                December 2024
     ;                 --------------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, for some update table commands,
     ; it will convert up to 18 characters when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ; In VFP Advanced, for some update table commands,
     ; it will convert all characters (up to 255 characters) when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ;
     ; 2024/12/20, by ccb
     ;

             cmp dword ptr vfpa_sys9179_data,00h
             jne Label597fa8


             mov ecx , esi                                                   ;0x00597fa6 :        8bce

     Label597fa8 ::
             pushd 02Eh                                                      ;0x00597fa8 :        6a2e
             lea eax ,  dword ptr [ ebx + 44 ]                               ;0x00597faa :        8d432c
             mov  dword ptr [ ebx + 8 ] , ecx                                ;0x00597fad :        894b08
             call Fun43cd2a                                                  ;0x00597fb0 :        e8754deaff


     ;
     ;                 --------------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CONVERTE ALL CHARACTERS WHEN CONVERTING CHARACTER FIELDS TO NUMERIC FIELDS
     ;                                December 2024
     ;                 --------------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9, for some update table commands,
     ; it will convert up to 18 characters when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ; In VFP Advanced, for some update table commands,
     ; it will convert all characters (up to 255 characters) when converting Character or Varchar fields to Numeric, Float, Double or Integer fields.
     ;
     ; 2024/12/20, by ccb
     ;

             cmp dword ptr vfpa_sys9179_data,00h
             je Label597fb5
             cmp dword ptr [ ebx + 8 ] , 012h
             jb Label597fb5
             mov dword ptr [ ebx + 8 ] , 012h


     Label597fb5 ::
             jmp Label59812b                                                 ;0x00597fb5 :        e971010000


4. APPLIES TO:

     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.

     IMPORTANT NOTE:
     In VFP 9.0.0.3504 (SP1) and later, we can use the following code:
     USE ("testaltertable.dbf") ALIAS testaltertable EXCLUSIVE
     REPLACE ALL fld1 WITH ALLTRIM(fld1)
     ALTER TABLE ("testaltertable.dbf") ALTER fld1 N(20,2)
     and then there is no the bug.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix369.asp


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.