BIG problem with Locate

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vallemanden
Posts: 19
Joined: Sat 11 Jun 2011 07:44

BIG problem with Locate

Post by vallemanden » Sat 02 Jul 2011 14:32

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

AndreyZ

Post by AndreyZ » Mon 04 Jul 2011 08:54

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]);

vallemanden
Posts: 19
Joined: Sat 11 Jun 2011 07:44

Post by vallemanden » Mon 04 Jul 2011 09:49

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

AndreyZ

Post by AndreyZ » Mon 04 Jul 2011 12:06

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.

vallemanden
Posts: 19
Joined: Sat 11 Jun 2011 07:44

Post by vallemanden » Mon 04 Jul 2011 13:23

replyed on your mail

AndreyZ

Post by AndreyZ » Mon 04 Jul 2011 14:37

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.

vallemanden
Posts: 19
Joined: Sat 11 Jun 2011 07:44

Post by vallemanden » Mon 04 Jul 2011 15:15

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

AndreyZ

Post by AndreyZ » Tue 05 Jul 2011 08:15

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;

Post Reply