Exemplo n.º 1
0
        /// <summary>
        /// Gets the current number of nested levels of transactions begun. A value of zero indicates that
        /// the session is not currently in a transaction. This parameter is read-only.
        /// </summary>
        /// <param name="session">The <see cref="Session"/> to query.</param>
        /// <returns>The current transaction level of the specified database session.</returns>
        public static int GetTransactionLevel(this Session session)
        {
            int output;

            Windows8Api.JetGetSessionParameter(session.JetSesid, Windows10Sesparam.TransactionLevel, out output);
            return(output);
        }
Exemplo n.º 2
0
        public void LazyCommitWithSmallerDuration()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 2);
            this.InsertRecord(this.tableid, 1);
            this.InsertRecord(this.tableid, 3);
            JET_COMMIT_ID commitId1;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.LazyFlush, new TimeSpan(0, 0, 5), out commitId1);
            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 4);
            this.InsertRecord(this.tableid, 5);
            JET_COMMIT_ID commitId2;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.LazyFlush, new TimeSpan(0, 0, 2), out commitId2);
            DateTime commitTime = DateTime.Now;

            Assert.IsTrue(commitId2 > commitId1);
            EseInteropTestHelper.ThreadSleep(2500);
            TimeSpan timeToFlush = this.lastCallbackTime - commitTime;

            Assert.IsTrue(commitId2 < this.lastCommitIdFlushed);
            Assert.IsTrue(timeToFlush.TotalMilliseconds < 2500);
        }
        public void JetCreateIndex4()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);

            const string IndexName        = "another_index";
            const string IndexDescription = "-TestColumn\0\0";

            var indexcreate = new JET_INDEXCREATE
            {
                szIndexName = IndexName,
                szKey       = IndexDescription,
                cbKey       = IndexDescription.Length,
                grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                ulDensity   = 100,
            };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            Api.JetSetCurrentIndex(this.sesid, this.tableid, IndexName);
        }
Exemplo n.º 4
0
        public void VerifyEsentErrorInformationIsCorrect()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            JET_ERRINFOBASIC errinfobasic;

            // OutOfCursors is a Memory error.
            // JET_errcatError -> JET_errcatOperation -> JET_errcatResource -> JET_errcatMemory
            Windows8Api.JetGetErrorInfo(JET_err.OutOfCursors, out errinfobasic);

            Assert.AreEqual(JET_ERRCAT.Memory, errinfobasic.errcat);
            Assert.AreEqual(JET_ERRCAT.Error, (JET_ERRCAT)errinfobasic.rgCategoricalHierarchy[0]);
            Assert.AreEqual(JET_ERRCAT.Operation, errinfobasic.rgCategoricalHierarchy[1]);
            Assert.AreEqual(JET_ERRCAT.Resource, errinfobasic.rgCategoricalHierarchy[2]);
            Assert.AreEqual(JET_ERRCAT.Memory, errinfobasic.rgCategoricalHierarchy[3]);
            Assert.AreEqual(JET_ERRCAT.Unknown, errinfobasic.rgCategoricalHierarchy[4]);
            Assert.AreEqual(JET_ERRCAT.Unknown, errinfobasic.rgCategoricalHierarchy[5]);
            Assert.AreEqual(JET_ERRCAT.Unknown, errinfobasic.rgCategoricalHierarchy[6]);
            Assert.AreEqual(JET_ERRCAT.Unknown, errinfobasic.rgCategoricalHierarchy[7]);

            Assert.AreEqual(string.Empty, errinfobasic.rgszSourceFile);
            Assert.AreEqual(0, errinfobasic.lSourceLine);
            Assert.AreEqual(JET_err.OutOfCursors, errinfobasic.errValue);
        }
