Page 1 of 1

[patch_done] Fix incorrect loCaseInsensitive in Lazarus

Posted: 12.06.2011, 14:02
by ism
loCaseInsensitive incorrect work with russian characters.

like as

ZTable1.Locate('test_field','Л',[loCaseInsensitive, loPartialKey]);
not found 'л'

patch also fixes crashes Postgres with UTF8 in Lazarus

Code: Select all

Index: src/component/ZDatasetUtils.pas
===================================================================
--- src/component/ZDatasetUtils.pas	(revision 903)
+++ src/component/ZDatasetUtils.pas	(working copy)
@@ -909,8 +909,13 @@
           DecodedKeyValues[I], vtString);
         if CaseInsensitive then
         begin
+          {$IFDEF FPC}
           DecodedKeyValues[I].VString :=
+            WideUpperCase(UTF8Decode (DecodedKeyValues[I].VString));
+          {$ELSE}
+          DecodedKeyValues[I].VString :=
             AnsiUpperCase(DecodedKeyValues[I].VString);
+          {$ENDIF}
         end;
       end;
     end
@@ -955,8 +960,13 @@
           begin
             DecodedKeyValues[I] := SoftVarManager.Convert(
               DecodedKeyValues[I], vtString);
+            {$IFDEF FPC}
             DecodedKeyValues[I].VString :=
+              WideUpperCase(UTF8Decode (DecodedKeyValues[I].VString));
+            {$ELSE}
+            DecodedKeyValues[I].VString :=
               AnsiUpperCase(DecodedKeyValues[I].VString);
+            {$ENDIF}
           end
           else
           begin
@@ -1015,7 +1025,11 @@
       end;
 
       if CaseInsensitive then
-        Value2 := AnsiUpperCase(Value2);
+      {$IFDEF FPC}
+      Value2 := AnsiUpperCase(Utf8ToAnsi(Value2));
+      {$ELSE}
+      Value2 := AnsiUpperCase(Value2);
+      {$ENDIF}
       Result := AnsiStrLComp(PAnsiChar(Value2), PAnsiChar(Value1), Length(Value1)) = 0;
     end
     else
@@ -1064,8 +1078,13 @@
         else
           if CaseInsensitive then
           begin
+            {$IFDEF FPC}
             Result := KeyValues[I].VString =
+              AnsiUpperCase (Utf8ToAnsi(ResultSet.GetString(ColumnIndex)));
+            {$ELSE}
+            Result := KeyValues[I].VString =
               AnsiUpperCase(ResultSet.GetString(ColumnIndex));
+            {$ENDIF}
           end
           else
           begin
Index: src/dbc/ZDbcPostgreSqlResultSet.pas
===================================================================
--- src/dbc/ZDbcPostgreSqlResultSet.pas	(revision 903)
+++ src/dbc/ZDbcPostgreSqlResultSet.pas	(working copy)
@@ -197,7 +197,7 @@
 
   if Connection.GetCharactersetCode = csUTF8 then
     case SQLType of
-      stString: SQLType := stUnicodeString;
+      stString: SQLType := {$IFDEF FPC} stString;  {$ELSE}  stUnicodeString; {$ENDIF}
       stAsciiStream: SQLType := stUnicodeStream;
     end;
 
Index: src/dbc/ZDbcPostgreSqlUtils.pas
===================================================================
--- src/dbc/ZDbcPostgreSqlUtils.pas	(revision 903)
+++ src/dbc/ZDbcPostgreSqlUtils.pas	(working copy)
@@ -285,7 +285,7 @@
 
   if Connection.GetCharactersetCode = csUTF8 then
     case Result of
-      stString: Result := stUnicodeString;
+      stString: Result :=  {$IFDEF FPC} stString;  {$ELSE}  stUnicodeString; {$ENDIF}
       stAsciiStream: Result := stUnicodeStream;
     end;
 end;

Posted: 12.06.2011, 15:15
by mse
Hint: Contrary to Lazarus MSEide+MSEgui uses UnicodeString instead of utf-8 encoded AnsiString, so {$ifdef FPC} probably is not the optimal compilation condition.

Martin

Posted: 13.06.2011, 10:18
by ism
And how best to ?

Give me example

Zeos components can be installed in MSEide ? I do not know.

Posted: 13.06.2011, 11:21
by ism
I checked, the plug module "sysutils", and everything will work in MSEide.

Posted: 13.06.2011, 13:39
by mse
ism wrote:And how best to ?
I don't know.
Zeos components can be installed in MSEide ?
Yes, although not tested with Zeos 7.0. Please compile MSEide with -dmse_with_zeoslib or use the project apps/ide/mseide_zeos.prj in order to install components for Zeos 6.x in MSEide.

Posted: 13.06.2011, 13:45
by mse
ism wrote:I checked, the plug module "sysutils", and everything will work in MSEide.
I don't understand.

Posted: 13.06.2011, 14:15
by ism
You can try to test this patch in MSEide and report the results ?
How to distinguish MSEide from Lazarus c using IFDEF ?
ZeosDbo officially supports MSEide ?

I have never never worked with MSEide.

Posted: 14.06.2011, 07:15
by mse
ism wrote:You can try to test this patch in MSEide and report the results ?
I have no time to study Zeos 7.0 in deep at the moment. I assume it uses UnicodeString with Delphi and AnsiString with FPC? MSEgui uses UnicodeString with FPC so there probably should be a solution without converting AnsiString<->UnicodeString.
How to distinguish MSEide from Lazarus c using IFDEF ?
Possibly with a {$define} in a environment specific include file. Maybe it is better to switch "Lazarus utf-8 AnsiString" <-> UnicodeString with a global variable or the like.
ZeosDbo officially supports MSEide ?
It seems so, MSEide+MSEgui is listed at
http://zeos.firmos.at/portal.php

Posted: 14.06.2011, 20:13
by ism
I do not think that the patch does is worse. Wait, the word of mdaems

To Lazarus, this patch is very needed

Posted: 21.06.2011, 15:25
by Dali
ism wrote:I do not think that the patch does is worse. Wait, the word of mdaems

To Lazarus, this patch is very needed
Couldn't agree more.

Posted: 22.06.2011, 20:02
by ism
Suggest your patch

Posted: 02.09.2011, 21:51
by mdaems
Patch done, svn Rev. 930