コード例 #1
0
        public void VerifyGetCurrentIndexReturnsIndexName()
        {
            const string IndexName = "NewIndexName";

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                // Oddity: Why dcan't it be specified in the constructor?
                // KeyColumns = indexKeys,
                IndexDefinition newIndex = new IndexDefinition(IndexName)
                {
                    Flags = IndexFlags.None, Density = 100,
                };

                var indexKey = new KeyColumn(this.testColumnid.Name, true);
                newIndex.KeyColumns.Add(indexKey);

                this.tableid.TableDefinition.CreateIndex(newIndex);

                transaction.Commit(false);

                this.tableid.SetCurrentIndex(IndexName);

                string actualIndexName;
                actualIndexName = this.tableid.CurrentIndex;

                Assert.AreEqual(IndexName, actualIndexName);

                // Try to set it to null (the primary index)
                this.tableid.CurrentIndex = null;
                actualIndexName           = this.tableid.CurrentIndex;
                Assert.AreEqual("PrimaryIndex", actualIndexName);
            }
        }
コード例 #2
0
        public void IsamDeleteTable()
        {
            const string TableName = "table_to_delete";

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                var tabledef = new TableDefinition(TableName);
                this.dbid.CreateTable(tabledef);
                trx.Commit(false);
            }

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                this.dbid.DropTable(TableName);
                trx.Commit(false);
            }

            try
            {
                Cursor cursor = this.dbid.OpenCursor(TableName, false);
                Assert.Fail("Column is still visible");
            }
            catch (Miei.EsentObjectNotFoundException)
            {
            }
        }
コード例 #3
0
        public void TestDisallowTruncation()
        {
            const string IndexName = "no_trunacation_index";

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                IndexDefinition indexdef = new IndexDefinition(IndexName);
                indexdef.KeyColumns.Add(new KeyColumn(IsamDdlTests.TestColumnName, true));
                indexdef.Flags = IndexFlags.DisallowTruncation;

                this.tableid.TableDefinition.CreateIndex(indexdef);
                trx.Commit(false);
            }

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                this.tableid.BeginEditForInsert();
                this.tableid.EditRecord[this.testColumnid.Name] = new string('X', 4096);
                try
                {
                    this.tableid.AcceptChanges();
                    Assert.Fail("Expected a truncation error");
                }
                catch (Miei.EsentKeyTruncatedException)
                {
                    // Expected
                }

                trx.Rollback();
            }

            this.tableid.TableDefinition.DropIndex(IndexName);
        }
コード例 #4
0
        public void IsamCreateIndexInvalidName()
        {
            const string IndexName = "[BAD!NAME]";

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                // Oddity: Why dcan't it be specified in the constructor?
                // KeyColumns = indexKeys,
                IndexDefinition newIndex = new IndexDefinition(IndexName)
                {
                    Flags = IndexFlags.None, Density = 100,
                };

                var indexKey = new KeyColumn(this.testColumnid.Name, true);
                newIndex.KeyColumns.Add(indexKey);

                try
                {
                    this.tableid.TableDefinition.CreateIndex(newIndex);
                    Assert.Fail("Expected exception not thrown.");
                }
                catch (Miei.EsentInvalidNameException)
                {
                }

                transaction.Commit(false);
            }
        }
コード例 #5
0
        public void JetGetTableColumnBaseInfo()
        {
            const string ColumnName = "column1";
            var          columndef  = new ColumnDefinition(ColumnName, typeof(string), ColumnFlags.Variable);

            columndef.MaxLength = 4096;
            Assert.IsFalse(columndef.IsAscii);

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                this.tableid.TableDefinition.AddColumn(columndef);

                trx.Commit();
            }

            ColumnDefinition actual = this.tableid.TableDefinition.Columns[ColumnName];

            Assert.AreEqual(columndef.MaxLength, actual.MaxLength);
            Assert.AreEqual(ColumnFlags.Sparse, actual.Flags);
            Assert.AreEqual(columndef.IsAscii, actual.IsAscii);
            Assert.IsFalse(actual.IsAscii);
            //// Assert.AreEqual(columndef.Columnid, actual.Columnid);
            Assert.AreEqual(columndef.Type, actual.Type);

            // The output grbit isn't checked for equality as esent will add some options by default.
        }
