|
1 | | -// Copyright © 2013, 2015 Oracle and/or its affiliates. All rights reserved. |
| 1 | +// Copyright © 2013, 2017 Oracle and/or its affiliates. All rights reserved. |
2 | 2 | // |
3 | 3 | // MySQL Connector/NET is licensed under the terms of the GPLv2 |
4 | 4 | // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most |
@@ -642,12 +642,12 @@ public void ExtendedCharsetOnConnection() |
642 | 642 | { |
643 | 643 | string database = "数据库"; |
644 | 644 | string user = "用户"; |
645 | | - string password = "test"; |
| 645 | + string password = "tést€"; |
646 | 646 |
|
647 | 647 | rootConnection.Open(); |
648 | 648 | MySqlCommand rootCommand = new MySqlCommand(); |
649 | 649 | rootCommand.Connection = rootConnection; |
650 | | - rootCommand.CommandText = string.Format("CREATE DATABASE `{0}`;", database); |
| 650 | + rootCommand.CommandText = string.Format("CREATE DATABASE IF NOT EXISTS `{0}`;", database); |
651 | 651 | rootCommand.CommandText += string.Format("GRANT ALL ON `{0}`.* to '{1}'@'localhost' identified by '{2}';", database, user, password); |
652 | 652 | rootCommand.ExecuteNonQuery(); |
653 | 653 |
|
@@ -675,5 +675,43 @@ public void ExtendedCharsetOnConnection() |
675 | 675 | } |
676 | 676 | } |
677 | 677 | } |
| 678 | + |
| 679 | + [Fact] |
| 680 | + public void CharacterVariablesByDefault() |
| 681 | + { |
| 682 | + MySqlConnectionStringBuilder rootSb = new MySqlConnectionStringBuilder(st.rootConn.ConnectionString); |
| 683 | + rootSb.CharacterSet = string.Empty; |
| 684 | + using (MySqlConnection rootConnection = new MySqlConnection(rootSb.ToString())) |
| 685 | + { |
| 686 | + rootConnection.Open(); |
| 687 | + MySqlCommand cmd = rootConnection.CreateCommand(); |
| 688 | + cmd.CommandText = "SELECT @@character_set_server"; |
| 689 | + string characterSet = cmd.ExecuteScalar().ToString(); |
| 690 | + Assert.False(string.IsNullOrWhiteSpace(characterSet)); |
| 691 | + |
| 692 | + cmd.CommandText = "SHOW VARIABLES LIKE 'character_set_c%'"; |
| 693 | + using (MySqlDataReader dr = cmd.ExecuteReader()) |
| 694 | + { |
| 695 | + Assert.True(dr.HasRows); |
| 696 | + while (dr.Read()) |
| 697 | + { |
| 698 | + switch (dr.GetString(0).ToLowerInvariant()) |
| 699 | + { |
| 700 | + case "character_set_client": |
| 701 | + Assert.Equal(characterSet, dr.GetString(1)); |
| 702 | + break; |
| 703 | + case "character_set_connection": |
| 704 | + Assert.Equal(characterSet, dr.GetString(1)); |
| 705 | + break; |
| 706 | + default: |
| 707 | + throw new InvalidOperationException(string.Format("Variable '{0}' not expected.", dr.GetString(0))); |
| 708 | + } |
| 709 | + } |
| 710 | + } |
| 711 | + |
| 712 | + cmd.CommandText = "SELECT @@character_set_results"; |
| 713 | + Assert.Equal(DBNull.Value, cmd.ExecuteScalar()); |
| 714 | + } |
| 715 | + } |
678 | 716 | } |
679 | 717 | } |
0 commit comments