Exemplo n.º 5
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.table     = "table";
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, string.Empty, string.Empty);
            Api.JetCreateDatabase(this.sesid, this.database, string.Empty, out this.dbid, CreateDatabaseGrbit.None);
            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTable(this.sesid, this.dbid, this.table, 0, 100, out this.tableid);

            JET_COLUMNID ignored;
            var          columndef = new JET_COLUMNDEF {
                coltyp = JET_coltyp.Text, cp = JET_CP.Unicode
            };

            Api.JetAddColumn(this.sesid, this.tableid, "C1", columndef, null, 0, out ignored);
            Api.JetAddColumn(this.sesid, this.tableid, "C2", columndef, null, 0, out ignored);
            Api.JetAddColumn(this.sesid, this.tableid, "C3", columndef, null, 0, out ignored);

            Api.JetCreateIndex(this.sesid, this.tableid, "Primary", CreateIndexGrbit.IndexPrimary, "+C1\0\0", 5, 100);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            JET_INDEXCREATE[] indexcreates = new[]
            {
                new JET_INDEXCREATE {
                    szIndexName = "Index2", cbKey = 5, szKey = "+C2\0\0"
                },
                new JET_INDEXCREATE {
                    szIndexName = "Index3", cbKey = 5, szKey = "+C3\0\0", cbVarSegMac = 100
                },
            };
            Api.JetCreateIndex2(this.sesid, this.tableid, indexcreates, indexcreates.Length);

            if (EsentVersion.SupportsWindows8Features)
            {
                var unicode = new JET_UNICODEINDEX()
                {
                    szLocaleName = "pt-br",
                    dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
                };

                var indexcreate = new JET_INDEXCREATE
                {
                    szIndexName = "win8BrazilIndex",
                    szKey       = "+C2\0\0",
                    cbKey       = 5,
                    pidxUnicode = unicode,
                    grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                    ulDensity   = 100,
                };
                Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            }

            Api.JetCloseTable(this.sesid, this.tableid);
            Api.JetOpenTable(this.sesid, this.dbid, this.table, null, 0, OpenTableGrbit.None, out this.tableid);
        }
        public void JetCreateIndex4UnicodeIndex2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);

            const string IndexName        = "another_index";
            const string IndexDescription = "-TestColumn\0\0";
            const string LocaleName       = "en-US";

            var unicode = new JET_UNICODEINDEX()
            {
                szLocaleName = LocaleName,
                dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
            };

            var indexcreate = new JET_INDEXCREATE
            {
                szIndexName = IndexName,
                szKey       = IndexDescription,
                cbKey       = IndexDescription.Length,
                pidxUnicode = unicode,
                grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                ulDensity   = 100,
            };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            Api.JetSetCurrentIndex(this.sesid, this.tableid, IndexName);
        }
