Example #1
0
        public void SetColNullability(ColumnSchema column, bool nullable)
        {
            int columnIndex = this._table.GetColumnIndex(column.GetName().Name);

            if (column.IsNullable() != nullable)
            {
                if (!nullable)
                {
                    Constraint c = new Constraint(this._database.NameManager.NewAutoName("CT", this._table.GetSchemaName(), this._table.GetName(), 5), null, 3)
                    {
                        Check = new ExpressionLogical(column)
                    };
                    c.PrepareCheckConstraint(this._session, this._table, true);
                    column.SetNullable(false);
                    this._table.AddConstraint(c);
                    this._table.SetColumnTypeVars(columnIndex);
                    this._database.schemaManager.AddSchemaObject(c);
                }
                else
                {
                    if (column.IsPrimaryKey())
                    {
                        throw Error.GetError(0x1596);
                    }
                    this._table.CheckColumnInFkConstraint(columnIndex, 2);
                    this.RemoveColumnNotNullConstraints(columnIndex);
                }
            }
        }
Example #2
0
 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);
     }
 }
Example #3
0
        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);
            }
        }