Length for String in Locate?

The official tester's forum for ZeosLib 7.1. Ask for help, post proposals or solutions.
Post Reply
ToodleDoo
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 07.02.2017, 23:40

Length for String in Locate?

Post by ToodleDoo »

Hi, is there a max length for the String in Locate?

I am using Sqlite-3, and a combination of String-items to give me a unique ID for some data. When I use Locate to find specific records, it sometimes doesn't work correctly, returning things not even close.

I am using
Date + Time + DataStr

The DataStr can often be 120-Characters or more in length and I am wondering if the Locate is not using the full string.

I can truncate the DataStr a little, but I still need it to be human-recognizable indicating what it is. The Time is formatted to the 100th of seconds to always make it unique.

Thank you.
Ubuntu 14.04-LTS, Acer i5, 6GB, 256GB-SSD, Lazarus 1.6.2, Zeos 7.1
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Length for String in Locate?

Post by marsupilami »

Hello ToodleDoo,

hmmm - I didn't look into that code yet. But it might be that the comparison of strings is done based on the current locale settings in Windows and these might make some strings that are different look the same for comparisons. In some regions a and á are the same when sorting strings. Maybe that is something that you are seeing here?

With best regards,

Jan
ToodleDoo
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 07.02.2017, 23:40

Re: Length for String in Locate?

Post by ToodleDoo »

marsupilami wrote:In some regions a and á are the same when sorting strings.Jan
Thanks for the follow up, but all the text is Normal old US-English, not umlaut in sight. :)
Ubuntu 14.04-LTS, Acer i5, 6GB, 256GB-SSD, Lazarus 1.6.2, Zeos 7.1
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Length for String in Locate?

Post by marsupilami »

Ok, I just had to ask. Is there a chance for you to provide a small example where the problem occurs? A small project and a database or database script?
ToodleDoo
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 07.02.2017, 23:40

Re: Length for String in Locate?

Post by ToodleDoo »

marsupilami wrote:Is there a chance for you to provide a small example where the problem occurs?
I don't have a small copy of the database, but I changed the process to create a Hash of the data and save that.
The hash is not working either. Here's some details. The Unique Hashes are being saved and recalled OK, just not being seen by Locate.

Code: Select all

uses
  MD5;
function EmailHash(aStr : String) : String;
begin
  Result:=MD5Print(MD5String(aStr));
end;
const
  fldHash = 'zHash';
var
  aHash : String;
begin
    aHash:=EmailHash(memoIn.Lines.Text); // ac3f4687903bcd83f9e6903bc
    if dm.tblEmails.Locate(fldHash,aHash,[loCaseInsensitive]) then
    begin
      LogEmails('DUP > '+aDate+' : '+aHash);
    end else
    begin
      dm.tblEmails.Insert;
 
Also on the subject of Locate, I noticed this behaviour with a TEdit...

Code: Select all

   // This never finds anything even if the Name exists
    if dm.tblEmails.Locate(fldName,edName.Text,[loCaseInsensitive]) then
  // but this does
    tStr:=edName.Text;
    if dm.tblEmails.Locate(fldName,tStr,[loCaseInsensitive]) then
 
I'll try to make some time to create a little working example, but there is something happening with Locate, not sure if it is me, Lazarus 1.6.2, Ubuntu 14.04, or Zeos 7.2.1-rc. :)

I appreciate any help.
Ubuntu 14.04-LTS, Acer i5, 6GB, 256GB-SSD, Lazarus 1.6.2, Zeos 7.1
ToodleDoo
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 07.02.2017, 23:40

Re: Length for String in Locate?

Post by ToodleDoo »

marsupilami wrote:Is there a chance for you to provide a small example where the problem occurs?
I don't have a small copy of the database, but I changed the process to create a Hash of the data and save that.
The hash is not working either. Here's some details. The Unique Hashes are being saved and recalled OK, just not being seen by Locate.

Code: Select all

uses
  MD5;
function EmailHash(aStr : String) : String;
begin
  Result:=MD5Print(MD5String(aStr));
end;
const
  fldHash = 'zHash';
var
  aHash : String;
begin
    aHash:=EmailHash(memoIn.Lines.Text); // ac3f4687903bcd83f9e6903bc
    if dm.tblEmails.Locate(fldHash,aHash,[loCaseInsensitive]) then
    begin
      LogEmails('DUP > '+aDate+' : '+aHash);
    end else
    begin
      dm.tblEmails.Insert;
 
Also on the subject of Locate, I noticed this behaviour with a TEdit...

Code: Select all

   // This never finds anything even if the Name exists
    if dm.tblEmails.Locate(fldName,edName.Text,[loCaseInsensitive]) then
  // but this does
    tStr:=edName.Text;
    if dm.tblEmails.Locate(fldName,tStr,[loCaseInsensitive]) then
 
I'll try to make some time to create a little working example, but there is something happening with Locate, not sure if it is me, Lazarus 1.6.2, Ubuntu 14.04, or Zeos 7.2.1-rc. :)

I appreciate any help.
Ubuntu 14.04-LTS, Acer i5, 6GB, 256GB-SSD, Lazarus 1.6.2, Zeos 7.1
ToodleDoo
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 07.02.2017, 23:40

Re: Length for String in Locate?

Post by ToodleDoo »

Arrrggghgh -- STOP!!

It was someone working on the project. They had done... "// tblEmails.Filtered:=False;"

Sorry for the bother. Appreciate the time taken to look into it.

Oh and I am the only one working on the project! :oops:
Ubuntu 14.04-LTS, Acer i5, 6GB, 256GB-SSD, Lazarus 1.6.2, Zeos 7.1
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Length for String in Locate?

Post by marsupilami »

Hello Hello ToodleDoo,

don't worry, things like that happen. Although I don't know why the Locate method shouldn't work when Filtered is false?

With best regards,

Jan
Post Reply