mysqldelphiunicodedelphi-2010adoconnection

Insert Unicode chars to MySQL with Delphi 2010


Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and TADOConnection with no luck.

Connection with ODBC

Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysrc;Initial Catalog=mydb

The SQL command:

INSERT INTO myTable (aCol) VALUES('Russian: русский язык')

Tried inserting it directly with

TADOConnection.Execute(SQL)

It only ends up in the database as "Russian: ??????? ????"

Also tried the method suggested here: http://www.3delite.hu/Object%20Pascal%20Developer%20Resources/delphiunicodemysqltutorial.html

With TADOQuery do
   begin
   SQL.Clear;
   SQL.Add('INSERT INTO myTable (aCol) VALUES(:p));
   Parameters.ParamByName('p').DataType := ftWideString;
   Parameters.ParamByName('p').Value := 'Russian: русский язык';
   ExecSQL;
end;

Making this in code doesn't work at all for me, only if I add parameters in designtime, but then it's still the same result in the database with questionmarks all over.


Solution

  • It seems TADOConnection doesn't support Unicode, at least I can't get it to work.

    If I instead use dbExpress TSQLConnection and TSQLQuery to insert to the database it works as intended. But I must do it with Parameters and not with directly with an INSERT command

                    with qTarget.Params.ParamByName('p' + IntToStr(i)) do
                    begin
                        DataType    := ftWideString;
                        Value           := Fields[i].AsWideString;
                    end;
                    qTarget.ExecSQL;