Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: How to write queries with widestring or utf8 MySQL
[1 2 |Next ]
How to write queries with widestring or utf8 MySQL
Posted: 2007/09/14 19:47
 
Hi! I 'm testing anyDAC for using it with utf8 AND MySQL 5.0

I could write an application with TNTDBGrid who wrote and read back an UTF8 charcter.

Now I want to use a SQL statment and try to pass a widestring on it to store an UTF8 Character in a MySQL table...

I have done somes test... like

[...]
TntEdit1.Text := #$03A8#$03A9#$03AA;

ADQuery1.SQL.Text := 'INSERT INTO T2 (id, name) VALUES (:id,:name)';
ADQuery1.Params.ParamByName('id').AsInteger := 555;
ADQuery1.Params.ParamByName('name').AsWideString := TntEdit1.Text;
ADQuery1.ExecSQL;
[...]

but get this exception:

Project Project1.exe raised exception class EMySQLNativeException with message '[AnyDAC][Phys][MySQL][LIBMYSQL] Incorrect string value: 'xA8xA9xAA' for column 'name' at row 1'. Process stopped. Use Step or Run to continue.


or tried this:

[..]
ADQuery1.SQL.Text := 'INSERT INTO T2 (id, name) VALUES (:id,:name)';
ADQuery1.Params.ParamByName('id').AsInteger := 555;
ADQuery1.Params.ParamByName('name').AsWideString := WideChar(#$0275);
TntLabel1.Caption := ADQuery1.Params.ParamByName('name').AsWideString;
ADQuery1.ExecSQL;
[..]

and get a '?' on the column

I have attached the source code... that must be a very easy thing to do.. but I 'm very newbie with Widestrings and UTF8 and unicode....

You only need a db named Test with this table:

CREATE TABLE `t2` (
`name` varchar(11) NOT NULL,
`id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

File Attachment:
File name: UTF8MySQL-9ac559bc042fc7dcc69e5a5663080f57.zip
File size:4172 bytes
Re:How to write queries with widestring or utf8 MySQL
Posted: 2007/09/15 01:02
 
Hello

Thank you for detailed report.

To work with UTF8, add to your connection definition:
- CharacterSet=utf8
- Utf8Mapping=WideString

Regards,
Dmitry
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/15 07:21
 
Diman wrote:


To work with UTF8, add to your connection definition:
- CharacterSet=utf8
- Utf8Mapping=WideString



Sorry to not to tell you before, I have allready done thoses settings, before sending the first post.

The problem I have is WITH thoses settings.

please, try the attachment...
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/15 09:47
 
I does not see Unit1 in archive.
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/15 12:22
 
Diman wrote:
I does not see Unit1 in archive.

Oops!
File Attachment:
File name: UTF8MySQL.zip
File size:6133 bytes
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/16 02:53
 
Ok. What are your versions of MySQL server and libmysql.dll ? Most simple to get that - run ADExecutor, connect to MySQL server and ADExecutor will show versions.
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/16 10:29
 
that's the output of adExecutor:

Connection info:
DLL = C:WINNTlibmysql.dll
Version = 500020000
ServerInfo = 5.0.45-community-nt
ClientInfo = 5.0.2-alpha
CharacterSetName = latin1_swedish_ci
HostInfo = 192.168.0.2 via TCP/IP
NameCaseSensitive = False
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/16 23:14
 
Ok, upgrade you libmysql.dll to 5.0.45. And the problem should gone. If not, then I will give you workaround.
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/17 20:59
 
thanks! it seems that is working (i just needed to erase the persisted fields, the change of the libMySql version changed the fieldef from WideString (old Version) to String (New Version)...

I just wander with wich server version it will be compatible? no matter to have a 5.0.45 lib version and a linux 5.0.22 server (I know at least that's the version I will have to work against)
Re:How to write queries with widestring or utf8 My
Posted: 2007/09/17 22:11
 
Hello

You should have at least 5.0.8 version of libmysql.dll

Regards,
Dmitry
[1 2 |Next ]