Formatted string when inserting UTF8 database

I am using Delphi 2010, Firebird 2.5.2, IBExpress components.

Database Encryption - UTF8. In db connection, UTF8.

Database:

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'); 

Table:

 CREATE TABLE NEW_TABLE ( NEW_FIELD VARCHAR(255) ); 

connection code:

  Database.params.Clear; Database.params.Add('user_name=SYSDBA'); Database.params.Add('password=masterke'); Database.params.Add('sql_role_name=UTF8'); Database.Open; 

Enter a code:

 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; 

I get the exception "Malformed string". How to insert this line?

+6
source share
1 answer

Make sure your field encoding is UTF-8.

When creating a new field, you have two options:

  • Create a default encoding domain and map and set the field to the domain
  • Create a field without a domain, setting the encoding and matching it manually.

The image below shows the field created using the IBExpert domain.

IBExpert with domain and charset

0
source

Source: https://habr.com/ru/post/946173/


All Articles