Exemplo n.º 7
0
        /// <summary>
        /// A 32-bit integer ID that is logged in traces and can be used by clients to
        /// correlate ESE actions with their activity.
        /// </summary>
        /// <param name="session">The <see cref="Session"/> to query.</param>
        /// <returns>The corrlation identifer of the specified database session.</returns>
        public static int GetCorrelationID(this Session session)
        {
            int output;

            Windows8Api.JetGetSessionParameter(session.JetSesid, Windows10Sesparam.CorrelationID, out output);
            return(output);
        }
        public void CreateResizeAndTrimDatabase()
        {
            if (!EsentVersion.SupportsWindows81Features)
            {
                return;
            }

            string       dir      = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);

            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);

            InstanceParameters instanceParameters = new InstanceParameters(instance);

            instanceParameters.EnableShrinkDatabase = ShrinkDatabaseGrbit.On;
            Api.JetInit(ref instance);
            try
            {
                string database = Path.Combine(dir, "CreateAndResizeDatabase.db");

                JET_SESID sesid;
                JET_DBID  dbid;
                Api.JetBeginSession(instance, out sesid, string.Empty, string.Empty);

                Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.DbExtensionSize, 256, null);
                Api.JetCreateDatabase(sesid, database, string.Empty, out dbid, CreateDatabaseGrbit.None);

                Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.DbExtensionSize, 1, null);

                int databaseSpaceOwned;
                Api.JetGetDatabaseInfo(sesid, dbid, out databaseSpaceOwned, JET_DbInfo.SpaceOwned);

                // We have to take into account the reserved pages in the database as per the API to get the actual
                // space.
                databaseSpaceOwned += ReservedPages;

                int actualPages;
                Windows8Api.JetResizeDatabase(sesid, dbid, databaseSpaceOwned + 100, out actualPages, ResizeDatabaseGrbit.None);
                EseInteropTestHelper.ConsoleWriteLine("actualPages is {0}.", actualPages);

                Assert.IsTrue(actualPages >= databaseSpaceOwned + 100, "Database didn't grow enough!");

                int actualPagesAfterTrim = 0;
                Windows8Api.JetResizeDatabase(sesid, dbid, 0, out actualPagesAfterTrim, ResizeDatabaseGrbit.None);
                EseInteropTestHelper.ConsoleWriteLine("actualPagesAfterTrim is {0}.", actualPagesAfterTrim);

                Assert.IsTrue(actualPagesAfterTrim < actualPages, "Database didn't shrink!");

                int databaseSizeOnDiskInPages;
                Api.JetGetDatabaseInfo(sesid, dbid, out databaseSizeOnDiskInPages, Windows81DbInfo.FilesizeOnDisk);
                EseInteropTestHelper.ConsoleWriteLine("databaseSizeOnDiskInPages is {0}.", databaseSizeOnDiskInPages);
                Assert.AreEqual(actualPagesAfterTrim, databaseSizeOnDiskInPages);
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
        public void CreateTwoIndexesUsingJetCreateIndex4()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            JET_TABLEID tableToIndex;

            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTable(this.sesid, this.dbid, "tabletoindex", 1, 100, out tableToIndex);

            var columndef = new JET_COLUMNDEF()
            {
                cp     = JET_CP.Unicode,
                coltyp = JET_coltyp.LongText,
            };

            Api.JetAddColumn(this.sesid, tableToIndex, "column", columndef, null, 0, out this.testColumnid);

            Api.JetCloseTable(this.sesid, tableToIndex);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            Api.JetOpenTable(this.sesid, this.dbid, "tabletoindex", null, 0, OpenTableGrbit.DenyRead, out tableToIndex);
            const string Index1Name        = "firstIndex";
            const string Index1Description = "-column\0\0";

            const string Index2Name        = "secondIndex";
            const string Index2Description = "+column\0\0";

            var indexcreates = new[]
            {
                new JET_INDEXCREATE
                {
                    szIndexName = Index1Name,
                    szKey       = Index1Description,
                    cbKey       = Index1Description.Length,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 100,
                },
                new JET_INDEXCREATE
                {
                    szIndexName = Index2Name,
                    szKey       = Index2Description,
                    cbKey       = Index2Description.Length,
                    grbit       = CreateIndexGrbit.None,
                    ulDensity   = 100,
                },
            };

            Windows8Api.JetCreateIndex4(this.sesid, tableToIndex, indexcreates, indexcreates.Length);

            Api.JetSetCurrentIndex(this.sesid, tableToIndex, Index1Name);
            Api.JetSetCurrentIndex(this.sesid, tableToIndex, Index2Name);
            Api.JetSetCurrentIndex(this.sesid, tableToIndex, null);
            Api.JetCloseTable(this.sesid, tableToIndex);
        }
        public void VerifySetSessionParamCommitDefault()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Windows8Api.JetSetSessionParameter(this.session, JET_sesparam.CommitDefault, (int)CommitTransactionGrbit.LazyFlush);
        }
        public void JetCreateIndex4ThrowsExceptionWhenIndexcreatesAreNull()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                throw new ArgumentNullException();
            }

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, null, 0);
        }
Exemplo n.º 12
0
 public void CheckStopServiceInstance2OnWIndows7ThrowsException()
 {
     try
     {
         Windows8Api.JetStopServiceInstance2(JET_INSTANCE.Nil, (StopServiceGrbit)0x1);
         Assert.Fail("JetStopServiceInstance2 should have thrown UnsupportedApiException on Win7.");
     }
     catch (InvalidOperationException)
     {
     }
 }
Exemplo n.º 13
0
        public void SortDataDifferentLocalesWithJetOpenTemporaryTable2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            CultureInfo cultureInfo = new CultureInfo("es-ES_tradnl");
            string      localeName  = cultureInfo.CompareInfo.Name;

            Assert.AreEqual("es-ES_tradnl", localeName);

            var columns = new[]
            {
                new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Text, cp = JET_CP.Unicode, grbit = ColumndefGrbit.TTKey
                },
            };
            var columnids = new JET_COLUMNID[columns.Length];

            var idxunicode = new JET_UNICODEINDEX
            {
                szLocaleName = localeName,
            };

            var opentemporarytable = new JET_OPENTEMPORARYTABLE
            {
                cbKeyMost    = SystemParameters.KeyMost,
                ccolumn      = columns.Length,
                grbit        = TempTableGrbit.Scrollable,
                pidxunicode  = idxunicode,
                prgcolumndef = columns,
                prgcolumnid  = columnids,
            };

            Windows8Api.JetOpenTemporaryTable2(this.sesid, opentemporarytable);

            // Note that es-ES_tradnl sorts differently than English.
            var data = new[] { "canary", "cocoa", "chicken", "bad!" };

            foreach (string s in data)
            {
                using (var update = new Update(this.sesid, opentemporarytable.tableid, JET_prep.Insert))
                {
                    Api.SetColumn(this.sesid, opentemporarytable.tableid, columnids[0], s, Encoding.Unicode);
                    update.Save();
                }
            }

            Array.Sort(data, new CultureInfo(localeName).CompareInfo.Compare);

            CollectionAssert.AreEqual(data, this.RetrieveAllRecordsAsString(opentemporarytable.tableid, columnids[0]).ToArray());
            Api.JetCloseTable(this.sesid, opentemporarytable.tableid);
        }
        public void JetCreateIndex4ThrowsExceptionWhenNumIndexcreatesIsTooLong()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                throw new ArgumentOutOfRangeException();
            }

            var indexcreates = new[] { new JET_INDEXCREATE() };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, indexcreates, indexcreates.Length + 1);
        }
        public void VerifyJetResizeDatabaseThrowsExceptionWhenDesiredPagesIsNegative()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                throw new ArgumentOutOfRangeException();
            }

            int ignored;

            Windows8Api.JetResizeDatabase(this.sesid, this.dbid, -1, out ignored, ResizeDatabaseGrbit.None);
        }
