Page 1 of 1

BIG problem with Locate

Posted: Sat 02 Jul 2011 14:32
by vallemanden
Hi
I have BIG problems with locate
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.BeginUpdate;
Query3.SQL.Add('SELECT * from cust');
Query3.SQL.Add('WHERE custnr = ''' + Query1.FieldByName('custnr').AsString + '''');
Query3.SQL.EndUpdate;
Query3.open;

This Works ALL the time, but

Query3.Close;
Query3.SQL.Clear;
Query3.SQL.BeginUpdate;
Query3.SQL.Add('SELECT * from cust');
Query3.SQL.EndUpdate;
Query3.open;
Query3.Locate('custnr', Query1.FieldByName('custnr').AsString, [loPartialKey]);

only works sometimes ?

using delphi2010 on vista32 and MySQL
kind regards
Vallemanden

Posted: Mon 04 Jul 2011 08:54
by AndreyZ
Hello,

The point is that the query returns case insensitive values from the server, and the Locate method is case sensitive by default. To avoid the problem, you should use the following code:

Code: Select all

Query3.Locate('custnr', Query1.FieldByName('custnr').AsString, [loPartialKey, loCaseInsensitive]);

Posted: Mon 04 Jul 2011 09:49
by vallemanden
it does not seem to help that i use [loPartialKey, loCaseInsensitive]
custnr is NOT uniq and it is NOT index

i'm using v 3.50.0.14, lost my reg code for new version :?

opdated to newest version now
but no change

Posted: Mon 04 Jul 2011 12:06
by AndreyZ
Please post here or send to andreyz*devart*com a script to create and fill the cust table. Also please specify the exact string you are trying to locate.

Posted: Mon 04 Jul 2011 13:23
by vallemanden
replyed on your mail

Posted: Mon 04 Jul 2011 14:37
by AndreyZ
I cannot reproduce the problem. The Locate method searches for a specified record and makes it the active record. I've checked this functionality, and it works correctly. Please specify the exact string that the Locate method cannot correctly find in the cust table.

Posted: Mon 04 Jul 2011 15:15
by vallemanden
i try diff. custnr in a edit, you can see them in the table any times it return notthing and sometime it returnes the same as i tryed b4, and sometime the correct record

i try many custnr, not just 1 or the same

Posted: Tue 05 Jul 2011 08:15
by AndreyZ
Please specify if the cursor in the TDBGrid component jumps to another position when you call the Locate method. Also, to obtain the same result in the second case, you should use the Filter property instead of the Locate method. Here is an example:

Code: Select all

Query3.Close; 
Query3.SQL.Clear; 
Query3.SQL.BeginUpdate; 
Query3.SQL.Add('SELECT * from cust'); 
Query3.SQL.EndUpdate; 
Query3.Open;
Query3.Filter := 'custnr=' + Query1.FieldByName('custnr').AsString;
Query3.Filtered := True;