使用 Delphi 2010 将 Unicode 字符插入 MySQL

发布于 2024-09-26 08:12:41 字数 1012 浏览 1 评论 0原文

尝试使用 Delphi 2010 和 TADOConnection 将带有 Unicode 字符的值插入 MySQL 数据库,但没有成功。

与 ODBC 连接

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

SQL 命令:

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

尝试直接插入它,

TADOConnection.Execute(SQL)

结果在数据库中仅显示为“Russian: ????????? ????”

还尝试了这里建议的方法: 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;

仅当我在设计时添加参数时,在代码中进行此操作对我来说根本不起作用,但在数据库中它仍然是相同的结果,并且到处都是问号。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆 2024-10-03 08:12:41

TADOConnection 似乎不支持 Unicode,至少我无法让它工作。

如果我改为使用 dbExpress TSQLConnection 和 TSQLQuery 插入数据库,它将按预期工作。但我必须使用参数来完成,而不是直接使用 INSERT 命令来完成

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

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;
瞎闹 2024-10-03 08:12:41

我相信这个 PHP 脚本首先执行 SET NAMES utf8 查询

I believe this PHP script executes a SET NAMES utf8 query first

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文