From 2e38f63e6748d45e2b09daa19204543fd87f2341 Mon Sep 17 00:00:00 2001 From: Deepak Saini Date: Mon, 30 Sep 2024 16:28:40 +0530 Subject: [PATCH 1/3] some enhancements tasks for json support --- .../Data/SqlClient/SqlInternalConnectionTds.cs | 2 -- .../Data/SqlClient/SqlInternalConnectionTds.cs | 2 -- .../tests/ManualTests/SQL/JsonTest/JsonTest.cs | 18 +++++------------- .../tools/TDS/TDS.Servers/GenericTDSServer.cs | 4 ---- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 9d9bf49437..66e01e2c2c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -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); } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 4c0a2d365b..7345e098f4 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -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); } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs index c8b3507b5d..20e12bc29a 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -67,8 +67,7 @@ public void TestJsonWrite() { string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test"); string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_WriteTest"); - - string tableCreate = "CREATE TABLE " + tableName + " (Data json)"; + string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)"; string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert; @@ -79,8 +78,7 @@ 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 command.CommandText = spCreate; @@ -126,7 +124,6 @@ public async Task TestJsonWriteAsync() string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test"); string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_WriteTest"); - string tableCreate = "CREATE TABLE " + tableName + " (Data json)"; string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)"; string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert; @@ -137,8 +134,7 @@ 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 command.CommandText = spCreate; @@ -182,7 +178,6 @@ public void TestJsonRead() string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test"); string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_ReadTest"); - 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; @@ -193,8 +188,7 @@ public void TestJsonRead() 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 command.CommandText = spCreate; @@ -241,7 +235,6 @@ public async Task TestJsonReadAsync() string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test"); string spName = DataTestUtility.GetUniqueNameForSqlServer("spJson_ReadTest"); - 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; @@ -252,8 +245,7 @@ public async Task TestJsonReadAsync() 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 command.CommandText = spCreate; diff --git a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/GenericTDSServer.cs b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/GenericTDSServer.cs index 5d31aaf543..06cc2b7401 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/GenericTDSServer.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/GenericTDSServer.cs @@ -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 @@ -552,7 +550,6 @@ protected virtual TDSMessageCollection OnAuthenticationCompleted(ITDSServerSessi responseMessage.Add(featureExtActToken); } -#if DEBUG // Check if Json is supported if (session.IsJsonSupportEnabled) { @@ -578,7 +575,6 @@ protected virtual TDSMessageCollection OnAuthenticationCompleted(ITDSServerSessi featureExtAckToken.Options.Add(jsonSupportOption); } } -#endif // Create DONE token TDSDoneToken doneToken = new TDSDoneToken(TDSDoneTokenStatusType.Final); From 7e9f0e7354c260f1f0b0e4860b3952cb02166ed8 Mon Sep 17 00:00:00 2001 From: Deepak Saini Date: Mon, 30 Sep 2024 16:35:18 +0530 Subject: [PATCH 2/3] added some missing drop table funtion --- .../tests/ManualTests/SQL/JsonTest/JsonTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs index 20e12bc29a..0a1d5a9fe5 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -168,6 +168,8 @@ public async Task TestJsonWriteAsync() int rowsAffected3 = await command.ExecuteNonQueryAsync(); ValidateRowsAffected(rowsAffected3); } + + DataTestUtility.DropTable(connection, tableName); } } } @@ -280,6 +282,8 @@ public async Task TestJsonReadAsync() await ValidateRowsAsync(reader2); reader2.Close(); } + + DataTestUtility.DropTable(connection, tableName); } } } From a36cbc72872822a5ea82459c2e3a15ce7dc0e47d Mon Sep 17 00:00:00 2001 From: Deepak Saini Date: Mon, 30 Sep 2024 21:14:31 +0530 Subject: [PATCH 3/3] remove unique naming for tables and SPs --- .../ManualTests/SQL/JsonTest/JsonTest.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs index 0a1d5a9fe5..38cbbf7bc2 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -64,9 +64,9 @@ 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 tableName = "jsonWriteTest"; + string spName = "spJsonWriteTest"; string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)"; string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert; @@ -81,6 +81,7 @@ public void TestJsonWrite() DataTestUtility.CreateTable(connection, tableName, "(data json)"); //Create SP for writing json values + DataTestUtility.DropStoredProcedure(connection, spName); command.CommandText = spCreate; command.ExecuteNonQuery(); @@ -114,6 +115,7 @@ public void TestJsonWrite() } DataTestUtility.DropTable(connection, tableName); + DataTestUtility.DropStoredProcedure(connection, spName); } } } @@ -121,8 +123,8 @@ public void TestJsonWrite() [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 tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)"; string spCreate = "CREATE PROCEDURE " + spName + " (@jsonData json) AS " + tableInsert; @@ -137,6 +139,7 @@ public async Task TestJsonWriteAsync() DataTestUtility.CreateTable(connection, tableName, "(data json)"); //Create SP for writing json values + DataTestUtility.DropStoredProcedure(connection, spName); command.CommandText = spCreate; await command.ExecuteNonQueryAsync(); @@ -170,6 +173,7 @@ public async Task TestJsonWriteAsync() } DataTestUtility.DropTable(connection, tableName); + DataTestUtility.DropStoredProcedure(connection, spName); } } } @@ -177,12 +181,12 @@ public async Task TestJsonWriteAsync() [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 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)) { @@ -193,6 +197,7 @@ public void TestJsonRead() DataTestUtility.CreateTable(connection, tableName, "(data json)"); //Create SP for reading from json column + DataTestUtility.DropStoredProcedure(connection, spName); command.CommandText = spCreate; command.ExecuteNonQuery(); @@ -227,6 +232,7 @@ public void TestJsonRead() } DataTestUtility.DropTable(connection, tableName); + DataTestUtility.DropStoredProcedure(connection, spName); } } } @@ -234,12 +240,12 @@ public void TestJsonRead() [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 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)) { @@ -250,6 +256,7 @@ public async Task TestJsonReadAsync() DataTestUtility.CreateTable(connection, tableName, "(data json)"); //Create SP for reading from json column + DataTestUtility.DropStoredProcedure(connection, spName); command.CommandText = spCreate; await command.ExecuteNonQueryAsync(); @@ -284,6 +291,7 @@ public async Task TestJsonReadAsync() } DataTestUtility.DropTable(connection, tableName); + DataTestUtility.DropStoredProcedure(connection, spName); } } }