Fix for deleting text columns (#928)

* Added handling for deleting problematic rows

* minor formatting changes

* Null checks and executereader implemented

* minor formatting

* Fix for column deletion for text

* minor space format

* more format changes

* Removal of top 200 and change of text comparison

* space fix

* minor commit

* Added new tests for single clause

* simplified regex

* spacing fix

* some polish for RowEditBaseTests

* space fix

* loc update (#914)

* loc update

* loc updates

* Warning for multiple delete (#931)

* Fix for multiple delete bug

* minor space removal

* removed catch error in RowDelete

* small optimizations

* space adding

* WIP on creating test

* Some cleanup

* removed spaces

* Fix for verifytext

* Added check for command format correctness.

* tidying up

* added working test for command exception

* simplification of TestDbDataReader getint

* Corrections made

* spacing and naming issues

* minor space

* one more space issue

* Revert "Support ActiveDirectoryPassword authentication (#899)" (#915)

This reverts commit b786a14c03.

* revert changes to connectionService

* fix for asserts

* fix clauses

Co-authored-by: khoiph1 <khoiph@microsoft.com>
Co-authored-by: Amir Omidi <amir@aaomidi.com>
This commit is contained in:
Alex Ma
2021-07-16 14:11:32 -07:00
committed by GitHub
parent 0032cc684b
commit c731744298
2 changed files with 79 additions and 29 deletions

View File

@@ -181,38 +181,60 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
}
else
{
if (cellData.RawObject is byte[] ||
col.DbColumn.DataTypeName.Equals("TEXT", StringComparison.OrdinalIgnoreCase) ||
col.DbColumn.DataTypeName.Equals("NTEXT", StringComparison.OrdinalIgnoreCase))
if (parameterize)
{
// Special cases for byte[] and TEXT/NTEXT types
cellDataClause = "IS NOT NULL";
}
else
{
// General case is to just use the value from the cell
if (parameterize)
// Add a parameter and parameterized clause component
// NOTE: We include the row ID to make sure the parameter is unique if
// we execute multiple row edits at once.
string paramName = $"@Param{RowId}{col.Ordinal}";
if (cellData.RawObject is byte[])
{
// Add a parameter and parameterized clause component
// NOTE: We include the row ID to make sure the parameter is unique if
// we execute multiple row edits at once.
string paramName = $"@Param{RowId}{col.Ordinal}";
cellDataClause = $"= {paramName}";
SqlParameter parameter = new SqlParameter(paramName, col.DbColumn.SqlDbType)
{
Value = cellData.RawObject
};
output.Parameters.Add(parameter);
cellDataClause = $"= CONVERT (VARBINARY(MAX), {paramName})";
}
else if (col.DbColumn.DataTypeName.Equals("TEXT", StringComparison.OrdinalIgnoreCase) || (col.DbColumn.DataTypeName.Equals("TEXT", StringComparison.OrdinalIgnoreCase) ||
col.DbColumn.DataTypeName.Equals("NTEXT", StringComparison.OrdinalIgnoreCase)))
{
// Special case for TEXT/NTEXT types.
//NOTE: the types are not compatible with n/varchar so direct comparison
// will not work for these types, must convert first.
cellDataClause = $"= CONVERT (NVARCHAR(MAX), {paramName})";
}
else
{
// Add the clause component with the formatted value
cellDataClause = $"= {ToSqlScript.FormatValue(cellData, col.DbColumn)}";
cellDataClause = $"= {paramName}";
}
SqlParameter parameter = new SqlParameter(paramName, col.DbColumn.SqlDbType)
{
Value = cellData.RawObject
};
output.Parameters.Add(parameter);
}
else
{
// Add the clause component with the formatted value
cellDataClause = $"= {ToSqlScript.FormatValue(cellData, col.DbColumn)}";
}
}
string completeComponent = $"({col.EscapedName} {cellDataClause})";
string completeComponent;
if (cellData.RawObject is byte[])
{
completeComponent = $"(CONVERT (VARBINARY(MAX), {col.EscapedName}) {cellDataClause})";
}
else if (col.DbColumn.DataTypeName.Equals("TEXT", StringComparison.OrdinalIgnoreCase) ||
col.DbColumn.DataTypeName.Equals("NTEXT", StringComparison.OrdinalIgnoreCase))
{
// Special case for TEXT/NTEXT types as explained on line 197.
completeComponent = $"(CONVERT (NVARCHAR(MAX), {col.EscapedName}) {cellDataClause})";
}
else
{
completeComponent = $"({col.EscapedName} {cellDataClause})";
}
output.ClauseComponents.Add(completeComponent);
}