FIX: SET COLLATE & Queries - Additional Problem ScenariosID: Q181085
|
Queries in Visual FoxPro that compare integer fields in the WHERE clause of
a SQL Select statement between two or more tables may not return all
matching records. This problem occurs when the collation sequence is set to
anything but Machine.
This article provides some additional known scenarios where this happens in
addition to the scenarios described in the articles listed in the
REFERENCES section.
Use one of the following three workarounds to resolve this problem:
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This has been corrected in Visual FoxPro 6.0.
The SET COLLATE command, according to the Visual FoxPro Online help,
"Specifies a collation sequence for character fields in subsequent indexing
and sorting operations." The command should not have any affect on numeric
or integer type fields or their comparison.
SET COLLATE TO "Hungary"
*SET COLLATE TO "Machine"
CREATE CURSOR cur1 (field_a I)
**INDEX ON field_a TAG field_a
CREATE CURSOR cur2 (field_b I)
**INDEX ON field_b TAG field_b
SELECT 0
INSERT INTO cur1 VALUES (2838)
INSERT INTO cur2 VALUES (2830)
INSERT INTO cur2 VALUES (2838)
IF "05.00.00" $ VERSION()
SELECT * FROM cur1 INNER JOIN cur2 ON cur1.field_a=cur2.field_b
ELSE
SELECT * FROM cur1, cur2 WHERE cur1.field_a=cur2.field_b
ENDIF
SET COLLATE TO "Hungary"
Remove the comment from the following line of code:
*SET COLLATE TO "Machine"
Now, run the program. It should return one record.
CREATE CURSOR cur1 (field_a I)
**INDEX ON field_a TAG field_a
CREATE CURSOR cur2 (field_b I)
**INDEX ON field_b TAG field_b
Save and run the program. It should return one record.
CODEPAGE=1251
CLEAR ALL
CLEAR
** Store the current collation sequence to the variable yyy.
yyy=SET("collate")
** Setting collate to General, a collation sequence that illustrates
** the problem.
SET COLLATE TO "Russian"
*SET COLLATE TO "Machine"
** Create two cursors with one integer field in each.
CREATE CURSOR t1 (in1 i)
*INDEX ON in1 TAG in1
CREATE CURSOR t2 (in2 i)
*INDEX ON in2 TAG in2
** Populate each cursor with 2000 records, inserting the loop counter
** into the integer field.
FOR x=1 TO 2000
INSERT INTO t1 (in1) VALUES(x)
INSERT INTO t2 (in2) VALUES(x)
ENDFOR
** The SELECT statement to join the two tables.
SELECT * FROM t1,t2 WHERE in1=in2 INTO CURSOR t3
** Checking _Tally to see how many records the query returned.
WAIT WINDOW STR(_Tally)+" records returned by the query"
** Start of loop to determine what records are missing.
x=0
SCAN
x=x+1
IF NOT in1=x
WAIT WINDOW "Missing integer"+ STR(x)
x=in1
ENDIF
ENDSCAN
** Set collate back to its original setting.
SET COLLATE TO yyy
For additional information, please see the following articles in the Microsoft Knowledge Base:
Q176884 PRB: Problems with SET COLLATE and Queries with Integer Fields
Q164869 SET COLLATE TO "GENERAL" May Affect Search Results
Additional query words: kbvfp600fix
Keywords : kbMAC kbVFp FxprgIntl FxprgRushmore FxprgSql FxprgTable
Version : MACINTOSH:3.0b; WINDOWS:3.0,3.0b,5.0,5.0a
Platform : MACINTOSH WINDOWS
Issue type : kbbug
Last Reviewed: June 17, 1999