Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 committed Mar 20, 2019
1 parent 9c2a700 commit a15c350
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3332,18 +3332,15 @@ private void SetUpRPCParameters(_SqlRPC rpc, int startCount, bool inSchema, SqlP
if (parameter.IsDerivedParameterTypeName)
{
string[] parts = MultipartIdentifier.ParseMultipartIdentifier(parameter.TypeName, "[\"", "]\"", SR.SQL_TDSParserTableName, false);
if (parts != null)
if (parts != null && parts.Length==4) // will always return int[4] right justified
{
int length = parts.Length;
if (
length >= 3 && //require at least 3 parts
parts[length - 1] != null && // name must not be null
parts[length - 2] != null && // schema must not be null
parts[length - 3] != null && // server should not be null or we don't need to remove it
(length == 3 || parts[length - 4] == null) // if a database space is availble then is must be null
parts[3] != null && // name must not be null
parts[2] != null && // schema must not be null
parts[1] != null // server should not be null or we don't need to remove it
)
{
parameter.TypeName = QuoteIdentifier(parts.AsSpan(length-2));
parameter.TypeName = QuoteIdentifier(parts.AsSpan(2,2));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private enum SqlParameterFlags : short
CoercedValueIsDataFeed = 1 << 5,
IsDerivedParameterTypeName = 1 << 6,
SourceColumnNullMapping = 1 << 7,
HasScale = 1 << 9, // V1.0 compat, ignore _hasScale
HasScale = 1 << 8, // V1.0 compat, ignore _hasScale
}

private MetaType _metaType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void UDT_DataSetFill()
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsUdtTestDatabasePresent), nameof(DataTestUtility.AreConnStringsSetup))]
public void UDTParams_DeriveParameters()
public void UDTParams_DeriveParameters_CheckAutoFixSuccess()
{
// the type and sproc must be commited to the database or this test will deadlock with a schema lock violation
// if you are missing these database entities then you should look for an updated version of the database creation script
Expand Down Expand Up @@ -402,6 +402,68 @@ public void UDTParams_DeriveParameters()
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsUdtTestDatabasePresent), nameof(DataTestUtility.AreConnStringsSetup))]
public void UDTParams_DeriveParameters_CheckAutoFixOverride()
{
// the type and sproc must be commited to the database or this test will deadlock with a schema lock violation
// if you are missing these database entities then you should look for an updated version of the database creation script

string sprocName = "sp_insert_customers";
string typeName = "CustomerAddress";
string customerAddressTypeIncorrectName = $"{DataTestUtility.UdtTestDbName}.dbo.{typeName.Trim('[', ']')}";
string customerAddressTypeCorrectedName = $"[dbo].[{typeName.Trim('[', ']')}]";
string customerParameterName = "@customers";

Address addr = Address.Parse("123 baker st || Redmond");
DataTable table = new DataTable();
table.Columns.Add();
table.Columns.Add();
table.Rows.Add("john", addr);

using (SqlConnection connection = new SqlConnection(_connStr))
{
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
using (SqlCommand cmd = new SqlCommand(sprocName, connection, transaction))
{
try
{
cmd.CommandType = CommandType.StoredProcedure;

SqlCommandBuilder.DeriveParameters(cmd);

Assert.NotNull(cmd.Parameters);
Assert.Equal(2, cmd.Parameters.Count); // [return_value, table]

SqlParameter p = cmd.Parameters[1];

Assert.Equal(customerParameterName, p.ParameterName);
Assert.Equal(SqlDbType.Structured, p.SqlDbType);
Assert.Equal(customerAddressTypeIncorrectName, p.TypeName); // the 3 part name is incorrect but needs to be maintained for compatibility
p.Value = table;

p.TypeName = customerAddressTypeIncorrectName; // force using the incorrect name by manually setting it

Assert.Throws<SqlException>(
() => cmd.ExecuteNonQuery()
);
}
finally
{
try
{
transaction.Rollback();
}
catch
{
// ignore rollback failure exceptions to preserve original thrown error in test result
}
}
}

}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsUdtTestDatabasePresent), nameof(DataTestUtility.AreConnStringsSetup))]
public void Reader_PointEarly()
{
Expand Down

0 comments on commit a15c350

Please sign in to comment.