コード例 #6
0
        public void TestColumnCollectionByColumnid()
        {
            const string ColumnName = "column2";

            using (var trx = new IsamTransaction(this.sesid))
            {
                var columndefExpected = new ColumnDefinition(ColumnName)
                {
                    MaxLength = 8192,
                    Type      = typeof(string),
                    Flags     = ColumnFlags.None,
                };

                this.tableid.TableDefinition.AddColumn(columndefExpected);
                trx.Commit(false);

                ColumnDefinition columndefForColumnid = this.tableid.TableDefinition.Columns[ColumnName];
                ColumnDefinition retrievedColumndef   =
                    this.tableid.TableDefinition.Columns[columndefForColumnid.Columnid];

                Assert.AreEqual(columndefExpected.MaxLength, retrievedColumndef.MaxLength);
                Assert.AreEqual(false, retrievedColumndef.IsAscii);
                Assert.AreEqual(columndefExpected.Type, retrievedColumndef.Type);
                Assert.IsNotNull(retrievedColumndef.Columnid);

                // The Flags aren't asserted as esent will add some options by default
            }
        }
コード例 #7
0
        public void TestColumnCollectionByName()
        {
            const string ColumnName = "column1";

            using (var trx = new IsamTransaction(this.sesid))
            {
                var columndefExpected = new ColumnDefinition(ColumnName)
                {
                    MaxLength = 4096,
                    Type      = typeof(string),
                    Flags     = ColumnFlags.None,
                };

                this.tableid.TableDefinition.AddColumn(columndefExpected);
                trx.Commit(false);

                ColumnDefinition retrievedColumndef = this.tableid.TableDefinition.Columns[ColumnName];

                Assert.AreEqual(columndefExpected.MaxLength, retrievedColumndef.MaxLength);
                Assert.AreEqual(false, retrievedColumndef.IsAscii);
                Assert.AreEqual(columndefExpected.Type, retrievedColumndef.Type);
                Assert.IsNotNull(retrievedColumndef.Columnid);

                // The Flags comparison fails, as esent will add some options by default
                // Assert.AreEqual(columndefExpected.Flags, retrievedColumndef.Flags);
                Assert.AreEqual(ColumnFlags.Sparse, retrievedColumndef.Flags);
            }
        }
コード例 #8
0
        public void TestDropColumn()
        {
            const string ColumnName   = "column_to_delete";
            int          defaultValue = Any.Int32;

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                var columndef = new ColumnDefinition(ColumnName)
                {
                    Type = typeof(int), DefaultValue = defaultValue,
                };
                this.tableid.TableDefinition.AddColumn(columndef);

                trx.Commit(false);
            }

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                this.tableid.TableDefinition.DropColumn(ColumnName);
                trx.Commit(false);

                try
                {
                    var columndef = this.tableid.TableDefinition.Columns[ColumnName];
                    Assert.Fail("Column is still visible");
                }
                catch (Miei.EsentColumnNotFoundException)
                {
                }
            }
        }
コード例 #9
0
        public void CreateOneColumnOfEachType()
        {
            Type[] validTypes = new Type[]
            {
                typeof(bool), typeof(byte), typeof(char), typeof(System.DateTime), typeof(double),
                typeof(short), typeof(int), typeof(long), typeof(float), typeof(string),
                typeof(ushort), typeof(uint), typeof(byte[]), typeof(System.Guid),
            };
            using (var trx = new IsamTransaction(this.sesid))
            {
                foreach (var coltyp in validTypes)
                {
                    var columnName = coltyp.ToString();
                    columnName = columnName.Substring(columnName.LastIndexOf('.') + 1);

                    // Special case byte[]
                    if ("Byte[]" == columnName)
                    {
                        columnName = "ByteArray";
                    }

                    Debug.Print("columnName is '{0}'", columnName);

                    var columndef = new ColumnDefinition(columnName)
                    {
                        Type = coltyp
                    };
                    this.tableid.TableDefinition.AddColumn(columndef);

                    Assert.AreEqual(columndef.Name, this.tableid.TableDefinition.Columns[columnName].Name);
                }

                trx.Commit(false);
            }
        }
