Page 1 of 1

Length for String in Locate?

Posted: 07.02.2017, 23:51
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.

Re: Length for String in Locate?

Posted: 08.02.2017, 10:39
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

Re: Length for String in Locate?

Posted: 09.02.2017, 18:02
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. :)

Re: Length for String in Locate?

Posted: 10.02.2017, 08:22
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?

Re: Length for String in Locate?

Posted: 10.02.2017, 19:48
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.

Re: Length for String in Locate?

Posted: 10.02.2017, 19:50
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.

Re: Length for String in Locate?

Posted: 10.02.2017, 20:18
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:

Re: Length for String in Locate?

Posted: 12.02.2017, 11:52
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