Send to DB in UTF8

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Send to DB in UTF8

Post by trob »

Hello

How can i send the SQL commands to the database in UTf8? I use Delphi 2010.

The DB and the fields are UTF8. I want to send datas in UTF8 too, so none of characters are lost by the Unicode > latin/cp1250 > Utf8 conversions.
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post by mrLion »

set TZConnection.Property to:
codepage=UTF8

this is for PostgreSQL. For other version DB its may different....
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

it does not work :(

It still sends in cp1250
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post by mrLion »

???? Are you create BD in UTF8 codepage???? Are you sure?
And what DB Server you are use??
My example for PostrgreSQL, for you case it`s parameter may be different.
Check documentation for connect string.
and for write use:

query.ParamByName('Par').AsWideString:='string....';


.......
P.S. Publick you code. i`m want to see it. :?:
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

At the end, this is the solution:

Code: Select all

function convtodb(input: string):string;
var a: PAnsiChar;
    w: PWideChar;
Begin
  GetMem(w,255);
  GetMem(a,255);
  StringToWideChar(input,w,255);
  UnicodeToUtf8(a,w,255);
  Result:=a;
  FreeMem(w);
  FreeMem(a);
End;
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post by mrLion »

:blink2: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Why you use this incredible code???!?!!!!!!
Why you can`t use simple example:
(sorry, i`m use C++....)

q : TZQuery;

q.SQL.Clear();
q.SQL.Add('Insert into tbl values (:Z1)');
q.ParamByName('Z1').AsWideString:='in forest born the.... :))))';
q.ExecSQL;
db.Commit();

?????
for what do you have to ohm horseradish so perverted? Sorry for my english :) i`m use Google translate...
why write some stupid function of conversion, if everything is ready in the code itself ZEOS.
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

If you use some normal language, i would answer you.

Yes, i have a good reason.
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post by mrLion »

What exactly is meant by a "normal language"?
I think I would not try to hurt you! Sorry if came by accident. My native language - Russian. If you want to let it get started.

Which, interestingly, it is reasonable to use the conversion function? I do not understand. :blink:
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

OK.

A want to see every db-change in the MySQL log, and it logs only the SQL commands. The parameters can't be seen in the log.

I know, there are better solutions for logging, but until i programming it, i use MySQL's log.
mrLion
Senior Boarder
Senior Boarder
Posts: 71
Joined: 20.03.2010, 10:17

Post by mrLion »

trob, Sorry, i`m dont use MySQL. Cant help you in this case.
trob
Senior Boarder
Senior Boarder
Posts: 51
Joined: 20.03.2007, 02:24

Post by trob »

No problem, now i use the code above, and it works fine.
Locked