Page 1 of 1

Unicode (Database) <->Non unicode (Application) on the fly conversion

Posted: Mon 22 Oct 2007 12:17
by crafty
Hi,

I have a following scenario:
There is a MySQL Database which uses UTF8 encoding and is populated by web application which supports this type of encoding. Our application currently doesn't support unicode because of the controls used and we can't easily migrate to other controls.
We need to communicate with the database, read the Unicode data and convert it to Non-unicode to be able to display it correctly. We also need the non-unicode data from the application to be converted into unicode before being written to the database. The application needs to support only one encoding (cp1250) so there will be no loose of data.

Can this task be accomplished using MyDac? Can the data be intercepted and reencoded at this level?

Posted: Mon 22 Oct 2007 14:25
by Antaeus
Try to set TMyConnection.Options.Charset to cp1250. This equals to calling the SET NAMES command of MySQL with cp1250 as its parameter. In this case MySQL server handles all character set conversion issues himself.

Posted: Tue 23 Oct 2007 09:49
by crafty
Hi,

Thanks for the answer, it solved the problem :) It turned out that the web application was inserting data using utf but decleared the wrong charset in 'set names' so choosing cp1250 in application wasn't helping until your answer set us on the right track :)

I have another question though. Is it possible for the application or for MyDac to detect user's settings in `Control Panel->Regional and Language Options` and choose the right non unicode Options.Charset for the user?
This way we could have UTF8 database and users could insert and read their data correctly (using their charset), unless of course they try to read data from users who use another charset.

Posted: Tue 23 Oct 2007 15:00
by Antaeus
MyDAC has no such functionality. You can implement it by yourself, or let the user to choose the right encoding from a list and remember his choice to avoid asking on each program start.