Exemplo n.º 16
0
        public void SortDataCaseSensitiveWithJetOpenTemporaryTable3()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            const string LocaleName = "pt-BR";

            var columns = new[]
            {
                new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Text, cp = JET_CP.Unicode, grbit = ColumndefGrbit.TTKey
                },
            };
            var columnids = new JET_COLUMNID[columns.Length];

            var idxunicode = new JET_UNICODEINDEX
            {
                dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
                szLocaleName = LocaleName,
            };

            var opentemporarytable = new JET_OPENTEMPORARYTABLE
            {
                cbKeyMost    = SystemParameters.KeyMost,
                ccolumn      = columns.Length,
                grbit        = TempTableGrbit.Scrollable,
                pidxunicode  = idxunicode,
                prgcolumndef = columns,
                prgcolumnid  = columnids,
            };

            Windows8Api.JetOpenTemporaryTable2(this.session, opentemporarytable);

            var data = new[] { "g", "a", "A", "aa", "x", "b", "X" };

            foreach (string s in data)
            {
                using (var update = new Update(this.session, opentemporarytable.tableid, JET_prep.Insert))
                {
                    Api.SetColumn(this.session, opentemporarytable.tableid, columnids[0], s, Encoding.Unicode);
                    update.Save();
                }
            }

            Array.Sort(data, new CultureInfo(LocaleName).CompareInfo.Compare);
            CollectionAssert.AreEqual(
                data, this.RetrieveAllRecordsAsString(opentemporarytable.tableid, columnids[0]).ToArray());
            Api.JetCloseTable(this.session, opentemporarytable.tableid);
        }
Exemplo n.º 17
0
        public void Defragment()
        {
            //int passes = -1, seconds = -1;
            //Api.JetDefragment(defragCursor.jetSession, defragCursor.chainStateDbId, "Chain", ref passes, ref seconds, DefragGrbit.BatchStart);
            //Api.JetDefragment(defragCursor.jetSession, defragCursor.chainStateDbId, "ChainState", ref passes, ref seconds, DefragGrbit.BatchStart);

            if (EsentVersion.SupportsWindows81Features)
            {
                this.logger.Info("Begin shrinking chain state database");

                int actualPages;
                Windows8Api.JetResizeDatabase(this.jetSession, this.chainStateDbId, 0, out actualPages, Windows81Grbits.OnlyShrink);

                this.logger.Info("Finished shrinking chain state database: {0:#,##0} MB".Format2((float)actualPages * SystemParameters.DatabasePageSize / 1.MILLION()));
            }
        }
Exemplo n.º 18
0
        public void TestJetStopServiceInstance2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            using (var instance = new Instance("TestJetStopServiceInstance"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();
                Windows8Api.JetStopServiceInstance2(instance, StopServiceGrbit.All);
            }
        }
Exemplo n.º 19
0
        public void CommitIdFromCommitTransaction2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 2);
            this.InsertRecord(this.tableid, 1);
            this.InsertRecord(this.tableid, 3);
            JET_COMMIT_ID commitId;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.None, new TimeSpan(0), out commitId);
            Assert.IsTrue(commitId > null);
            Assert.IsTrue(commitId < this.lastCommitIdFlushed);
        }
