in src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs [286:479]
private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams requestParams)
{
var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel;
var path = requestParams.TableChangeInfo.Path;
var newValue = requestParams.TableChangeInfo.Value;
if (path.Length == 1)
{
var propertyName = path[0] as string;
switch (propertyName)
{
case TablePropertyNames.Description:
table.Description = GetStringValue(newValue);
break;
case TablePropertyNames.Name:
table.Name = GetStringValue(newValue);
break;
case TablePropertyNames.Schema:
table.Schema = GetStringValue(newValue);
break;
default:
break;
}
}
else if (path.Length == 3)
{
var propertyNameL1 = path[0] as string;
var indexL1 = Convert.ToInt32(path[1]);
var propertyNameL2 = path[2] as string;
switch (propertyNameL1)
{
case TablePropertyNames.Columns:
var column = table.Columns.Items[indexL1];
switch (propertyNameL2)
{
case TableColumnPropertyNames.AllowNulls:
column.IsNullable = GetBooleanValue(newValue);
break;
case TableColumnPropertyNames.DefaultValue:
column.DefaultValue = GetStringValue(newValue);
break;
case TableColumnPropertyNames.IdentityIncrement:
column.IdentityIncrement = GetInt32Value(newValue);
break;
case TableColumnPropertyNames.IdentitySeed:
column.IdentitySeed = GetInt32Value(newValue);
break;
case TableColumnPropertyNames.IsIdentity:
column.IsIdentity = GetBooleanValue(newValue);
break;
case TableColumnPropertyNames.IsPrimaryKey:
column.IsPrimaryKey = GetBooleanValue(newValue);
break;
case TableColumnPropertyNames.Length:
column.Length = GetStringValue(newValue);
break;
case TableColumnPropertyNames.Name:
column.Name = GetStringValue(newValue);
break;
case TableColumnPropertyNames.Precision:
column.Precision = GetInt32Value(newValue);
break;
case TableColumnPropertyNames.Scale:
column.Scale = GetInt32Value(newValue);
break;
case TableColumnPropertyNames.Type:
column.DataType = GetStringValue(newValue);
break;
default:
break;
}
break;
case TablePropertyNames.CheckConstraints:
var checkConstraint = table.CheckConstraints.Items[indexL1];
switch (propertyNameL2)
{
case CheckConstraintPropertyNames.Name:
checkConstraint.Name = GetStringValue(newValue);
break;
case CheckConstraintPropertyNames.Enabled:
checkConstraint.Enabled = GetBooleanValue(newValue);
break;
case CheckConstraintPropertyNames.Expression:
checkConstraint.Expression = GetStringValue(newValue);
break;
default:
break;
}
break;
case TablePropertyNames.ForeignKeys:
var foreignKey = table.ForeignKeys.Items[indexL1];
switch (propertyNameL2)
{
case ForeignKeyPropertyNames.Enabled:
foreignKey.Enabled = GetBooleanValue(newValue);
break;
case ForeignKeyPropertyNames.IsNotForReplication:
foreignKey.IsNotForReplication = GetBooleanValue(newValue);
break;
case ForeignKeyPropertyNames.Name:
foreignKey.Name = GetStringValue(newValue);
break;
case ForeignKeyPropertyNames.OnDeleteAction:
foreignKey.OnDeleteAction = SqlForeignKeyActionUtil.GetValue(GetStringValue(newValue));
break;
case ForeignKeyPropertyNames.OnUpdateAction:
foreignKey.OnUpdateAction = SqlForeignKeyActionUtil.GetValue(GetStringValue(newValue));
break;
case ForeignKeyPropertyNames.PrimaryKeyTable:
foreignKey.PrimaryKeyTable = GetStringValue(newValue);
break;
default:
break;
}
break;
case TablePropertyNames.Indexes:
var sqlIndex = table.Indexes.Items[indexL1];
switch (propertyNameL2)
{
case IndexPropertyNames.Enabled:
sqlIndex.Enabled = GetBooleanValue(newValue);
break;
case IndexPropertyNames.IsClustered:
sqlIndex.IsClustered = GetBooleanValue(newValue);
break;
case IndexPropertyNames.IsUnique:
sqlIndex.IsUnique = GetBooleanValue(newValue);
break;
case IndexPropertyNames.Name:
sqlIndex.Name = GetStringValue(newValue);
break;
default:
break;
}
break;
default:
break;
}
}
else if (path.Length == 5)
{
var propertyNameL1 = path[0] as string;
var indexL1 = Convert.ToInt32(path[1]);
var propertyNameL2 = path[2] as string;
var indexL2 = Convert.ToInt32(path[3]);
var propertyNameL3 = path[4] as string;
switch (propertyNameL1)
{
case TablePropertyNames.ForeignKeys:
// TODO: handle foreign key collection property update
// changes need to be made in DACFX to support it.
switch (propertyNameL2)
{
case ForeignKeyPropertyNames.ColumnMapping:
switch (propertyNameL3)
{
case ForeignKeyColumnMappingPropertyNames.ForeignKeyColumn:
break;
case ForeignKeyColumnMappingPropertyNames.PrimaryKeyColumn:
break;
default:
break;
}
break;
default:
break;
}
break;
case TablePropertyNames.Indexes:
var sqlIndex = table.Indexes.Items[indexL1];
switch (propertyNameL2)
{
case IndexPropertyNames.Columns:
var columnSpec = sqlIndex.Columns[indexL2];
switch (propertyNameL3)
{
case IndexColumnSpecificationPropertyNames.Column:
columnSpec.Column = GetStringValue(newValue);
break;
case IndexColumnSpecificationPropertyNames.Ascending:
columnSpec.isAscending = GetBooleanValue(newValue);
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
}
}