public void CheckAddColumn(ColumnSchema col) { this.CheckModifyTable(); if (this._table.FindColumn(col.GetName().Name) != -1) { throw Error.GetError(0x1580); } if (col.IsPrimaryKey() && this._table.HasPrimaryKey()) { throw Error.GetError(0x159a); } if (col.IsIdentity() && this._table.HasIdentityColumn()) { throw Error.GetError(0x1595); } if (((!this._table.IsEmpty(this._session) && !col.HasDefault) && (!col.IsNullable() || col.IsPrimaryKey())) && !col.IsIdentity()) { throw Error.GetError(0x159b); } }
public void RetypeColumn(ColumnSchema oldCol, ColumnSchema newCol) { bool flag = true; int typeCode = oldCol.GetDataType().TypeCode; int num2 = newCol.GetDataType().TypeCode; this.CheckModifyTable(); if (!this._table.IsEmpty(this._session) && (typeCode != num2)) { flag = newCol.GetDataType().CanConvertFrom(oldCol.GetDataType()); switch (typeCode) { case 0x457: case 0x7d0: flag = false; break; } } if (!flag) { throw Error.GetError(0x15b9); } int columnIndex = this._table.GetColumnIndex(oldCol.GetName().Name); if ((newCol.IsIdentity() && this._table.HasIdentityColumn()) && (this._table.IdentityColumn != columnIndex)) { throw Error.GetError(0x1595); } if (this._table.GetPrimaryKey().Length > 1) { newCol.SetPrimaryKey(oldCol.IsPrimaryKey()); if (ArrayUtil.Find(this._table.GetPrimaryKey(), columnIndex) == -1) { } } else if (this._table.HasPrimaryKey()) { if (!oldCol.IsPrimaryKey()) { if (newCol.IsPrimaryKey()) { throw Error.GetError(0x159c); } } else { newCol.SetPrimaryKey(true); } } else if (newCol.IsPrimaryKey()) { throw Error.GetError(0x159a); } if (((((num2 == typeCode) & (oldCol.IsNullable() == newCol.IsNullable())) & (oldCol.GetDataType().Scale == newCol.GetDataType().Scale)) & (oldCol.IsIdentity() == newCol.IsIdentity())) & ((oldCol.GetDataType().Precision == newCol.GetDataType().Precision) || ((oldCol.GetDataType().Precision < newCol.GetDataType().Precision) && ((typeCode == 12) || (typeCode == 0x3d))))) { oldCol.SetType(newCol); oldCol.SetDefaultExpression(newCol.GetDefaultExpression()); if (newCol.IsIdentity()) { oldCol.SetIdentity(newCol.GetIdentitySequence()); } this._table.SetColumnTypeVars(columnIndex); this._table.ResetDefaultsFlag(); } else { this._database.schemaManager.CheckColumnIsReferenced(this._table.GetName(), this._table.GetColumn(columnIndex).GetName()); this._table.CheckColumnInCheckConstraint(columnIndex); this._table.CheckColumnInFkConstraint(columnIndex); this.CheckConvertColDataType(oldCol, newCol); this.RetypeColumn(newCol, columnIndex); } }