예제 #1
0
        public void CreateBasicTableColumnIndex3OnXp()
        {
            var tablecreate = new JET_TABLECREATE { szTableName = "table" };

            string directory = SetupHelper.CreateRandomDirectory();
            string database = Path.Combine(directory, "test.db");

            using (var instance = new Instance("XpCreateBasicTableColumnIndex3"))
            {
                instance.Parameters.Recovery = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, String.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        Api.JetCreateTableColumnIndex3(session, dbid, tablecreate);
                        Assert.AreNotEqual(JET_TABLEID.Nil, tablecreate.tableid);
                        Assert.AreEqual(tablecreate.cCreated, 1);
                        Api.JetCloseTable(session, tablecreate.tableid);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }
        }
예제 #2
0
파일: Cursor.cs 프로젝트: fzhenmei/study
 public Cursor(Instance instance, string databaseFileName)
 {
     m_DatabaseFileName = databaseFileName;
     Session = new Session(instance);
     Api.JetAttachDatabase(Session, databaseFileName, AttachDatabaseGrbit.None);
     Api.JetOpenDatabase(Session, databaseFileName, null, out Dbid, OpenDatabaseGrbit.None);
 }
예제 #3
0
        public void VerifyInstanceDoesNotCallJetTermWhenCreateInstanceFails()
        {
            var mocks = new MockRepository();
            var mockApi = mocks.StrictMock<IJetApi>();
            using (new ApiTestHook(mockApi))
            {
                Expect.Call(
                    mockApi.JetCreateInstance2(
                        out Arg<JET_INSTANCE>.Out(JET_INSTANCE.Nil).Dummy,
                        Arg<string>.Is.Anything,
                        Arg<string>.Is.Anything,
                        Arg<CreateInstanceGrbit>.Is.Anything))
                    .Return((int) JET_err.InvalidName);
                mocks.ReplayAll();

                try
                {
                    using (var instance = new Instance("testfail"))
                    {
                        Assert.Fail("Expected an EsentErrorException");
                    }
                }
                catch (EsentErrorException)
                {
                    // expected
                }

                mocks.VerifyAll();
            }
        }
예제 #4
0
        public EsentChainStateManager(string baseDirectory)
        {
            this.baseDirectory = baseDirectory;
            this.jetDirectory = Path.Combine(baseDirectory, "ChainState");
            this.jetDatabase = Path.Combine(this.jetDirectory, "ChainState.edb");

            this.jetInstance = new Instance(Guid.NewGuid().ToString());
            var success = false;
            try
            {
                EsentStorageManager.InitInstanceParameters(jetInstance, jetDirectory);
                this.jetInstance.Init();

                this.CreateOrOpenDatabase();

                this.cursorCache = new DisposableCache<IChainStateCursor>(1024,
                    createFunc: () => new EsentChainStateCursor(this.jetDatabase, this.jetInstance),
                    prepareAction: cursor =>
                    {
                        // rollback any open transaction before returning the cursor to the cache
                        if (cursor.InTransaction)
                            cursor.RollbackTransaction();
                    });

                success = true;
            }
            finally
            {
                if (!success)
                {
                    this.cursorCache?.Dispose();
                    this.jetInstance.Dispose();
                }
            }
        }
예제 #5
0
        public EsentBlockTxesStorage(string baseDirectory, int? index = null)
        {
            this.jetDirectory = Path.Combine(baseDirectory, "BlockTxes");
            if (index.HasValue)
                this.jetDirectory = Path.Combine(jetDirectory, index.Value.ToString());
            this.jetDatabase = Path.Combine(this.jetDirectory, "BlockTxes.edb");

            this.cursorCache = new DisposableCache<EsentBlockTxesCursor>(1024,
                createFunc: () => new EsentBlockTxesCursor(this.jetDatabase, this.jetInstance));

            this.jetInstance = new Instance(Guid.NewGuid().ToString());
            var success = false;
            try
            {
                EsentStorageManager.InitInstanceParameters(jetInstance, jetDirectory);
                this.jetInstance.Init();
                this.CreateOrOpenDatabase();
                success = true;
            }
            finally
            {
                if (!success)
                    this.jetInstance.Dispose();
            }
        }
예제 #6
0
 public void TestJetRestoreInstanceThrowsExceptionWhenSourceIsNull()
 {
     using (var instance = new Instance("RestoreNullSource"))
     {
         Api.JetRestoreInstance(instance, null, "somewhere", null);
     }
 }
        private static void CreateDatabase()
        {
            using (var databaseInstance = new Instance(DatabasePath))
            {
                InitializeDatabaseInstance(databaseInstance);

                if (File.Exists(DatabasePath))
                {
                    return;
                }

                using (var session = new Session(databaseInstance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, DatabasePath, null, out dbid, CreateDatabaseGrbit.OverwriteExisting);
                    using (var transaction = new Transaction(session))
                    {
                        JET_TABLEID tableid;
                        Api.JetCreateTable(session, dbid, "Message", 0, 100, out tableid);

                        CreateIdColumn(session, tableid);
                        CreateDateCreatedColumn(session, tableid);
                        CreateIndexes(session, tableid);

                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }

                    Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None);
                    Api.JetDetachDatabase(session, DatabasePath);
                }
            }
        }
예제 #8
0
        public void Initialize()
        {
            _instance = CreateEsentInstance();
            _primarySessionId = new Session(_instance);

            InitializeDatabaseAndTables();
        }
예제 #9
0
        /// <summary>
        /// Create a new database and return a connection to
        /// the database. The database will be overwritten if
        /// it already exists.
        /// </summary>
        /// <param name="database">The path to the database.</param>
        /// <param name="mode">Creation mode for the database.</param>
        /// <returns>A new connection to the database.</returns>
        public virtual Connection CreateDatabase(string database, DatabaseCreationMode mode)
        {
            database = Path.GetFullPath(database);

            lock (this.lockObject)
            {
                this.SetGlobalParameters();
                this.Tracer.TraceInfo("create database '{0}'", database);

                // Create the database then open it
                using (var instance = new Instance(this.GetNewInstanceName()))
                {
                    SetParametersAndInitializeInstance(database, instance);

                    using (var session = new Session(instance))
                    {
                        CreateDatabaseGrbit grbit = (DatabaseCreationMode.OverwriteExisting == mode) ?
                            CreateDatabaseGrbit.OverwriteExisting : CreateDatabaseGrbit.None;

                        JET_DBID dbid;
                        Api.JetCreateDatabase(session, database, String.Empty, out dbid, grbit);
                        Api.JetCloseDatabase(session, dbid, CloseDatabaseGrbit.None);
                        Api.JetDetachDatabase(session, database);
                    }
                }

                return this.AttachDatabase(database, DatabaseOpenMode.ReadWrite);
            }
        }
예제 #10
0
        public void Setup()
        {
            this.instance = new Instance(Guid.NewGuid().ToString(), "RetrieveColumnsPerfTest");
            this.instance.Parameters.NoInformationEvent = true;
            this.instance.Parameters.Recovery = false;
            this.instance.Init();

            this.session = new Session(this.instance);

            // turn off logging so initialization is faster
            this.columnidDict = SetupHelper.CreateTempTableWithAllColumns(this.session, TempTableGrbit.ForceMaterialization, out this.tableid);

            // Insert a record and position the tableid on it
            using (var transaction = new Transaction(this.session))
            using (var update = new Update(this.session, this.tableid, JET_prep.Insert))
            {
                Api.SetColumn(this.session, this.tableid, this.columnidDict["boolean"], this.expectedBool);
                Api.SetColumn(this.session, this.tableid, this.columnidDict["int32"], this.expectedInt32);
                Api.SetColumn(this.session, this.tableid, this.columnidDict["int64"], this.expectedInt64);
                Api.SetColumn(this.session, this.tableid, this.columnidDict["guid"], this.expectedGuid);
                Api.SetColumn(this.session, this.tableid, this.columnidDict["unicode"], this.expectedString, Encoding.Unicode);

                update.Save();
                transaction.Commit(CommitTransactionGrbit.None);
            }

            Api.TryMoveFirst(this.session, this.tableid);
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            Thread.BeginThreadAffinity();
        }
        public static void OpenDatabase(string jetDatabase, Instance jetInstance, bool readOnly)
        {
            using (var jetSession = new Session(jetInstance))
            {
                var attachGrbit = AttachDatabaseGrbit.None;
                if (readOnly)
                    attachGrbit |= AttachDatabaseGrbit.ReadOnly;
                if (EsentVersion.SupportsWindows7Features)
                    attachGrbit |= Windows7Grbits.EnableAttachDbBackgroundMaintenance;

                Api.JetAttachDatabase(jetSession, jetDatabase, attachGrbit);
                var success = false;
                try
                {
                    using (var cursor = new EsentChainStateCursor(jetDatabase, jetInstance))
                    {
                        // reset flush column
                        using (var jetUpdate = cursor.jetSession.BeginUpdate(cursor.flushTableId, JET_prep.Replace))
                        {
                            Api.SetColumn(cursor.jetSession, cursor.flushTableId, cursor.flushColumnId, 0);

                            jetUpdate.Save();
                        }
                    }

                    success = true;
                }
                finally
                {
                    if (!success)
                        Api.JetDetachDatabase(jetSession, jetDatabase);
                }
            }
        }