コード例 #10
0
        public void IsamDropIndex()
        {
            const string IndexName = "index_to_delete";

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                // Oddity: Why dcan't it be specified in the constructor?
                // KeyColumns = indexKeys,
                IndexDefinition newIndex = new IndexDefinition(IndexName)
                {
                    Flags = IndexFlags.None, Density = 100,
                };

                var indexKey = new KeyColumn(this.testColumnid.Name, true);
                newIndex.KeyColumns.Add(indexKey);

                this.tableid.TableDefinition.CreateIndex(newIndex);

                transaction.Commit(false);

                this.tableid.SetCurrentIndex(IndexName);
            }

            try
            {
                // Try deleting it, even though it is in use. Should fail.
                this.tableid.TableDefinition.DropIndex(IndexName);
                Assert.Fail("Index was deleted, even though it is in use!");
            }
            catch (Miei.EsentIndexInUseException)
            {
                // Expected exception thrown
            }

            // Set to the primary index.
            this.tableid.SetCurrentIndex(null);

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                this.tableid.TableDefinition.DropIndex(IndexName);
                transaction.Commit(false);
            }

            try
            {
                this.tableid.SetCurrentIndex(IndexName);
                Assert.Fail("Index is still visible");
            }
            catch (Miei.EsentErrorException)
            {
                // Expected exception thrown
            }
        }
コード例 #11
0
 public void TestCursorDisposeAfterRollback()
 {
     using (IsamTransaction trx = new IsamTransaction(this.sesid))
     {
         using (var tableid = this.dbid.OpenCursor(this.tableName))
         {
             // Issue: This is not safe. It actually crashes, because
             // rolling back a transaction will close the underlying table.
             // trx.Rollback();
         }
     }
 }
コード例 #12
0
        public void CreateColumnWithDefaultValue()
        {
            int          defaultValue  = Any.Int32;
            const string NewColumnName = "column_with_default";

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                var columndef = new ColumnDefinition(NewColumnName)
                {
                    Type = typeof(int), DefaultValue = defaultValue,
                };

                this.tableid.TableDefinition.AddColumn(columndef);

                trx.Commit(false);

                try
                {
                    using (IsamTransaction trx2 = new IsamTransaction(this.sesid))
                    {
                        using (var cursor = this.dbid.OpenCursor(this.tableName))
                        {
                            cursor.BeginEditForInsert();
                            cursor.AcceptChanges();
                            trx2.Commit(false);

                            cursor.MoveBeforeFirst();
                            cursor.MoveNext();
                            Assert.AreEqual(defaultValue, cursor.Record[NewColumnName]);
                        }
                    }
                }
                finally
                {
                    this.tableid.TableDefinition.DropColumn(NewColumnName);
                }
            }
        }
コード例 #13
0
        public void IsamCreateIndex()
        {
            const string IndexName = "new_index";

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                // Oddity: Why dcan't it be specified in the constructor?
                // KeyColumns = indexKeys,
                IndexDefinition newIndex = new IndexDefinition(IndexName)
                {
                    Flags = IndexFlags.None, Density = 100,
                };

                var indexKey = new KeyColumn(this.testColumnid.Name, true);
                newIndex.KeyColumns.Add(indexKey);

                this.tableid.TableDefinition.CreateIndex(newIndex);

                transaction.Commit(false);

                this.tableid.SetCurrentIndex(IndexName);
            }
        }
コード例 #14
0
 protected void CommitAttributeUpdate(DatastoreObject obj, string[] attributeNames, IsamTransaction transaction, bool haveChanged, bool skipMetaUpdate)
 {
     if (haveChanged)
     {
         if (!skipMetaUpdate)
         {
             // Increment the current USN
             long     currentUsn = ++this.context.DomainController.HighestCommittedUsn;
             DateTime now        = DateTime.Now;
             obj.UpdateAttributeMeta(attributeNames, currentUsn, now);
         }
         this.dataTableCursor.AcceptChanges();
         transaction.Commit();
     }
     else
     {
         // No changes have been made to the object
         this.dataTableCursor.RejectChanges();
         transaction.Abort();
     }
 }