Exemplo n.º 20
0
        public void JetCreateIndex4SpaceHintsUnicodeIndex2()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);

            const string IndexName        = "another_index";
            const string IndexDescription = "-TestColumn\0\0";
            const string LocaleName       = "en-US";

            var spacehintsIndex = new JET_SPACEHINTS()
            {
                ulInitialDensity = 33,
                cbInitial        = 4096,
                grbit            = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward,
                ulMaintDensity   = 44,
                ulGrowth         = 144,
                cbMinExtent      = 1024 * 1024,
                cbMaxExtent      = 3 * 1024 * 1024,
            };

            var unicode = new JET_UNICODEINDEX()
            {
                szLocaleName = LocaleName,
                dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
            };

            var indexcreate = new JET_INDEXCREATE
            {
                szIndexName = IndexName,
                szKey       = IndexDescription,
                cbKey       = IndexDescription.Length,
                pidxUnicode = unicode,
                grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                pSpaceHints = spacehintsIndex,
            };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            Api.JetSetCurrentIndex(this.sesid, this.tableid, IndexName);
        }
Exemplo n.º 21
0
        public void VerifyJetIndexInfoLocaleName()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);

            const string IndexName        = "localizedIndex";
            const string IndexDescription = "-TestColumn\0\0";
            const string LocaleName       = "pt-bR";

            var unicode = new JET_UNICODEINDEX()
            {
                szLocaleName = LocaleName,
                dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
            };

            var indexcreate = new JET_INDEXCREATE
            {
                szIndexName = IndexName,
                szKey       = IndexDescription,
                cbKey       = IndexDescription.Length,
                pidxUnicode = unicode,
                grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                ulDensity   = 100,
            };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            string localeNameOut;

            Api.JetGetIndexInfo(this.sesid, this.dbid, this.table, IndexName, out localeNameOut, Windows8IdxInfo.LocaleName);
            Assert.IsNotNull(localeNameOut);
            Assert.AreEqual(LocaleName, localeNameOut, true);

            localeNameOut = null;
            Api.JetGetTableIndexInfo(this.sesid, this.tableid, IndexName, out localeNameOut, Windows8IdxInfo.LocaleName);
            Assert.IsNotNull(localeNameOut);
            Assert.AreEqual(LocaleName, localeNameOut, true);

            Api.JetSetCurrentIndex(this.sesid, this.tableid, IndexName);
        }
        public void VerifySetSessionParamCommitGenericContextSimple()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            int cb = 3;

            byte[] trxContext = new byte[cb];
            trxContext[0] = 0x23;
            trxContext[1] = 0x32;
            trxContext[2] = 0x33;

            Windows8Api.JetSetSessionParameter(this.session, JET_sesparam.CommitGenericContext, trxContext, cb);

            this.PulseUpdateTrx();
        }
Exemplo n.º 23
0
        public void Defragment()
        {
            using (SetSessionContext())
            {
                //int passes = int.MaxValue, seconds = int.MaxValue;
                //Api.JetDefragment(this.jetSession, this.chainStateDbId, "", ref passes, ref seconds, DefragGrbit.BatchStart);

                if (EsentVersion.SupportsWindows81Features)
                {
                    logger.Info("Begin shrinking chain state database");

                    int actualPages;
                    Windows8Api.JetResizeDatabase(this.jetSession, this.chainStateDbId, 0, out actualPages, Windows81Grbits.OnlyShrink);

                    logger.Info($"Finished shrinking chain state database: {(float)actualPages * SystemParameters.DatabasePageSize / 1.MILLION():N0} MB");
                }
            }
        }
        public void JetCreateIndex4ThrowsExceptionWhenIndexNameIsNull()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                throw new ArgumentNullException();
            }

            const string Key          = "+column\0";
            var          indexcreates = new[]
            {
                new JET_INDEXCREATE
                {
                    cbKey = Key.Length,
                    szKey = Key,
                },
            };

            Windows8Api.JetCreateIndex4(this.sesid, this.tableid, indexcreates, indexcreates.Length);
        }
Exemplo n.º 25
0
        public void Defragment()
        {
            using (var handle = this.cursorCache.TakeItem())
            {
                var cursor = handle.Item;

                //int passes = int.MaxValue, seconds = int.MaxValue;
                //Api.JetDefragment(cursor.jetSession, cursor.blockDbId, "", ref passes, ref seconds, DefragGrbit.BatchStart);

                if (EsentVersion.SupportsWindows81Features)
                {
                    logger.Info("Begin shrinking block database");

                    int actualPages;
                    Windows8Api.JetResizeDatabase(cursor.jetSession, cursor.blockDbId, 0, out actualPages, Windows81Grbits.OnlyShrink);

                    logger.Info($"Finished shrinking block database: {((float)actualPages * SystemParameters.DatabasePageSize / 1.MILLION()):N0} MB");
                }
            }
        }
