Skip to content

Commit e751db2

Browse files
author
Gabriela Martinez
committed
Merge remote-tracking branch 'remotes/origin/6.7' into 6.8
2 parents adf1054 + 6f08bb6 commit e751db2

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
6.8.7
22
- Changed handshake process to use bytes instead of encoded strings.
3+
- Added support for Chinese character set gb18030. (Oracle bug # 21098546).
34

45

56
6.8.6

Source/MySql.Data/CharSetMap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2014, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2015, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -148,6 +148,7 @@ private static void LoadCharsetMap()
148148
mapping.Add("utf16", new CharacterSet("utf-16BE", 2));
149149
mapping.Add("utf16le", new CharacterSet("utf-16", 2));
150150
mapping.Add("utf32", new CharacterSet("utf-32BE", 4));
151+
mapping.Add("gb18030", new CharacterSet("gb18030", 4));
151152
}
152153

153154
internal static void InitCollections(MySqlConnection connection)

Tests/MySql.Data.Tests/CharacterSetTests.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,91 @@ public void UsingUtf32()
491491
}
492492

493493

494+
495+
/// <summary>
496+
/// Test for new functionality on 5.7.9 supporting chinese character sets gb18030
497+
/// WL #4024
498+
/// (Oracle bug #21098546).
499+
/// </summary>
500+
[Fact]
501+
public void CanInsertChineseCharacterSetGB18030()
502+
{
503+
if (st.Version < new Version(5, 7, 4)) return;
504+
505+
try
506+
{
507+
st.execSQL("CREATE TABLE Test (id int, name VARCHAR(100) CHAR SET gb18030, KEY(name(20)))");
508+
using (MySqlConnection c = new MySqlConnection(st.conn.ConnectionString + ";charset=gb18030"))
509+
{
510+
c.Open();
511+
MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES(1, '㭋玤䂜蚌')", c);
512+
cmd.ExecuteNonQuery();
513+
cmd = new MySqlCommand("INSERT INTO test VALUES(2, 0xC4EEC5ABBDBFA1A4B3E0B1DABBB3B9C520A1A4CBD5B6ABC6C2)", c);
514+
cmd.ExecuteNonQuery();
515+
cmd = new MySqlCommand("SELECT id, name from test", c);
516+
var reader = cmd.ExecuteReader();
517+
while (reader.Read())
518+
{
519+
if (reader.GetUInt32(0) == 1)
520+
Assert.Equal("㭋玤䂜蚌", reader.GetString(1));
521+
if (reader.GetUInt32(0) == 2)
522+
Assert.Equal("念奴娇·赤壁怀古 ·苏东坡", reader.GetString(1));
523+
}
524+
}
525+
}
526+
finally
527+
{
528+
st.execSQL("drop table if exists `Test`");
529+
}
530+
}
531+
532+
533+
534+
/// <summary>
535+
/// Test for new functionality on 5.7.9 supporting chinese character sets on gb18030
536+
/// WL #4024
537+
/// (Oracle bug #21098546).
538+
/// </summary>
539+
[Fact]
540+
public void CanCreateDbUsingChineseCharacterSetGB18030()
541+
{
542+
if (st.Version < new Version(5, 7, 4)) return;
543+
544+
MySqlConnectionStringBuilder rootSb = new MySqlConnectionStringBuilder(st.rootConn.ConnectionString);
545+
rootSb.CharacterSet = "gb18030";
546+
using (MySqlConnection rootConnection = new MySqlConnection(rootSb.ToString()))
547+
{
548+
string database = "㭋玤䂜蚌";
549+
550+
rootConnection.Open();
551+
MySqlCommand rootCommand = new MySqlCommand();
552+
rootCommand.Connection = rootConnection;
553+
rootCommand.CommandText = string.Format("CREATE DATABASE `{0}` CHARSET=gb18030;", database);
554+
rootCommand.ExecuteNonQuery();
555+
556+
try
557+
{
558+
rootSb.Database = database;
559+
using (MySqlConnection conn = new MySqlConnection(rootSb.ConnectionString))
560+
{
561+
conn.Open();
562+
Assert.Equal(database, conn.Database);
563+
}
564+
}
565+
finally
566+
{
567+
if (rootConnection.State == ConnectionState.Open)
568+
{
569+
rootCommand.CommandText = string.Format("DROP DATABASE `{0}`;", database);
570+
rootCommand.ExecuteNonQuery();
571+
}
572+
}
573+
}
574+
}
575+
576+
577+
578+
494579
public void Dispose()
495580
{
496581
st.execSQL("DROP TABLE IF EXISTS TEST");

0 commit comments

Comments
 (0)