Skip to content

Commit

Permalink
Add correct code page for Kazakh collation (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
karinazhou authored Jun 10, 2020
1 parent 1be606c commit e1b6cd4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4268,6 +4268,9 @@ internal int GetCodePage(SqlCollation collation, TdsParserStateObject stateObj)
{
}
break;
case 0x43f:
codePage = 1251; // Kazakh code page based on SQL Server
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,9 @@ internal int GetCodePage(SqlCollation collation, TdsParserStateObject stateObj)
ADP.TraceExceptionWithoutRethrow(e);
}
break;
case 0x43f:
codePage = 1251; // Kazakh code page based on SQL Server
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
Expand Down Expand Up @@ -145,6 +146,60 @@ public static void CheckSparseColumnBit()
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
public static void CollatedDataReaderTest()
{
var databaseName = DataTestUtility.GetUniqueName("DB");
// Remove square brackets
var dbName = databaseName.Substring(1, databaseName.Length - 2);

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString)
{
InitialCatalog = dbName,
Pooling = false
};

using (SqlConnection con = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = con.CreateCommand())
{
try
{
con.Open();

// Create collated database
cmd.CommandText = $"CREATE DATABASE {databaseName} COLLATE KAZAKH_90_CI_AI";
cmd.ExecuteNonQuery();

//Create connection without pooling in order to delete database later.
using (SqlConnection dbCon = new SqlConnection(builder.ConnectionString))
using (SqlCommand dbCmd = dbCon.CreateCommand())
{
var data = "TestData";

dbCon.Open();
dbCmd.CommandText = $"SELECT '{data}'";
using (SqlDataReader reader = dbCmd.ExecuteReader())
{
reader.Read();
Assert.Equal(data, reader.GetString(0));
}
}

// Let connection close safely before dropping database for slow servers.
Thread.Sleep(500);
}
catch (SqlException e)
{
Assert.True(false, $"Unexpected Exception occurred: {e.Message}");
}
finally
{
cmd.CommandText = $"DROP DATABASE {databaseName}";
cmd.ExecuteNonQuery();
}
}
}

private static bool IsColumnBitSet(SqlConnection con, string selectQuery, int indexOfColumnSet)
{
bool columnSetPresent = false;
Expand Down

0 comments on commit e1b6cd4

Please sign in to comment.