Exemplo n.º 26
0
        public void TestJetStopServiceInstance2StopsSubsequentOperations()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            using (var instance = new Instance("TestJetStopServiceInstance"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();

                StopServiceGrbit[] resumableGrbits = new StopServiceGrbit[]
                {
                    StopServiceGrbit.QuiesceCaches,
                    StopServiceGrbit.BackgroundUserTasks,
                };

                foreach (StopServiceGrbit grbit in resumableGrbits)
                {
                    JET_SESID sesid;
                    Windows8Api.JetStopServiceInstance2(instance, grbit);
                    try
                    {
                        Api.JetBeginSession(instance, out sesid, null, null);
                        Api.JetEndSession(sesid, EndSessionGrbit.None);
                    }
                    catch (EsentClientRequestToStopJetServiceException)
                    {
                        Assert.Fail("JetBeginSession should not have thrown an exception when the service is stopped with {0}.", grbit);
                    }

                    // Resuming the service should allow BeginSession to work.
                    Windows8Api.JetStopServiceInstance2(instance, StopServiceGrbit.Resume);
                    Api.JetBeginSession(instance, out sesid, null, null);
                    Api.JetEndSession(sesid, EndSessionGrbit.None);
                }
            }
        }
Exemplo n.º 27
0
        public void NavigationSeekWithFiltering()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            JET_TABLECREATE tc = this.CreateTable(this.tableName);

            this.InsertRecord(tc.tableid, 1, 300);
            this.InsertRecord(tc.tableid, 2, 100);
            this.InsertRecord(tc.tableid, 3, 200);

            JET_INDEX_COLUMN filter = this.CreateFilter(this.columnIdData1, 250, JetRelop.LessThanOrEqual);

            JET_INDEX_COLUMN[] filters = { filter };

            Windows8Api.JetSetCursorFilter(this.sesId, tc.tableid, filters, CursorFilterGrbit.None);
            this.SeekToRecordClustered(tc.tableid, 1, SeekGrbit.SeekGE);
            this.VerifyCurrentRecord(tc.tableid, 2, 100);
        }
Exemplo n.º 28
0
        public void LazyCommitFollowedByReadOnlyCanCommitLazy()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 1);
            JET_COMMIT_ID commitId;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.LazyFlush, new TimeSpan(0, 0, 0), out commitId);

            Api.JetBeginTransaction(this.sesid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None);

            Assert.IsTrue(commitId >= this.lastCommitIdFlushed);

            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.WaitLastLevel0Commit);

            Assert.IsTrue(commitId < this.lastCommitIdFlushed);
        }
Exemplo n.º 29
0
        public void CreateBasicTableColumnIndex4OnWindows7ThrowsException()
        {
            if (!EsentVersion.SupportsWindows7Features)
            {
                return;
            }

            var tablecreate = new JET_TABLECREATE {
                szTableName = "table"
            };

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

            using (var instance = new Instance("Windows7CreateBasicTableColumnIndex4"))
            {
                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))
                    {
                        try
                        {
                            Windows8Api.JetCreateTableColumnIndex4(session, dbid, tablecreate);
                            Assert.Fail("JetCreateTableColumnIndex4() is supposed to throw an exception on Win7.");
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Moves the cursor.
 /// </summary>
 /// <param name="tableId">The table id.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="filters">Filters to apply to the move.</param>
 /// <param name="exTypeExpected">The ex type expected.</param>
 private void MoveCursor(JET_TABLEID tableId, JET_Move offset, JET_INDEX_COLUMN[] filters, Type exTypeExpected)
 {
     try
     {
         Windows8Api.JetSetCursorFilter(this.sesId, tableId, filters, CursorFilterGrbit.None);
         Api.JetMove(this.sesId, tableId, offset, MoveGrbit.None);
         if (exTypeExpected != null)
         {
             Assert.Fail("Should have thrown {0}", exTypeExpected);
         }
     }
     catch (EsentException ex)
     {
         if (exTypeExpected != null)
         {
             Assert.AreEqual <Type>(exTypeExpected, ex.GetType());
         }
         else
         {
             throw;
         }
     }
 }