Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement tasks for json support #2891

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading