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); } } } }
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); }
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(); } }
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(); } } }
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(); } }
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); } } }
public void Initialize() { _instance = CreateEsentInstance(); _primarySessionId = new Session(_instance); InitializeDatabaseAndTables(); }
/// <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); } }
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); } } }
public void SetAndGetAsciiSystemPath() { using (var instance = new Instance("asciisystempath")) { instance.Parameters.SystemDirectory = this.directory; StringAssert.Contains(instance.Parameters.SystemDirectory, this.directory); } }
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) }); }
public void SetAndGetAsciiLogPath() { using (var instance = new Instance("asciilogpath")) { instance.Parameters.LogFileDirectory = this.directory; StringAssert.Contains(instance.Parameters.LogFileDirectory, this.directory); } }
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); } }
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(); }
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); } }
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); }
/// <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()); }
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; }
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); }
private void TimerCallback(object state) { lock (sessionLock) { if (sessionCount <= 0 && currentInstance != null) { sessionCount = 0; currentInstance.Dispose(); currentInstance = null; } } }
/// <summary> /// Получить экземпляр. /// </summary> public IEsentInstance GetInstance() { lock (sessionLock) { if (currentInstance == null) { currentInstance = CreateInstance(); } sessionCount++; return new EsentInstance(OnDispose, currentInstance); } }
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); } }
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; }
/// <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); } } }
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]); } } } } }
public Writer(Instance instance) { this.instance = instance; }