View Issue Details

IDProjectCategoryView StatusLast Update
0015725FPCDatabasepublic2011-05-01 21:45
ReporterCarlos Valente Assigned ToJoost van der Sluis  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
PlatformI386OSLinux 
Product Version2.4.0 
Target Version2.4.2Fixed in Version2.4.2 
Summary0015725: The options loCaseInsensitive and loPartialKey of the locate method in the SQLdb doesn't work correctly.
DescriptionThe options loCaseInsensitive and loPartialKey of the locate method in the SQLdb doesn't work correctly.

In the KeyPress event of the object TDBGrid, typing the letter B, it is not the first word that start with that letter (eg, Bruno),
but if there is one name B (only), he finds him.

Steps To Reproduceprocedure TfrmPrestadores.grdDadosKeyPress(Sender: TObject; var Key: char);
begin
  DM.tbPrestadores.Locate('Nome', key, [loCaseInsensitive,loPartialKey]);
end;
Additional InformationThe database I'm using is MySQL 5.
The version of Lazarus that I'm using is 0.9.29;
TagsNo tags attached.
Fixed in Revision15209
FPCOldBugId0
FPCTarget
Attached Files

Relationships

has duplicate 0017684 closedJoost van der Sluis TBuFDataset.Locate : TLocateOptions 

Activities

LacaK

2010-02-10 10:08

developer   ~0034346

Last edited: 2010-02-15 07:44

Looking at TBufDataset.Locate method in bufdataset.pas I see, that parameter Options: TLocateOptions is not used.

We can fix it by adding:
for FieldNr:=0 to FieldsAmount-1 do
 +begin
ProcessFieldCompareStruct(TField(SearchFields[FieldNr]),DBCompareStruct[FieldNr]);
 +DBCompareStruct[FieldNr].Option:=options;
 +end;

But looking at IndexCompareRecords() and DBCompareText() I see, that only loCaseInsensitive is implemented.
So we should add test for loPartialKey in DBCompareText() and use
AnsiStrLIComp or AnsiStrLComp(pchar(subValue),pchar(aValue), Length(subValue)):
begin
  if [loCaseInsensitive,loPartialKey]<=options then
    Result := AnsiStrLIComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
  else if loPartialKey in options then
    Result := AnsiStrLComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
  else if loCaseInsensitive in options then
    Result := AnsiCompareText(pchar(subValue),pchar(aValue))
  else
    Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
end;

Carlos Valente

2010-02-10 15:48

reporter   ~0034358

Excuse me, but I am newbie and my English is not very good. What should I do exactly? Thank you very much.

LacaK

2010-02-11 07:14

developer   ~0034381

Last edited: 2010-02-15 09:46

You have 2 options:
1. Fix-add missing functionality by your own hands (it requires changing source units of FreePascal in your installation)
or
2. Wait if maintainer (developer) of fcl-db package will do it (watch this bug report if status changed), it may take weeks or months ;-)

Please next questions (if any) ask in Lazarus forums in Database section http://lazarus.freepascal.org/index.php/board,16.0.html
...
http://lazarus.freepascal.org/index.php/topic,8609.0.html

2010-02-15 09:45

 

bufdataset.diff (1,069 bytes)   
--- f:\tmp\bufdataset.pas.orig	Mon Feb 15 09:37:24 2010
+++ f:\tmp\bufdataset.pas	Fri Feb 12 12:38:50 2010
@@ -524,9 +524,12 @@ begin
 end;
 
 function DBCompareText(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
-
 begin
-  if loCaseInsensitive in options then
+  if [loCaseInsensitive,loPartialKey]<=options then
+    Result := AnsiStrLIComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
+  else if loPartialKey in options then
+    Result := AnsiStrLComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
+  else if loCaseInsensitive in options then
     Result := AnsiCompareText(pchar(subValue),pchar(aValue))
   else
     Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
@@ -2733,7 +2736,10 @@ begin
 
     SetLength(DBCompareStruct,FieldsAmount);
     for FieldNr:=0 to FieldsAmount-1 do
+      begin
       ProcessFieldCompareStruct(TField(SearchFields[FieldNr]),DBCompareStruct[FieldNr]);
+      DBCompareStruct[FieldNr].Options:=options;
+      end;
   finally
     SearchFields.Free;
   end;
bufdataset.diff (1,069 bytes)   

Joost van der Sluis

2010-03-12 18:16

manager   ~0035390

Thanks for the patch

Issue History

Date Modified Username Field Change
2010-02-10 01:15 Carlos Valente New Issue
2010-02-10 01:15 Carlos Valente Status new => assigned
2010-02-10 01:15 Carlos Valente Assigned To => Joost van der Sluis
2010-02-10 10:08 LacaK Note Added: 0034346
2010-02-10 15:48 Carlos Valente Note Added: 0034358
2010-02-11 07:14 LacaK Note Added: 0034381
2010-02-15 07:44 LacaK Note Edited: 0034346
2010-02-15 09:45 LacaK File Added: bufdataset.diff
2010-02-15 09:46 LacaK Note Edited: 0034381
2010-03-12 18:16 Joost van der Sluis Fixed in Revision => 15005
2010-03-12 18:16 Joost van der Sluis Status assigned => resolved
2010-03-12 18:16 Joost van der Sluis Fixed in Version => 2.5.1
2010-03-12 18:16 Joost van der Sluis Resolution open => fixed
2010-03-12 18:16 Joost van der Sluis Note Added: 0035390
2010-03-12 18:16 Joost van der Sluis Target Version => 2.4.1
2010-10-22 14:12 Jonas Maebe Relationship added has duplicate 0017684
2010-11-13 21:27 Jonas Maebe FPCOldBugId => 0
2010-11-13 21:27 Jonas Maebe Fixed in Revision 15005 => 15209
2010-11-13 21:27 Jonas Maebe Fixed in Version 2.5.1 => 2.4.2
2010-11-13 21:27 Jonas Maebe Target Version 2.4.1 => 2.4.2
2011-05-01 21:45 Marco van de Voort Status resolved => closed