Page 1 of 1

[patch_done] Loockup error

Posted: 03.07.2012, 11:17
by Shagrat3
I found bag:
Found unneeded code lines for WideString

Posted: 03.07.2012, 19:51
by EgonHugeist
Shagrat3,

i don't understand, why these lines are not needed.

I think the whole code is this:

Code: Select all

    if PartialKey then
    begin
      if CurrentType = stUnicodeString then
      begin
        WValue1 := KeyValues[I].VUnicodeString;
        WValue2 := ResultSet.GetUnicodeString(ColumnIndex);

        if CaseInsensitive then
          WValue2 := WideUpperCase(WValue2);
        {$IFDEF DELPHI12_UP}
        Result := SysUtils.AnsiStrLComp(PWideChar(WValue2), PWideChar(WValue1), Length(WValue1)) = 0;
        {$ELSE}
          AValue1 := UTF8ToAnsi(UTF8Encode(WValue1));
          AValue2 := UTF8ToAnsi(UTF8Encode(WValue2));
          Result := AnsiStrLComp(PAnsiChar(AValue2), PAnsiChar(AValue1), Length(AValue1)) = 0;
        {$ENDIF}
      end
      else //-> AnsiStringData or other string-compatible data-fields
      begin
        AValue1 := AnsiString(KeyValues[I].VString);
        AValue2 := AnsiString(ResultSet.GetString(ColumnIndex));

        if CaseInsensitive then
          {$IFDEF LAZARUSUTF8HACK}
          AValue2 := AnsiUpperCase(Utf8ToAnsi(AValue2));
          {$ELSE}
          AValue2 := {$IFDEF DELPHI12_UP}AnsiStrings.{$ENDIF}AnsiUpperCase(AValue2);
          {$ENDIF}
        Result := AnsiStrLComp(PAnsiChar(AValue2), PAnsiChar(AValue1), Length(AValue1)) = 0;
      end;
Which means we do also compare nun Unicode-Fields. In my branch both (stUnicodeString/stString) types are valid. stString is for Ansi-Connection or Fields which have a static mask like type 'Mac' or 'IP' of PostgresSQL. stUnicodeString is for unicode Connections and means a UTF8Decoded Wide/UnicodeString.

So please try to teach me, why these lines are waste.
Your toppic also points me to an error. Do you realy have one? Has something changed?

Michael

Posted: 04.07.2012, 12:42
by Shagrat3
In picture has:

Code: Select all

if CaseInsensitive then
        {$IFDEF LAZARUSUTF8HACK}
        AValue2 := AnsiUpperCase(Utf8ToAnsi(AValue2));
        {$ELSE}
        AValue2 := {$IFDEF DELPHI12_UP}AnsiStrings.{$ENDIF}AnsiUpperCase(AValue2);
        {$ENDIF}
      Result := AnsiStrLComp(PAnsiChar(AValue2), PAnsiChar(AValue1), Length(AValue1)) = 0;
     end;
The unnecessary part of the code corrupts the correct comparison WideString

Posted: 04.07.2012, 12:44
by Shagrat3

Posted: 04.07.2012, 13:26
by EgonHugeist
Shagrat3,

you're right! Wondering why these lines are still available. I had removed them from \testing serveral weeks ago.

Patch done Rev 1438 \testing and merged 1439 \testing-egonhugeist
Available on trunk in two weeks.

Thank you for that hint. But the other thread is talking about my branch where these lines do not exsits...

Michael