YIPES! Insert into TEXT column fails when using UTF-8 encoding

YIPES! Insert into TEXT column fails when using UTF-8 encoding

Postby gwerner » Fri 13 May 2005 20:02

Using MySQL Direct 2.80.5.0
MySQL 4.1.11-nt via TCP/IP

Table defined:
testID int NOT NULL - autoincrement
textfield text NOT NULL - utf8

The following code successfully runs, but fails to store anything after the first special character (Ñ):

Code: Select all
CoreLab.MySql.MySqlConnection conn = new MySqlConnection(connectionstring);
conn.Open();
string s = "UNA PEQUEÑA CONTRIBUCION";
using (MySqlCommand cmd = conn.CreateCommand())
{
   cmd.CommandType = CommandType.Text;
   cmd.CommandText = "insert into test (textfield) values (@textfield)";
   cmd.Parameters.Add("@textfield", s);
   cmd.ExecuteNonQuery();
}
conn.Close();
conn.Dispose();
gwerner
 

Partial answer

Postby gwerner » Fri 13 May 2005 20:39

Okay, found out that I need to add conn.Unicode = true before the conn.Open command. Now I have the following question:

What is the easiest way to determine the version of MySQL so that I can determine if Unicode is supported (or is this detected by MySQLNet)? In other words, can I just always set Unicode=true?
gwerner
 
Posts: 3
Joined: Fri 13 May 2005 20:10

One more thing

Postby gwerner » Fri 13 May 2005 20:50

One last note. Even if Unicode is set to false on the connection, the text should still be input. It should just replace all the unicode chars with ?s. That's what MySQL does itself. Right now it just truncates it.
gwerner
 
Posts: 3
Joined: Fri 13 May 2005 20:10

Re: Partial answer

Postby Serious » Mon 16 May 2005 07:22

gwerner wrote:What is the easiest way to determine the version of MySQL
You can get MySQL Server version with MySqlConnection.ServerVersion property. See example in MySQLDirect .NET help.
gwerner wrote:In other words, can I just always set Unicode=true?
MySQLDirect .NET does not use unicode with servers that do not support it, so you can set Unicode=true safely.
gwerner wrote:One last note. Even if Unicode is set to false on the connection, the text should still be input. It should just replace all the unicode chars with ?s. That's what MySQL does itself. Right now it just truncates it.
This is default behavior of the System.Text.Encoding class.
Serious
 


Return to dotConnect for MySQL