Page 1 of 1

Problems on reading MySQL TEXT fields in Unicode

Posted: Fri 26 Nov 2010 18:39
by DmitriNL
I'm trying to connect and retrieve Unicode data from a MySQL database. Reading Unicode text from a TEXT field shows wrong characters.

I'm using Windows 7, C++ Builder XE, dbExpress (XE package), MySQL 4.1.18-nt on a webserver and MySQL 5.1.53-community local.

The following parameters are set:

Code: Select all

SQLConnection1->DriverName = "MySQL";
SQLConnection1->GetDriverFunc = "getSQLDriverMYSQL";
SQLConnection1->LibraryName = "dbxmys.dll";
SQLConnection1->VendorLib = "libmysql.dll";
SQLConnection1->Params->Clear();
SQLConnection1->Params->Add("DriverName=MySQL");
SQLConnection1->Params->Add("HostName=domain.net");
SQLConnection1->Params->Add("Database=***");
SQLConnection1->Params->Add("User_Name=***");
SQLConnection1->Params->Add("Password=***");
SQLConnection1->Params->Add("Port=3306");
SQLConnection1->Params->Add("BlobSize=-1");
SQLConnection1->Params->Add("ErrorResourceFile=");
SQLConnection1->Params->Add("LocaleCode=0000");
SQLConnection1->Params->Add("Compressed=False");
SQLConnection1->Params->Add("Encrypted=False");
SQLConnection1->Params->Add("ConnectTimeout=60");
SQLConnection1->Params->Add("ServerCharSet=utf8");
SQLConnection1->LoginPrompt = false;
SQLDataSet1->GetMetadata = false;
Reading from a VARCHAR field works excellent but reading from a TEXT field shows Chinese characters while the content is in Japanese.

I'm using the following code for reading:

Code: Select all

SQLDataSet1->Close();
SQLDataSet1->CommandText = "SELECT * FROM table";
SQLDataSet1->ExecSQL(true);
SQLDataSet1->Open();
SQLDataSet1->First();
Memo1->Clear();
while(!SQLDataSet1->Eof)
{
  Memo1->Lines->Add(SQLDataSet1->FieldByName("field")->AsString); 
  SQLDataSet1->Next();
}
SQLDataSet1->Close();
Writing to the database works when I set 'ServerCharSet=utf8' in the TSQLConnection parameters. Is there maybe a property I missed for reading TEXT fields?

I'm using the following code for writing:

Code: Select all

SQLDataSet1->Close();
SQLDataSet1->CommandText = L"INSERT INTO table ("field") VALUES ('エンバカデロ・テクノロジーズは');";
SQLDataSet1->ExecSQL(true);
SQLDataSet1->Close();
Does someone has an idea how the read TEXT fields in Unicode? Thank you in advance for your help.

Posted: Tue 30 Nov 2010 08:12
by Dimon
To solve the problem try using the Direct mode to connect to MySQL database. For this you should set the TSQLConnection.DriverName property to 'DevartMySQLDirect' and the TSQLConnection.GetDriverFunc property to 'getSQLDriverMySQLDirect' value.

Posted: Tue 30 Nov 2010 16:56
by DmitriNL
After changing the property settings, I receive the error message: Project Project1.exe raised exception class TDBXError with message 'Unknown driver: DevartMySQLDirect'.

I'm using C++ Builder XE Enterprise which contains a dbExpress package. I didn't buy a standalone license. Can I download the missing DLL / library or do I need to buy an upgrade?

Posted: Fri 03 Dec 2010 08:50
by Dimon
To solve the problem add a link to the DbxDevartMySql unit, like this:

Code: Select all

#pragma package(smart_init) 
#pragma link "DbxDevartMySQL" 

Posted: Sat 04 Dec 2010 10:13
by DmitriNL
I've also tried your solutions but there is no file 'DbxDevartMySQL.xxx' or 'DbxDevart*.xxx' on my computer. Im using dbExpress delivered with C++ Builder XE.

Posted: Mon 06 Dec 2010 09:05
by Dimon
To use Devart dbExpress driver for MySQL you should install it. You can download it using the following link: http://www.devart.com/dbx/mysql/download.html

Posted: Tue 07 Dec 2010 07:40
by DmitriNL
This is not a long term solution. Your download is a trial. The dbExpress in C++ Builder should work properly otherwise this component is useless.

Posted: Tue 07 Dec 2010 13:55
by Dimon
We don't support standard dbExpress drivers. You can buy DbxMda here: http://www.devart.com/dbx/mysql/ordering.html

Posted: Thu 09 Dec 2010 08:52
by DmitriNL
Still this is not a proper solution. I'm disappointed. :(

Posted: Thu 09 Dec 2010 11:12
by Dimon
DbxMda provides a driver as an independent library that implements the common dbExpress interface for processing queries and stored procedures. DbxMda driver provides direct access to MySQL database server based on Borland dbExpress data access technology. It can work using MySQL client or native MySQL network protocol, that provides higher performance of direct access to server data without using the client dll library.