Skip to content

Commit

Permalink
resolve PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksa1 committed Sep 4, 2024
1 parent 968dcdf commit 6afd501
Showing 1 changed file with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,35 +301,29 @@ public async Task TestJsonReadAsync()
public void TestNullJson()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");

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

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

//Insert Null value
command.CommandText = tableInsert;
var parameter = new SqlParameter("@jsonData", SqlDbTypeExtensions.Json);
parameter.Value = DBNull.Value;
command.Parameters.Add(parameter);
command.ExecuteNonQuery();
using SqlCommand command = connection.CreateCommand();

//Query the table
command.CommandText = tableRead;
var reader = command.ExecuteReader();
//Insert Null value
command.CommandText = tableInsert;
var parameter = new SqlParameter("@jsonData", SqlDbTypeExtensions.Json);
parameter.Value = DBNull.Value;
command.Parameters.Add(parameter);
command.ExecuteNonQuery();

ValidateNullJson(reader);
reader.Close();
}
}
//Query the table
command.CommandText = tableRead;
var reader = command.ExecuteReader();
ValidateNullJson(reader);

reader.Close();
DataTestUtility.DropTable(connection, tableName);
}
}
}

0 comments on commit 6afd501

Please sign in to comment.