Skip to content

Commit

Permalink
Enhancement tasks for json support (dotnet#2891)
Browse files Browse the repository at this point in the history
* some enhancements tasks for json support

* added some missing drop table funtion

* remove unique naming for tables and SPs
  • Loading branch information
deepaksa1 authored Sep 30, 2024
1 parent 0266b4a commit cc58d79
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1365,9 +1365,7 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,

// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;
#if DEBUG
requestedFeatures |= TdsEnums.FeatureExtension.JsonSupport;
#endif
_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, encrypt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,9 +1641,7 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;

#if DEBUG
requestedFeatures |= TdsEnums.FeatureExtension.JsonSupport;
#endif

_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, _originalNetworkAddressInfo, encrypt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ private void ValidateSchema(SqlDataReader reader)

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public void TestJsonWrite()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");
string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_WriteTest");

string tableCreate = "CREATE TABLE " + tableName + " (Data json)";
{
string tableName = "jsonWriteTest";
string spName = "spJsonWriteTest";

string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)";
string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert;

Expand All @@ -79,10 +78,10 @@ public void TestJsonWrite()
using (SqlCommand command = connection.CreateCommand())
{
//Create Table
command.CommandText = tableCreate;
command.ExecuteNonQuery();
DataTestUtility.CreateTable(connection, tableName, "(data json)");

//Create SP for writing json values
DataTestUtility.DropStoredProcedure(connection, spName);
command.CommandText = spCreate;
command.ExecuteNonQuery();

Expand Down Expand Up @@ -116,17 +115,17 @@ public void TestJsonWrite()
}

DataTestUtility.DropTable(connection, tableName);
DataTestUtility.DropStoredProcedure(connection, spName);
}
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public async Task TestJsonWriteAsync()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");
string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_WriteTest");
string tableName = "jsonWriteTest";
string spName = "spJsonWriteTest";

string tableCreate = "CREATE TABLE " + tableName + " (Data json)";
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)";
string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert;

Expand All @@ -137,10 +136,10 @@ public async Task TestJsonWriteAsync()
using (SqlCommand command = connection.CreateCommand())
{
//Create Table
command.CommandText = tableCreate;
await command.ExecuteNonQueryAsync();
DataTestUtility.CreateTable(connection, tableName, "(data json)");

//Create SP for writing json values
DataTestUtility.DropStoredProcedure(connection, spName);
command.CommandText = spCreate;
await command.ExecuteNonQueryAsync();

Expand Down Expand Up @@ -172,31 +171,33 @@ public async Task TestJsonWriteAsync()
int rowsAffected3 = await command.ExecuteNonQueryAsync();
ValidateRowsAffected(rowsAffected3);
}

DataTestUtility.DropTable(connection, tableName);
DataTestUtility.DropStoredProcedure(connection, spName);
}
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public void TestJsonRead()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");
string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_ReadTest");
string tableName = "jsonReadTest";
string spName = "spJsonReadTest";

string tableCreate = "CREATE TABLE " + tableName + " (Data json)";
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)";
string tableRead = "SELECT * FROM " + tableName;
string spCreate = "CREATE PROCEDURE " + spName + "AS " + tableRead;
string spCreate = "CREATE PROCEDURE " + spName + " AS " + tableRead;

using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
//Create Table
command.CommandText = tableCreate;
command.ExecuteNonQuery();
DataTestUtility.CreateTable(connection, tableName, "(data json)");

//Create SP for reading from json column
DataTestUtility.DropStoredProcedure(connection, spName);
command.CommandText = spCreate;
command.ExecuteNonQuery();

Expand Down Expand Up @@ -231,31 +232,31 @@ public void TestJsonRead()
}

DataTestUtility.DropTable(connection, tableName);
DataTestUtility.DropStoredProcedure(connection, spName);
}
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public async Task TestJsonReadAsync()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");
string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_ReadTest");
string tableName = "jsonReadTest";
string spName = "spJsonReadTest";

string tableCreate = "CREATE TABLE " + tableName + " (Data json)";
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)";
string tableRead = "SELECT * FROM " + tableName;
string spCreate = "CREATE PROCEDURE " + spName + "AS " + tableRead;
string spCreate = "CREATE PROCEDURE " + spName + " AS " + tableRead;

using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
await connection.OpenAsync();
using (SqlCommand command = connection.CreateCommand())
{
//Create Table
command.CommandText = tableCreate;
await command.ExecuteNonQueryAsync();
DataTestUtility.CreateTable(connection, tableName, "(data json)");

//Create SP for reading from json column
DataTestUtility.DropStoredProcedure(connection, spName);
command.CommandText = spCreate;
await command.ExecuteNonQueryAsync();

Expand Down Expand Up @@ -288,6 +289,9 @@ public async Task TestJsonReadAsync()
await ValidateRowsAsync(reader2);
reader2.Close();
}

DataTestUtility.DropTable(connection, tableName);
DataTestUtility.DropStoredProcedure(connection, spName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ public virtual TDSMessageCollection OnLogin7Request(ITDSServerSession session, T

break;
}
#if DEBUG
case TDSFeatureID.JsonSupport:
{
// Enable Json Support
session.IsJsonSupportEnabled = true;
break;
}
#endif
default:
{
// Do nothing
Expand Down Expand Up @@ -552,7 +550,6 @@ protected virtual TDSMessageCollection OnAuthenticationCompleted(ITDSServerSessi
responseMessage.Add(featureExtActToken);
}

#if DEBUG
// Check if Json is supported
if (session.IsJsonSupportEnabled)
{
Expand All @@ -578,7 +575,6 @@ protected virtual TDSMessageCollection OnAuthenticationCompleted(ITDSServerSessi
featureExtAckToken.Options.Add(jsonSupportOption);
}
}
#endif

// Create DONE token
TDSDoneToken doneToken = new TDSDoneToken(TDSDoneTokenStatusType.Final);
Expand Down

0 comments on commit cc58d79

Please sign in to comment.