delphi – 插入UTF8数据库时格式错误的字符串
发布时间:2020-12-15 09:50:34 所属栏目:大数据 来源:网络整理
导读:我使用Delphi 2010,Firebird 2.5.2,IBExpress组件. 数据库字符集是UTF8.在db-connection UTF8中. 数据库: var Database: TIBDatabase;begin ... Database.params.Clear; Database.params.Add('user ''SYSDBA'' password ''masterkey'' '); Database.params.
我使用Delphi 2010,Firebird 2.5.2,IBExpress组件.
数据库字符集是UTF8.在db-connection UTF8中. 数据库: var Database: TIBDatabase; begin ... Database.params.Clear; Database.params.Add('user ''SYSDBA'' password ''masterkey'' '); Database.params.Add('page_size 16384'); Database.params.Add('default character set UTF8'); 表: CREATE TABLE NEW_TABLE ( NEW_FIELD VARCHAR(255) ); 连接代码: Database.params.Clear; Database.params.Add('user_name=SYSDBA'); Database.params.Add('password=masterke'); Database.params.Add('sql_role_name=UTF8'); Database.Open; 插入代码: var IBSQL: TIBSQL; begin IBSQL := TIBSQL.Create(nil); try IBSQL.Database := db; IBSQL.Transaction := tr IBSQL.SQL.Text := 'insert into NEW_TABLE (NEW_FIELD) values (:param)'; IBSQL.params[0].Value := '?abc?'; // unsupported symbols :( if not IBSQL.Transaction.Active then IBSQL.Transaction.StartTransaction; IBSQL.ExecQuery; // "Malformed string" exception here if IBSQL.Transaction.Active then IBSQL.Transaction.Commit; finally FreeAndNil(IBSQL); end; end; 我收到“格式错误的字符串”异常.如何插入此字符串? 解决方法
确保你的字段的字符集是UTF-8.
创建新字段时,您有两个选择: >使用默认字符集创建域并进行整理,并使用域设置字段 在下图中,显示使用IBExpert使用域创建的字段. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |