[patch_done] Fix incorrect loCaseInsensitive in Lazarus

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

[patch_done] Fix incorrect loCaseInsensitive in Lazarus

Post 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;
mse
Junior Boarder
Junior Boarder
Posts: 41
Joined: 17.07.2007, 06:30

Post 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
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post by ism »

And how best to ?

Give me example

Zeos components can be installed in MSEide ? I do not know.
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post by ism »

I checked, the plug module "sysutils", and everything will work in MSEide.
mse
Junior Boarder
Junior Boarder
Posts: 41
Joined: 17.07.2007, 06:30

Post 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.
mse
Junior Boarder
Junior Boarder
Posts: 41
Joined: 17.07.2007, 06:30

Post by mse »

ism wrote:I checked, the plug module "sysutils", and everything will work in MSEide.
I don't understand.
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post 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.
mse
Junior Boarder
Junior Boarder
Posts: 41
Joined: 17.07.2007, 06:30

Post 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
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post by ism »

I do not think that the patch does is worse. Wait, the word of mdaems

To Lazarus, this patch is very needed
Dali
Junior Boarder
Junior Boarder
Posts: 30
Joined: 08.02.2010, 14:36

Post 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.
ism
Zeos Test Team
Zeos Test Team
Posts: 202
Joined: 02.10.2010, 20:48

Post by ism »

Suggest your patch
Lazarus 1.0.8 fpc 2.6.0
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Patch done, svn Rev. 930
Image
Post Reply