/// <summary>
        /// Create a JET_COLUMNDEF from a ColumnDefintion.
        /// </summary>
        /// <param name="definition">The column definition to convert.</param>
        /// <returns>A JET_COLUMNDEF representing the ColumnDefintion.</returns>
        public JET_COLUMNDEF CreateColumndefFromColumnDefinition(ColumnDefinition definition)
        {
            ColumndefGrbit grbit = CalculateColumndefGrbit(definition);

            var columndef = new JET_COLUMNDEF
            {
                cbMax = definition.MaxSize,
                coltyp = this.columnTypeToColtypMapping[definition.Type],
                cp = (ColumnType.AsciiText == definition.Type) ? JET_CP.ASCII : JET_CP.Unicode,
                grbit = grbit,
            };

            return columndef;
        }
Exemple #2
0
 /// <summary>
 /// Returns a copy of the ColumnDefinition.
 /// </summary>
 /// <returns>A copy of the current definition.</returns>
 private ColumnDefinition Clone()
 {
     var clone = new ColumnDefinition(this.Name, this.Type)
         {
             IsAutoincrement = this.IsAutoincrement,
             IsNotNull = this.IsNotNull,
             IsVersion = this.IsVersion,
             MaxSize = this.MaxSize,
             DefaultValue = this.DefaultValue
         };
     return clone;
 }
        /// <summary>
        /// Determine the ColumndefGrbit for the column definition.
        /// </summary>
        /// <param name="definition">The column definition.</param>
        /// <returns>The grbit to use when creating the column.</returns>
        private static ColumndefGrbit CalculateColumndefGrbit(ColumnDefinition definition)
        {
            ColumndefGrbit grbit = ColumndefGrbit.None;
            if (definition.IsAutoincrement)
            {
                grbit |= ColumndefGrbit.ColumnAutoincrement;
            }

            if (definition.IsNotNull)
            {
                grbit |= ColumndefGrbit.ColumnNotNULL;
            }

            if (definition.IsVersion)
            {
                grbit |= ColumndefGrbit.ColumnVersion;
            }

            if (EsentVersion.SupportsWindows7Features)
            {
                // Only long-value columns can be compressed
                if (ColumnType.Binary == definition.Type
                    || ColumnType.AsciiText == definition.Type
                    || ColumnType.Text == definition.Type)
                {
                    grbit |= Windows7Grbits.ColumnCompressed;
                }
            }

            return grbit;
        }
 /// <summary>
 /// Create a table with a column of the given type and make sure the SqlImplementation class
 /// is called with the right arguments.
 /// </summary>
 /// <param name="columnType">The column type to expect.</param>
 /// <param name="sqlType">The string to use as the SQL column type.</param>
 private void TestCreateSingleColumnTable(ColumnType columnType, string sqlType)
 {
     var columndefs = new ColumnDefinition[]
     {
         new ColumnDefinition("mycolumn", columnType),
     };
     Expect.Call(() => this.mockImpl.CreateTable(null, null)).Constraints(Is.Equal("mytable"), List.Equal(columndefs));
     this.mocks.ReplayAll();
     this.sql.Execute(String.Format("CREATE TABLE mytable (mycolumn {0})", sqlType));
     this.mocks.VerifyAll();
 }
        public void CreateColumnWithDefaultValue()
        {
            var columndef = new ColumnDefinition("defaultcolumn", ColumnType.Int32);
            columndef.DefaultValue = "1234";

            this.table.CreateColumn(columndef);

            Record record = this.table.NewRecord();
            record.Save();

            Assert.AreEqual(1234, record["defaultcolumn"]);
        }
Exemple #6
0
 /// <summary>
 /// Add a new column to the table. This always fails, as the table is read-only.
 /// </summary>
 /// <param name="columndef">The column definition.</param>
 /// <returns>Always throws an exception.</returns>
 public override Table CreateColumn(ColumnDefinition columndef)
 {
     this.CheckNotClosed();
     throw this.CreateReadOnlyException();
 }
Exemple #7
0
 /// <summary>
 /// Add a new column to the table.
 /// </summary>
 /// <param name="columndef">The column definition.</param>
 /// <returns>The table the column was added to.</returns>
 public abstract Table CreateColumn(ColumnDefinition columndef);