예제 #12
0
 public void SetAndGetAsciiSystemPath()
 {
     using (var instance = new Instance("asciisystempath"))
     {
         instance.Parameters.SystemDirectory = this.directory;
         StringAssert.Contains(instance.Parameters.SystemDirectory, this.directory);
     }
 }
예제 #13
0
파일: EsentDb.cs 프로젝트: 925coder/library
 public EsentDb(string dbname)
 {
     this.dbname = dbname;
       instance = OpenInstance(dbname);
       session = CreateSession(instance);
       dbid = CreateDatabase(dbname, instance, session);
       table = CreateTable(session, dbid, "store", new Tuple<string, JET_coltyp>[] { Tuple.Create("key", JET_coltyp.Long), Tuple.Create("data", JET_coltyp.LongText) });
 }
예제 #14
0
 public void SetAndGetAsciiLogPath()
 {
     using (var instance = new Instance("asciilogpath"))
     {
         instance.Parameters.LogFileDirectory = this.directory;
         StringAssert.Contains(instance.Parameters.LogFileDirectory, this.directory);
     }
 }
예제 #15
0
 public void InstanceCanConvertToJetInstance()
 {
     using (var instance = new Instance("converttoinstance"))
     {
         JET_INSTANCE jetinstance = instance;
         Assert.AreEqual(jetinstance, instance.JetInstance);
     }
 }
 private static void InsertMessageIntoDatabase(Guid messageId)
 {
     using (var databaseInstance = new Instance(DatabasePath))
     {
         InitializeDatabaseInstance(databaseInstance);
         InsertMessage(databaseInstance, messageId);
     }
 }
예제 #17
0
        public void each_up()
        {
            var tempDir = Path.Combine(Environment.CurrentDirectory, "with_a_dummy_instance");
            var tempPath = Path.Combine(tempDir, "test.db");
            if(Directory.Exists(tempDir)) Directory.Delete(tempDir, true);

            Instance = new Instance(Guid.NewGuid().ToString());
            Instance.Init();
        }
예제 #18
0
파일: EsentConfig.cs 프로젝트: nka1/Daytona
 public static void CreateMessageStore(string MessageTypeName, Instance instance)
 {
     using (var session = new Session(instance))
     {
         JET_DBID dbid;
         Api.JetOpenDatabase(session, DatabaseName, null, out dbid, OpenDatabaseGrbit.None);
         CreateMessageTable(MessageTypeName, session, dbid);
     }
 }
예제 #19
0
 public void Setup()
 {
     this.instance = new Instance(Guid.NewGuid().ToString(), "TemporaryTableTests");
     this.instance.Parameters.Recovery = false;
     this.instance.Parameters.NoInformationEvent = true;
     this.instance.Parameters.PageTempDBMin = SystemParameters.PageTempDBSmallest;
     this.instance.Init();
     this.session = new Session(this.instance);
 }
