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);
            }
        }
Example #4
0
 public void CheckCreateForeignKey(Constraint c)
 {
     if ((((c.Core.UpdateAction == 4) || (c.Core.UpdateAction == 2)) || ((c.Core.UpdateAction == 0) || (c.Core.DeleteAction == 4))) || (c.Core.DeleteAction == 2))
     {
         for (int i = 0; i < c.Core.RefCols.Length; i++)
         {
             ColumnSchema column = this._table.GetColumn(c.Core.RefCols[i]);
             if (column.IsGenerated())
             {
                 throw Error.GetError(0x1594, column.GetNameString());
             }
         }
     }
     if ((c.Core.MainName == this._table.GetName()) && ArrayUtil.HaveCommonElement(c.Core.RefCols, c.Core.MainCols))
     {
         throw Error.GetError(0x1597);
     }
     if ((c.Core.UpdateAction == 4) || (c.Core.DeleteAction == 4))
     {
         for (int i = 0; i < c.Core.RefCols.Length; i++)
         {
             ColumnSchema column = this._table.GetColumn(c.Core.RefCols[i]);
             if (column.GetDefaultExpression() == null)
             {
                 string statementName = column.GetName().StatementName;
                 throw Error.GetError(0x1591, statementName);
             }
         }
     }
     if (((c.Core.UpdateAction == 2) || (c.Core.DeleteAction == 2)) && !this._session.IsProcessingScript())
     {
         for (int i = 0; i < c.Core.RefCols.Length; i++)
         {
             ColumnSchema column = this._table.GetColumn(c.Core.RefCols[i]);
             if (!column.IsNullable())
             {
                 string statementName = column.GetName().StatementName;
                 throw Error.GetError(0x1590, statementName);
             }
         }
     }
     this._database.schemaManager.CheckSchemaObjectNotExists(c.GetName());
     if (this._table.GetConstraint(c.GetName().Name) != null)
     {
         throw Error.GetError(0x1580, c.GetName().StatementName);
     }
     if (this._table.GetFkConstraintForColumns(c.Core.MainTable, c.Core.MainCols, c.Core.RefCols) != null)
     {
         throw Error.GetError(0x1598, c.GetName().StatementName);
     }
     if (c.Core.MainTable.IsTemp() != this._table.IsTemp())
     {
         throw Error.GetError(0x1594, c.GetName().StatementName);
     }
     if (c.Core.MainTable.GetUniqueConstraintForColumns(c.Core.MainCols, c.Core.RefCols) == null)
     {
         throw Error.GetError(0x1599, c.GetMain().GetName().StatementName);
     }
     c.Core.MainTable.CheckColumnsMatch(c.Core.MainCols, this._table, c.Core.RefCols);
     bool[] columnCheckList = c.Core.MainTable.GetColumnCheckList(c.Core.MainCols);
     this._session.GetGrantee().CheckReferences(c.Core.MainTable, columnCheckList);
 }