Page 1 of 1

Send to DB in UTF8

Posted: 04.07.2010, 16:36
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.

Posted: 04.07.2010, 19:08
by mrLion
set TZConnection.Property to:
codepage=UTF8

this is for PostgreSQL. For other version DB its may different....

Posted: 04.07.2010, 19:36
by trob
it does not work :(

It still sends in cp1250

Posted: 05.07.2010, 19:40
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. :?:

Posted: 06.07.2010, 12:10
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;

Posted: 06.07.2010, 19:21
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.

Posted: 06.07.2010, 22:17
by trob
If you use some normal language, i would answer you.

Yes, i have a good reason.

Posted: 07.07.2010, 18:46
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:

Posted: 08.07.2010, 02:43
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.

Posted: 08.07.2010, 04:39
by mrLion
trob, Sorry, i`m dont use MySQL. Cant help you in this case.

Posted: 08.07.2010, 04:42
by trob
No problem, now i use the code above, and it works fine.