예제 #20
0
        /// <summary>
        /// Dump the meta-data of the table.
        /// </summary>
        /// <param name="args">Arguments for the command.</param>
        private void DumpMetaData(string[] args)
        {
            if (args.Length != 1)
            {
                throw new ArgumentException("specify the database", "args");
            }

            string database = args[0];

            using (var instance = new Instance("dumpmetadata"))
            {
                instance.Parameters.Recovery = false;
                instance.Init();

                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetAttachDatabase(session, database, AttachDatabaseGrbit.ReadOnly);
                    Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.ReadOnly);

                    foreach (string table in Api.GetTableNames(session, dbid))
                    {
                        Console.WriteLine(table);
                        foreach (ColumnInfo column in Api.GetTableColumns(session, dbid, table))
                        {
                            Console.WriteLine("\t{0}", column.Name);
                            Console.WriteLine("\t\tColtyp:     {0}", column.Coltyp);
                            Console.WriteLine("\t\tColumnid:   {0}", column.Columnid);
                            if (JET_coltyp.LongText == column.Coltyp || JET_coltyp.Text == column.Coltyp)
                            {
                                Console.WriteLine("\t\tCode page:  {0}", column.Cp);
                            }

                            Console.WriteLine("\t\tMax length: {0}", column.MaxLength);
                            Console.WriteLine("\t\tGrbit:      {0}", column.Grbit);
                        }

                        foreach (IndexInfo index in Api.GetTableIndexes(session, dbid, table))
                        {
                            Console.WriteLine("\t{0}", index.Name);
                            Console.WriteLine("\t\tGrbit:          {0}", index.Grbit);
                            Console.WriteLine("\t\tCultureInfo:    {0}", index.CultureInfo);
                            Console.WriteLine("\t\tCompareOptions: {0}", index.CompareOptions);

                            foreach (IndexSegment segment in index.IndexSegments)
                            {
                                Console.WriteLine("\t\t\t{0}", segment.ColumnName);
                                Console.WriteLine("\t\t\t\tColtyp:      {0}", segment.Coltyp);
                                Console.WriteLine("\t\t\t\tIsAscending: {0}", segment.IsAscending);
                                Console.WriteLine("\t\t\t\tIsASCII:     {0}", segment.IsASCII);
                            }
                        }
                    }
                }
            }
        }
        public override void Initialise()
        {
            instance = new Instance(string.Empty);
            instance.Parameters.MaxVerPages = 1024;
            instance.Init();

            using (var session = new Session(instance))
                if (!fileSystem.FileExists(GetDatabaseFileName()))
                    CreateDatabaseAndTables(session, GetDatabaseFileName());
        }
예제 #22
0
파일: HowDoI.cs 프로젝트: VirtueMe/ravendb
 public void Setup()
 {
     Cleanup.DeleteDirectoryWithRetry(TestDirectory);
     Directory.CreateDirectory(TestDirectory);
     this.testInstance = new Instance("HowDoI");
     SetupHelper.SetLightweightConfiguration(this.testInstance);
     this.testInstance.Init();
     this.testSession = new Session(this.testInstance);
     Api.JetCreateDatabase(this.testSession, TestDatabase, null, out this.testDbid, CreateDatabaseGrbit.OverwriteExisting);
 }
        private static Guid InsertMessageIntoDatabase()
        {
            var messageId = Guid.NewGuid();

            using (var databaseInstance = new Instance(DatabasePath))
            {
                InitializeDatabaseInstance(databaseInstance);
                Message(databaseInstance, messageId);
            }
            return messageId;
        }
예제 #24
0
        public void Setup()
        {
            this.instance = new Instance(Guid.NewGuid().ToString(), "TempTableFixture");
            this.instance.Parameters.Recovery = false;
            this.instance.Parameters.PageTempDBMin = SystemParameters.PageTempDBSmallest;
            this.instance.Parameters.NoInformationEvent = true;
            this.instance.Init();

            this.session = new Session(this.instance);
            this.columnDict = SetupHelper.CreateTempTableWithAllColumns(this.session, TempTableGrbit.None, out this.tableid);
        }
예제 #25
0
 private void TimerCallback(object state)
 {
     lock (sessionLock)
     {
         if (sessionCount <= 0 && currentInstance != null)
         {
             sessionCount = 0;
             currentInstance.Dispose();
             currentInstance = null;
         }
     }
 }
