やっぱり括弧株(株)化けた
ソースファイル ConnectorNETTest.cs ソースファイルの文字コードはsjis
using System; using MySql.Data.MySqlClient; namespace CNTNS { class ConnectorNETTest { public static void Main() { Console.WriteLine("Hello World!"); string myConnectionString = "server=127.0.0.1;uid=root;" + "pwd=;database=test;charset=sjis;"; MySqlConnection conn = new MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); MySqlDataReader reader = null; MySqlCommand cmd = null; cmd = new MySqlCommand("DROP TABLE IF EXISTS t1", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("CREATE TABLE t1 (c1 INT, c2 CHAR(1)) DEFAULT CHARSET=sjis", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("INSERT INTO t1 VALUES (1, '1')", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("INSERT INTO t1 VALUES (2, 'ァ')", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("INSERT INTO t1 VALUES (3, 'あ')", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("INSERT INTO t1 VALUES (4, '㈱')", conn); reader = cmd.ExecuteReader(); reader.Close(); cmd = new MySqlCommand("SELECT * FROM t1", conn); reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader.GetString(0) + "=" + reader.GetString(1)); } reader.Close(); conn.Close(); Console.WriteLine("Hello MySQL!"); } } }
実行結果
D:\share\workspace\current\CSharp>ConnectorNETTest.exe Hello World! 1=1 2=ァ 3=あ 4=? Hello MySQL!
その時のMySQLのGeneral Log
32 Connect root@localhost on test 32 Query SHOW VARIABLES 32 Query SHOW COLLATION 32 Query SET NAMES sjis;SET character_set_results=NULL 32 Init DB test 32 Query DROP TABLE IF EXISTS t1 32 Query CREATE TABLE t1 (c1 INT, c2 CHAR(3)) DEFAULT CHARSET=sjis 32 Query INSERT INTO t1 VALUES (1, '1') 32 Query INSERT INTO t1 VALUES (2, 'ァ') 32 Query INSERT INTO t1 VALUES (3, 'あ') 32 Query INSERT INTO t1 VALUES (4, '?') 32 Query SELECT * FROM t1
その時のサーバ上のテーブル(mysqlクライアントにてset names cp932実行後に確認)
mysql> set names cp932; Query OK, 0 rows affected (0.00 sec) mysql> select * from t1; +------+------+ | c1 | c2 | +------+------+ | 1 | 1 | | 2 | ァ | | 3 | あ | | 4 | ? | +------+------+ 4 rows in set (0.02 sec)
INSERT時点で既に化けてるなー.