----------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - FIX THE CAST() FUNCTION FOR THE VFPOLEDB DRIVER
                                 January 2024
                 ----------------------------------------------------------------------------------
                                     CCB



1. BUG:

     There is a test program from Mr. Cetin Basoz:

     *PROC testcastfunctionforvfpoledb

     Local loCon As Adodb.Connection,;
       loCmd As Adodb.Command, ;
       loParm As Adodb.Parameter

     loCon = Createobject('AdoDb.Connection')
     loCmd = Createobject('Adodb.Command')

     loCon.ConnectionString='Provider=VFPOLEDB;Data Source=test.dbc'
     loCon.Open()

     loCmd.ActiveConnection=loCon
     loCmd.CommandText='update test set fld2 = cast(? as date) where fld1 = 0'

     loParm = loCmd.CreateParameter('fld2')
     loParm.Type = 129  && adChar
     loParm.Direction = 1
     loParm.Value = "^2018/09/22"
     loParm.Size = LEN(loParm.Value)
     loCmd.Parameters.Append( loParm )

     loCmd.Execute()

     loCon.Close

     Use test
     Locate for fld1 = 0
     Browse
     Use

     RETURN

     * END OF PROC TESTCASTFUNCTIONFORVFPOLEDB.

     Usually, we think fld2 is always equal to DATE(2018,9,22),
     But now fld2 is equal to an empty date.


2. CAUSE:

     There are some BUGs for the CAST() function in the VFPOLEDB driver,
     it can only convert Character data to Integer, Float, Numeric and DateTime data,
     it can not convert Character data to Date data,
     so fld2 is equal to an empty date.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label53d838 ::
             mov eax ,  dword ptr [ Data937220 ]                             ;0x0053d838 :        a120729300
             mov  dword ptr [ ebp + 0FFFFFEC4h ] , eax                       ;0x0053d83d :        8985c4feffff
             xor eax , eax                                                   ;0x0053d843 :        33c0
             inc eax                                                         ;0x0053d845 :        40
             mov  dword ptr [ ebp - 4 ] , eax                                ;0x0053d846 :        8945fc
             mov dword ptr [ Data93da28 ] ,  eax                             ;0x0053d849 :        a328da9300
             mov  eax , dword ptr [ ebp - 56 ]                               ;0x0053d84e :        8b45c8
             mov  ecx , dword ptr [eax]                                      ;0x0053d851 :        8b08
             lea edx ,  dword ptr [ ebp + 0FFFFFF44h ]                       ;0x0053d853 :        8d9544ffffff
             push edx                                                        ;0x0053d859 :        52
             lea edx ,  dword ptr [ ebp + 0FFFFFED0h ]                       ;0x0053d85a :        8d95d0feffff
             push edx                                                        ;0x0053d860 :        52
             push  dword ptr [ ebp - 52 ]                                    ;0x0053d861 :        ff75cc
             push  dword ptr [ ebp - 92 ]                                    ;0x0053d864 :        ff75a4
             pushd 03h                                                       ;0x0053d867 :        6a03
             push  dword ptr [ ebp - 116 ]                                   ;0x0053d869 :        ff758c
             pushd offset Data9223dc                                                  ;0x0053d86c :        68dc239200
             push  dword ptr [ ebp + 0FFFFFF14h ]                            ;0x0053d871 :        ffb514ffffff
             push eax                                                        ;0x0053d877 :        50
             call  dword ptr [ ecx + 24 ]                                    ;0x0053d878 :        ff5118
             mov  dword ptr [ ebp - 48 ] , eax                               ;0x0053d87b :        8945d0


     ;
     ;                 -----------------------------------------------------------------------
     ;                      VFP 9.0 FIX - FIX THE CAST() FUNCTION FOR THE VFPOLEDB DRIVER
     ;                                September 2018
     ;                 -----------------------------------------------------------------------
     ;                                     CCB
     ;
     ; Fix the CAST() function for the VFPOLEDB driver.
     ;
     ; 2018/9/22, by ccb
     ;

             call vfpa_fixcastfunctionforvfpoledb


     Label53d87e ::
             or  dword ptr [ ebp - 4 ] , 0FFFFFFFFh                          ;0x0053d87e :        834dfcff
             mov  eax , dword ptr [ ebp - 108 ]                              ;0x0053d882 :        8b4594
             mov dword ptr [ Data93da28 ] ,  eax                             ;0x0053d885 :        a328da9300

     Now in VFP Advanced, the CAST() function can convert Character data to Integer, Float, Numeric, DateTime and Date data.


4. APPLIES TO:

     VFP 9.0.0.2412
     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)

     VFPOLEDB driver 9.0.0.2412
     VFPOLEDB driver 9.0.0.5815

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

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

     2, foxite.com:
     https://www.foxite.com/archives/yet-another-bug-0000291461.htm

     3, microsoft.com:
     https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum?view=sql-server-2017


6. OTHER:

     For reference only, there is no guarantees.

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