private void ValidateTableDefinition()

in isam/TemporaryDatabase.cs [728:874]


        private void ValidateTableDefinition(TableDefinition tableDefinition)
        {
            // validate the table's properties
            DatabaseCommon.CheckName(
                tableDefinition.Name,
                new ArgumentException("Illegal name for a temporary table.", "tableDefinition"));
            if (tableDefinition.Name == null)
            {
                throw new ArgumentException("Illegal name for a temporary table.", "tableDefinition");
            }

            if (
                !(tableDefinition.Type == TableType.Sort || tableDefinition.Type == TableType.PreSortTemporary
                  || tableDefinition.Type == TableType.Temporary))
            {
                throw new ArgumentException("Illegal TableType for a temporary table.", "tableDefinition");
            }

            // validate all columns
            if (tableDefinition.Columns.Count == 0)
            {
                throw new ArgumentException("Temporary tables must have at least one column.", "tableDefinition");
            }

            foreach (ColumnDefinition columnDefinition in tableDefinition.Columns)
            {
                DatabaseCommon.CheckName(
                    columnDefinition.Name,
                    new ArgumentException("Illegal name for a column in a temporary table.", "tableDefinition"));
                if (columnDefinition.Name == null)
                {
                    throw new ArgumentException("Illegal name for a column in a temporary table.", "tableDefinition");
                }

                if (tableDefinition.Type == TableType.Sort || tableDefinition.Type == TableType.PreSortTemporary)
                {
                    JET_coltyp coltyp = DatabaseCommon.ColtypFromColumnDefinition(columnDefinition);
                    if (coltyp == JET_coltyp.LongText || coltyp == JET_coltyp.LongBinary)
                    {
                        // timestamp when ESE/ESENT supports JET_bitTTIntrinsicLVsOnly
                        DatabaseCommon.CheckEngineVersion(
                            this.IsamSession,
                            DatabaseCommon.ESENTVersion(6, 1, 6492, 0),
                            DatabaseCommon.ESEVersion(14, 0, 46, 0),
                            new ArgumentException(
                                "LongText and LongBinary columns are not supported for columns in a temporary table of type TableType.Sort or TableType.PreSortTemporary on this version of the database engine.",
                                "tableDefinition"));
                    }
                }

                if (0 != (columnDefinition.Flags
                          & ~(ColumnFlags.Fixed
                              | ColumnFlags.Variable
                              | ColumnFlags.Sparse
                              | ColumnFlags.NonNull
                              | ColumnFlags.MultiValued)))
                {
                    throw new ArgumentException("Illegal ColumnFlags for a column in a temporary table.", "tableDefinition");
                }

                if (columnDefinition.DefaultValue != null)
                {
                    throw new ArgumentException("Default values are not supported for temporary table columns.", "tableDefinition");
                }
            }

            // validate all indices
            if (tableDefinition.Indices.Count == 0
                && (tableDefinition.Type == TableType.Sort || tableDefinition.Type == TableType.PreSortTemporary))
            {
                throw new ArgumentException("Temporary tables of type TableType.Sort and TableType.PreSortTemporary must have an index defined.", "tableDefinition");
            }

            if (tableDefinition.Indices.Count > 1)
            {
                throw new ArgumentException("Temporary tables may only have a single index defined.", "tableDefinition");
            }

            foreach (IndexDefinition indexDefinition in tableDefinition.Indices)
            {
                DatabaseCommon.CheckName(
                    indexDefinition.Name,
                    new ArgumentException("Illegal name for an index in a temporary table.", "tableDefinition"));
                if (indexDefinition.Name == null)
                {
                    throw new ArgumentException("Illegal name for an index in a temporary table.", "tableDefinition");
                }

                if (0 != (indexDefinition.Flags
                          & ~(IndexFlags.Unique
                              | IndexFlags.Primary
                              | IndexFlags.AllowNull
                              | IndexFlags.SortNullsLow
                              | IndexFlags.SortNullsHigh
                              | IndexFlags.AllowTruncation)))
                {
                    throw new ArgumentException("Illegal IndexFlags for an index in a temporary table.", "tableDefinition");
                }

                // Require AllowTruncation.
                if (0 == (indexDefinition.Flags & IndexFlags.AllowTruncation))
                {
                    throw new ArgumentException("Illegal IndexFlags for an index in a temporary table.", "tableDefinition");
                }

                // 255 in XP.
                long keyMost = this.IsamSession.IsamInstance.IsamSystemParameters.KeyMost;

                if (indexDefinition.MaxKeyLength < 255 || indexDefinition.MaxKeyLength > keyMost)
                {
                    throw new ArgumentException("Illegal or unsupported MaxKeyLength for an index in a temporary table.", "tableDefinition");
                }

                // 12 in XP. 16 in Vista.
                int keyColumnMost = 16;

                if (indexDefinition.KeyColumns.Count == 0)
                {
                    throw new ArgumentException("No KeyColumns for an index in a temporary table.", "tableDefinition");
                }

                if (indexDefinition.KeyColumns.Count > keyColumnMost)
                {
                    throw new ArgumentException("Too many KeyColumns for an index in a temporary table.", "tableDefinition");
                }

                foreach (KeyColumn keyColumn in indexDefinition.KeyColumns)
                {
                    if (!tableDefinition.Columns.Contains(keyColumn.Name))
                    {
                        throw new ArgumentException("A KeyColumn for an index in the temporary table refers to a column that doesn't exist.", "tableDefinition");
                    }
                }

                if (indexDefinition.ConditionalColumns.Count != 0)
                {
                    throw new ArgumentException("Conditional columns are not supported for temporary table indices.", "tableDefinition");
                }

                if ((indexDefinition.Flags & IndexFlags.Primary) == 0
                    && (tableDefinition.Type == TableType.PreSortTemporary
                        || tableDefinition.Type == TableType.Temporary))
                {
                    throw new ArgumentException("Temporary tables of type TableType.PreSortTemporary and TableType.Temporary must have a primary index defined.", "tableDefinition");
                }
            }
        }