------------------------------------------------------------------------------------------ [BUG/PRB.] VFP 9.0 FIX - THE MAX() AND MIN() FUNCTIONS IN THE SELECT-SQL COMMAND January 2024 ------------------------------------------------------------------------------------------ CCB 1. BUG: In vfp9 (and vfp6, vfp7, vfp8), we can't use the MAX() and MIN() functions in the SELECT-SQL command, because there are 2 SQL aggregate functions with the same names. 2. CAUSE: There are some BUGs in the following code. 3. RESOLUTION: We can write some code to fix the BUG. Fun453dd4 :: ; proc near push ebx ;0x00453dd4 : 53 mov ebx , dword ptr [ edi + 4 ] ;0x00453dd5 : 8b5f04 cmp ebx , 046h ;0x00453dd8 : 83fb46 push ebp ;0x00453ddb : 55 mov ebp , dword ptr [ esp + 16 ] ;0x00453ddc : 8b6c2410 push esi ;0x00453de0 : 56 mov esi , eax ;0x00453de1 : 8bf0 mov dword ptr [ esp + 20 ] , esi ;0x00453de3 : 89742414 je Label5ca4e1 ;0x00453de7 : 0f84f4661700 cmp ebx , 044h ;0x00453ded : 83fb44 je Label5ca4eb ;0x00453df0 : 0f84f5661700 Label453df6 :: mov byte ptr [esi] , 043h ;0x00453df6 : c60643 inc esi ;0x00453df9 : 46 cmp ebx , 01FCh ;0x00453dfa : 81fbfc010000 mov byte ptr [edi] , 07h ;0x00453e00 : c60707 je Label446aa7 ;0x00453e03 : 0f849e2cffff Label453e09 :: pushd 00h ;0x00453e09 : 6a00 pushd 01h ;0x00453e0b : 6a01 pushd 00h ;0x00453e0d : 6a00 push edi ;0x00453e0f : 57 call Fun430428 ;0x00453e10 : e813c6fdff Label453e15 :: mov al , byte ptr [edi] ;0x00453e15 : 8a07 cmp al , 04h ;0x00453e17 : 3c04 jne Label453e28 ;0x00453e19 : 750d cmp dword ptr [ edi + 4 ] , 040BEh ;0x00453e1b : 817f04be400000 je Label5ca508 ;0x00453e22 : 0f84e0661700 Label453e28 :: cmp al , 07h ;0x00453e28 : 3c07 je Label5ca52d ;0x00453e2a : 0f84fd661700 Label453e30 :: cmp byte ptr [edi] , 04h ;0x00453e30 : 803f04 jne Label453e3f ;0x00453e33 : 750a cmp dword ptr [ edi + 4 ] , 03h ;0x00453e35 : 837f0403 je Label5ca53e ;0x00453e39 : 0f84ff661700 Label453e3f :: mov ecx , dword ptr [ esp + 16 ] ;0x00453e3f : 8b4c2410 and ebp , 0FFFFFFFDh ;0x00453e43 : 83e5fd push ebp ;0x00453e46 : 55 push ecx ;0x00453e47 : 51 Label453e48 :: mov ecx , edi ;0x00453e48 : 8bcf mov edx , esi ;0x00453e4a : 8bd6 call Fun4344bf ;0x00453e4c : e86e06feff test eax , eax ;0x00453e51 : 85c0 jl Label453e9f ;0x00453e53 : 7c4a je Label5ca552 ;0x00453e55 : 0f84f7661700 add esi , eax ;0x00453e5b : 03f0 cmp byte ptr [edi] , 07h ;0x00453e5d : 803f07 je Label5ca55d ;0x00453e60 : 0f84f7661700 Label453e66 :: cmp byte ptr [edi] , 01h ;0x00453e66 : 803f01 jne Label5ca56e ;0x00453e69 : 0f85ff661700 ; ; ------------------------------------------------------------------------------- ; VFP 9.0 FIX - THE MAX() AND MIN() FUNCTIONS IN THE SELECT-SQL COMMAND ; April 2023 ; ------------------------------------------------------------------------------- ; CCB ; ; In vfp9, we can't use the MAX() and MIN() functions in the SELECT-SQL command, ; because there are 2 SQL aggregate functions with the same names. ; In VFP Advanced, we can use the MAX() and MIN() functions in the SELECT-SQL command. ; ; 2023/4/11, by ccb ; cmp dword ptr vfpa_sys9131_data,00h je Label453e6f cmp dword ptr [ edi + 4 ] , 07h jne Label453e6f cmp ebx , 044h je Label453e09 cmp ebx , 046h je Label453e09 cmp ebx , 01FEh je Label453e6f_max cmp ebx , 01FDh je Label453e6f_min jmp Label453e6f Label453e6f_max :: mov ebx , 044h jmp Label453e09 Label453e6f_min :: mov ebx , 046h jmp Label453e09 Label453e6f :: cmp dword ptr [ edi + 4 ] , 03h ;0x00453e6f : 837f0403 jne Label5ca56e ;0x00453e73 : 0f85f5661700 ; ; ------------------------------------------------------------------------------- ; VFP 9.0 FIX - THE MAX() AND MIN() FUNCTIONS IN THE SELECT-SQL COMMAND ; April 2023 ; ------------------------------------------------------------------------------- ; CCB ; ; In vfp9, we can't use the MAX() and MIN() functions in the SELECT-SQL command, ; because there are 2 SQL aggregate functions with the same names. ; In VFP Advanced, we can use the MAX() and MIN() functions in the SELECT-SQL command. ; ; 2023/4/11, by ccb ; cmp dword ptr vfpa_sys9131_data,00h je Label453e79 cmp ebx , 044h je Label453e79_max cmp ebx , 046h je Label453e79_min jmp Label453e79 Label453e79_max :: Label453e79_min :: mov byte ptr [esi] , bl pushd 00h pushd 01h pushd 00h push edi call Fun430428 jmp Label453e8e Label453e79 :: pushd 00h ;0x00453e79 : 6a00 mov byte ptr [esi] , 03h ;0x00453e7b : c60603 pushd 01h ;0x00453e7e : 6a01 mov byte ptr [esi] , 0EAh ;0x00453e80 : c606ea pushd 00h ;0x00453e83 : 6a00 inc esi ;0x00453e85 : 46 push edi ;0x00453e86 : 57 mov byte ptr [esi] , bl ;0x00453e87 : 881e call Fun430428 ;0x00453e89 : e89ac5fdff Label453e8e :: mov edx , dword ptr [ esp + 16 ] ;0x00453e8e : 8b542410 mov byte ptr [ edx + 16 ] , 00h ;0x00453e92 : c6421000 mov edx , dword ptr [ esp + 20 ] ;0x00453e96 : 8b542414 mov eax , esi ;0x00453e9a : 8bc6 sub eax , edx ;0x00453e9c : 2bc2 inc eax ;0x00453e9e : 40 Label453e9f :: pop esi ;0x00453e9f : 5e pop ebp ;0x00453ea0 : 5d pop ebx ;0x00453ea1 : 5b ret 08h ;0x00453ea2 : c20800 4. APPLIES TO: VFP 6.0.8167.0 VFP 6.0.8961.0 (SP5) VFP 7.0.0.9262 VFP 7.0.0.9465 (SP1) VFP 8.0.0.2521 VFP 8.0.0.3117 (SP1) 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) The bug has been fixed in VFP Advanced. IMPORTANT NOTE: In vfp9 (and vfp6, vfp7, vfp8), we can use the MAX[] and MIN[] functions in the SELECT-SQL command, for example, * please refer to: https://www.foxite.com/archives/bug-or-alzheimer-0000494196.htm SELECT MAX[x1,x2] AS xmax FROM test INTO CURSOR test_tmp nofilter SELECT MIN[x1,x2] AS xmin FROM test INTO CURSOR test_tmp nofilter We can also use the following code: SELECT IIF(x1>=x2,x1,x2) AS xmax FROM test INTO CURSOR test_tmp nofilter && it is the same as MAX(x1,x2). SELECT IIF(x1<=x2,x1,x2) AS xmin FROM test INTO CURSOR test_tmp nofilter && it is the same as MIN(x1,x2). 5. REFERENCE WEBSITES: 1, baiyujia.com: http://www.baiyujia.com http://www.baiyujia.com/vfpdocuments/f_vfp9fix267.asp 2, foxite.com: https://www.foxite.com/archives/bug-or-alzheimer-0000494173.htm 6. OTHER: For reference only, there is no guarantees. Any questions or suggestions, please send me an email at ccb2000@163.com. |