Page 1 of 1

[patch_done] IFDEF ZEOS_FULL_UNICODE

Posted: 08.12.2008, 13:10
by mariuszekpl
I think about IFDEF ZEOS_FULL_UNICODE
What does it mean ?

If i compile ZEOS with ZEOS_FULL_UNICODE
i can't open correctly databases with Latin2 encoding.
I think about "SVN rev. 537."

example code

Code: Select all

{$IFDEF ZEOS_FULL_UNICODE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(UTF8String (SQL)));
    {$ELSE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL));
    {$ENDIF}      


If i have LATIN2 databse and ZEOS_FULL_UNICODE
When i execute

INSERT into TABLE_NAME (dane) VALUES ('łęćżę');

My SQL is UTF8String encoding but i need LATIN2 encoding send to PlainDriver

May by wy should change it

Code: Select all

{$IFDEF ZEOS_FULL_UNICODE}
  if WE_WANT_UNICODE = TRUE then
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(UTF8String 
  else
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL));
(SQL)));
    {$ELSE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL));
    {$ENDIF}      



or

Code: Select all

{$IFDEF ZEOS_FULL_UNICODE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SOME_FUNCTION(SQL)));
    {$ELSE}
    GetPlainDriver.db_execute_imm(GetDBHandle, PAnsiChar(SQL));
    {$ENDIF}      


SOME_FUNCTION - return string in suitable encoding

Sometimes i need open database in LATIN2 and UTF8 in this same project

Posted: 08.12.2008, 13:51
by mdaems
Good question... maybe we should rename the compiler directive to DELPHI12_UP, this meaning all Strings are unicodestrings.

Concerning the problem with the encoding of strings sent to the database we must start thinking about how this could be implemented best. If I understand correctly this would require something like replacing UTFString() calls by a function pointer that can be assigned dynamically in function of the required encoding. The assignment of the encoding function should happen on the connection object (dbc layer) I suppose you don't know a trick to let the user choose/type a string value meaning the name of the function to be called to encode the string?

What do you think?

Mark

Posted: 08.12.2008, 14:41
by gto
Hello there :)

I've created this directive, and it means DELPHI12_UP, indeed. It will really become clearly than ZEOS_FULL_UNICODE.

About the creation of this function to handle encoding, I think it should be thinked a bit. There are DB's in which the unicode support is very bad, and which don't support unicode SQLs (one which is firebird, as long I searched).

It will be very good if we can move all of our code to unicode, but DB's aren't doing this, too. We should take some care on compatibility, to not start to write lots of code on IFDEF, and become with two versions of Zeos, one inside another.

I think we need a planned rework, instead of continuous patching this version.

Posted: 08.12.2008, 14:51
by mariuszekpl
Can we remove changes from SVN rev. 537. ?
And use this function :
(I dont't test it but should work )

{$IFDEF ZEOS_FULL_UNICODE}
{**
Converts Unicode strings to Ansi (Delphi 2009 Up)
}
function UnicodeToAnsi(const UnicodeString: string): RawByteString;
begin
if WE_WANT_UNICODE = TRUE then
result := Utf8string(UnicodeString)
else
result := AnsiString(UnicodeString)
end;
{$ENDIF}

In this sample WE_WANT_UNICODE is global variable
but we can change it , to use property of connections or datasets
or Something Else.

What do you think?

Posted: 08.12.2008, 15:07
by mdaems
Conclusions :
* let's rename the compiler directive (you doing it, gto?)
* avoid conditional code as much as possible
* why revert 537? We should think about the replacement first, I believe. Or does it make the situation worse than before?

Mark

Posted: 08.12.2008, 15:37
by gto
mdaems wrote:Conclusions :
* let's rename the compiler directive (you doing it, gto?)
* avoid conditional code as much as possible
* why revert 537? We should think about the replacement first, I believe. Or does it make the situation worse than before?

Mark
I think the idea to revert is only to avoid a rework, as before 537 the calls are already centered on one function ;)

I'm doing, yes. Soon I'll post a patch here. 10 minutes ;)

Posted: 08.12.2008, 15:43
by gto
Uhm, much quicker :)

Patch created on testing folder, at Rev 537.

ZEOS_FULL_UNICODE removed from zeos.inc and all calls to it redirected to DELPHI12_UP.

UPDATE:

Already commited to Rev 538!

Posted: 08.12.2008, 15:45
by gto
Ahm.. sorry for trolling and triple-posting, but there's another idea: Why don't we create a table on supported DB's and their support to unicode, if any ?

I think will make things clear, and then we can plan something.

Am I right?

Posted: 08.12.2008, 15:48
by mdaems
That's a constructive idea. (New thread!!)

Mark