From bbbcc17171a1281d885fa3634dba5a5db9710899 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 25 Mar 2005 11:38:01 +0000 Subject: [PATCH] + Implementation of IndexForFields from Alexandrov Alexandru --- fcl/db/db.pp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/fcl/db/db.pp b/fcl/db/db.pp index b05008d623..5f70346df8 100644 --- a/fcl/db/db.pp +++ b/fcl/db/db.pp @@ -1703,6 +1703,7 @@ destructor TIndexDef.Destroy; begin //!! To be implemented + inherited Destroy; end; @@ -1782,8 +1783,35 @@ end; function TIndexDefs.GetIndexForFields(const Fields: string; CaseInsensitive: Boolean): TIndexDef; +var + i, FieldsLen: integer; + Last: TIndexDef; + Name: string; + Flds: string; begin - //!! To be implemented + Last := nil; + FieldsLen := Length(Fields); + for i := 0 to Count - 1 do + begin + Result := Items[I]; + Name := Result.Name; + Flds := Result.Fields; + if (Result.Options * [ixDescending, ixExpression] = []) and + (not CaseInsensitive or (ixCaseInsensitive in Result.Options)) and + AnsiSameText(Fields, Result.Fields) then + begin + Exit; + end else + if AnsiSameText(Fields, Copy(Result.Fields, 1, FieldsLen)) and + ((Length(Result.Fields) = FieldsLen) or + (Result.Fields[FieldsLen + 1] = ';')) then + begin + if (Last = nil) or + ((Last <> nil) And (Length(Last.Fields) > Length(Result.Fields))) then + Last := Result; + end; + end; + Result := Last; end; @@ -1793,7 +1821,8 @@ var i: LongInt; begin Result := -1; for i := 0 to Count - 1 do - if Items[i].Name = Name then begin + if AnsiSameText(Items[i].Name, Name) then + begin Result := i; Break; end; @@ -1866,7 +1895,10 @@ end. { $Log$ - Revision 1.41 2005-03-18 11:54:56 michael + Revision 1.42 2005-03-25 11:38:01 michael + + Implementation of IndexForFields from Alexandrov Alexandru + + Revision 1.41 2005/03/18 11:54:56 michael + Fixed second typo in provided patch Revision 1.39 2005/03/18 10:17:34 michael @@ -1894,4 +1926,4 @@ end. - implemented TUpdateMode, TProviderFlags - implemented TIndexDef, TIndexDefs -} \ No newline at end of file +}