예제 #26
0
 /// <summary>
 /// Получить экземпляр.
 /// </summary>
 public IEsentInstance GetInstance()
 {
     lock (sessionLock)
     {
         if (currentInstance == null)
         {
             currentInstance = CreateInstance();
         }
         sessionCount++;
         return new EsentInstance(OnDispose, currentInstance);
     }
 }
예제 #27
0
        public void SetAndGetUnicodeSystemPath()
        {
            if (!EsentVersion.SupportsUnicodePaths)
            {
                return;
            }

            using (var instance = new Instance("unicodesystempath"))
            {
                instance.Parameters.SystemDirectory = this.directory;
                StringAssert.Contains(instance.Parameters.SystemDirectory, this.directory);
            }
        }
예제 #28
0
파일: EsentDb.cs 프로젝트: 925coder/library
        private JET_DBID CreateDatabase(string database, Instance instance, Session session)
        {
            JET_DBID dbid;
              if (File.Exists(database))
              {
            Api.JetAttachDatabase(session, database, AttachDatabaseGrbit.None);
            Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.None);
              }
              else
            Api.JetCreateDatabase(session, database, null, out dbid, CreateDatabaseGrbit.None);

              return dbid;
        }
예제 #29
0
파일: EsentConfig.cs 프로젝트: nka1/Daytona
 /// <summary>
 /// Creates the message store.
 /// </summary>
 /// <param name="database">The database.</param>
 public static void CreateDatabase()
 {
     using (var instance = new Instance("createdatabase"))
     {
         instance.Parameters.CircularLog = true;
         instance.Init();
         using (var session = new Session(instance))
         {
             JET_DBID dbid;
             Api.JetCreateDatabase(session, DatabaseName, null, out dbid, CreateDatabaseGrbit.OverwriteExisting);
         }
     }
 }
예제 #30
0
        public void IinsertAndReadOneMessage()
        {
            TestHelper.CreateDatabase("EsentTestsDummy");
            using (var instance = new Instance("MyInstanceName"))
            {
                instance.Parameters.CircularLog = true;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetAttachDatabase(session, DatabaseName, AttachDatabaseGrbit.None);
                    Api.JetOpenDatabase(session, DatabaseName, null, out dbid, OpenDatabaseGrbit.None);

                    JET_TABLEID tableid;

                    if (Api.TryOpenTable(session, dbid, "EsentTestsDummymessages", OpenTableGrbit.None, out tableid))
                    {
                        IDictionary<string, JET_COLUMNID> columnids = Api.GetColumnDictionary(session, tableid);
                        JET_COLUMNID columnidMessage = columnids["message"];
                        JET_COLUMNID columnidMetaData = columnids["metadata"];

                        Assert.IsInstanceOfType(columnidMessage, typeof(JET_COLUMNID));
                        Assert.IsInstanceOfType(columnidMetaData, typeof(JET_COLUMNID));
                        AddMessage(session, tableid, ref columnidMessage, ref columnidMetaData);

                        var results = TestHelper.DumpByIndex(session, tableid, null, columnids);
                        Assert.IsNotNull(results);
                        Assert.IsTrue(results.Count == 1);
                        Assert.AreEqual("Hi this is the message", results[0]);
                    }
                    else
                    {
                        using (var table = new Table(session, dbid, "EsentTestsDummymessages", OpenTableGrbit.None))
                        {
                            IDictionary<string, JET_COLUMNID> columnids = Api.GetColumnDictionary(session, table);
                            JET_COLUMNID columnidMessage = columnids["message"];
                            JET_COLUMNID columnidMetaData = columnids["metadata"];

                            Assert.IsInstanceOfType(columnidMessage, typeof(JET_COLUMNID));
                            Assert.IsInstanceOfType(columnidMetaData, typeof(JET_COLUMNID));
                            AddMessage(session, table, ref columnidMessage, ref columnidMetaData);

                            var results = TestHelper.DumpByIndex(session, table, null, columnids);
                            Assert.IsNotNull(results);
                            Assert.IsTrue(results.Count == 1);
                            Assert.AreEqual("Hi this is the message", results[0]);
                        }
                    }
                }
            }
        }
예제 #31
0
 public Writer(Instance instance)
 {
     this.instance = instance;
 }