コード例 #15
0
 protected void CommitAttributeUpdate(DatastoreObject obj, string attributeName, IsamTransaction transaction, bool hasChanged, bool skipMetaUpdate)
 {
     this.CommitAttributeUpdate(obj, new string[] { attributeName }, transaction, hasChanged, skipMetaUpdate);
 }
コード例 #16
0
        public void Setup()
        {
            this.directory    = SetupHelper.CreateRandomDirectory();
            this.databaseName = Path.Combine(this.directory, "database.edb");
            this.tableName    = "table";
            this.instance     = SetupHelper.CreateNewInstance(this.directory);

            IsamSystemParameters isamSystemParameters = this.instance.IsamSystemParameters;

            isamSystemParameters.Recovery = "off";

            this.sesid = this.instance.CreateSession();

            this.sesid.CreateDatabase(this.databaseName);
            this.sesid.AttachDatabase(this.databaseName);

            this.dbid = this.sesid.OpenDatabase(this.databaseName);

            using (IsamTransaction transaction = new IsamTransaction(this.sesid))
            {
                var tabledef = new TableDefinition(this.tableName);
                this.testColumnid = new ColumnDefinition(TestColumnName)
                {
                    Type = typeof(string),
                };

                tabledef.Columns.Add(this.testColumnid);
                tabledef.Columns.Add(new ColumnDefinition("TestColumn1")
                {
                    Type = typeof(int),
                });
                tabledef.Columns.Add(new ColumnDefinition("TestColumn2")
                {
                    Type = typeof(int),
                });

                var primaryIndex = new IndexDefinition("PrimaryIndex")
                {
                    KeyColumns =
                    {
                        new KeyColumn(
                            "TestColumn1",
                            true),
                    },
                };
                primaryIndex.Flags = IndexFlags.Primary;
                tabledef.Indices.Add(primaryIndex);

                var textIndex = new IndexDefinition("TextIndex")
                {
                    KeyColumns =
                    {
                        new KeyColumn(
                            "StringTestColumn",
                            true),
                    },
                    CultureInfo = new CultureInfo("en-CA"),
                };
                tabledef.Indices.Add(textIndex);

                this.dbid.CreateTable(tabledef);

                transaction.Commit();
            }

            this.tableid = this.dbid.OpenCursor(this.tableName);
        }
コード例 #17
0
        public void TestAllowTruncation()
        {
            const string TableName    = "truncationtable";
            const string IntColumnOne = "TestColumn1";
            const string IntColumnTwo = "TestColumn2";

            var tabledef  = new TableDefinition(TableName);
            var columndef = new ColumnDefinition(TestColumnName)
            {
                Type = typeof(string),
            };

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                tabledef.Columns.Add(columndef);
                tabledef.Columns.Add(new ColumnDefinition(IntColumnOne)
                {
                    Type = typeof(int),
                });
                tabledef.Columns.Add(new ColumnDefinition(IntColumnTwo)
                {
                    Type = typeof(int),
                });

                var primaryIndex = new IndexDefinition("PrimaryIndex")
                {
                    KeyColumns =
                    {
                        new KeyColumn(
                            IntColumnOne,
                            true),
                    },
                };
                primaryIndex.Flags = IndexFlags.AllowTruncation | IndexFlags.Primary;

                // You can't call CreateIndex on the local tabledef. You must
                // tabledef.CreateIndex(primaryIndex);
//                this.dbid.CreateTable(tabledef);
                tabledef.Indices.Add(primaryIndex);
                this.dbid.CreateTable(tabledef);
                //                using (var cursor = this.dbid.OpenCursor(TableName))
//                {
//                    cursor.TableDefinition.CreateIndex(primaryIndex);
//                }

                trx.Commit(false);
            }

            using (IsamTransaction trx = new IsamTransaction(this.sesid))
            {
                using (var tableid = this.dbid.OpenCursor(TableName))
                {
                    tableid.BeginEditForInsert();
                    tableid.EditRecord[columndef.Name] = new string('X', 4096);

                    tableid.AcceptChanges();

                    trx.Commit(false);
                }
            }

            this.dbid.DropTable(TableName);
        }