public void NavigationClearFilter() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 1); this.InsertRecord(tc.tableid, 2); this.InsertRecord(tc.tableid, 3); this.InsertRecord(tc.tableid, 5); this.InsertRecord(tc.tableid, 6); JET_INDEX_COLUMN filter = this.CreateFilter(this.columnIdKey, 1, JetRelop.BitmaskEqualsZero); JET_INDEX_COLUMN[] filters = { filter }; this.MoveCursor(tc.tableid, JET_Move.First, filters); this.VerifyCurrentRecord(tc.tableid, 2); this.MoveCursor(tc.tableid, JET_Move.Next, null); this.VerifyCurrentRecord(tc.tableid, 3); this.MoveCursor(tc.tableid, JET_Move.Next, filters); this.VerifyCurrentRecord(tc.tableid, 6); }
/// <summary> /// Creates a table, adds columns, and indices on that table. /// <seealso cref="Api.JetCreateTableColumnIndex3"/> /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to which to add the new table.</param> /// <param name="tablecreate">Object describing the table to create.</param> /// <seealso cref="Api.JetCreateTableColumnIndex3"/> public static void JetCreateTableColumnIndex4( JET_SESID sesid, JET_DBID dbid, JET_TABLECREATE tablecreate) { Api.Check(Api.Impl.JetCreateTableColumnIndex4(sesid, dbid, tablecreate)); }
public void TestSetup() { if (!EsentVersion.SupportsWindows8Features) { return; } this.directory = SetupHelper.CreateRandomDirectory(); this.database = Path.Combine(this.directory, "database.edb"); this.instance = SetupHelper.CreateNewInstance(this.directory); //// Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, UnpublishedParam.EnablePeriodicShrinkDatabase, 0, null); this.callback = new DurableCommitCallback(this.instance, this.TestCallback); 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.JetCloseDatabase(this.sesid, this.dbid, CloseDatabaseGrbit.None); Api.JetOpenDatabase(this.sesid, this.database, null, out this.dbid, OpenDatabaseGrbit.None); Api.JetBeginTransaction(this.sesid); JET_TABLECREATE tc = this.CreateTable(this.tableName); Api.JetCloseTable(this.sesid, tc.tableid); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None); Api.JetOpenTable(this.sesid, this.dbid, this.tableName, null, 0, OpenTableGrbit.None, out this.tableid); }
public void Setup() { JET_TABLEID tableidTemp = new JET_TABLEID() { Value = (IntPtr)456, }; this.managed = new JET_TABLECREATE() { szTableName = "table7", szTemplateTableName = "parentTable", ulPages = 7, ulDensity = 62, rgcolumncreate = null, cColumns = 0, rgindexcreate = null, cIndexes = 0, szCallback = "module!FunkyFunction", cbtyp = JET_cbtyp.AfterReplace, grbit = CreateTableColumnIndexGrbit.FixedDDL, pSeqSpacehints = null, pLVSpacehints = null, cbSeparateLV = 0x999, tableid = tableidTemp, cCreated = 2, }; this.native = this.managed.GetNativeTableCreate2(); }
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 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 void Setup() { JET_TABLEID tableidTemp = new JET_TABLEID() { Value = (IntPtr)456, }; this.managed = new JET_TABLECREATE() { szTableName = "table7", szTemplateTableName = "parentTable", ulPages = 7, ulDensity = 62, rgcolumncreate = null, cColumns = 0, rgindexcreate = null, cIndexes = 0, szCallback = "module!FunkyFunction", cbtyp = JET_cbtyp.AfterReplace, grbit = CreateTableColumnIndexGrbit.FixedDDL, pSeqSpacehints = null, pLVSpacehints = null, cbSeparateLV = 0x999, tableid = tableidTemp, cCreated = 2, }; this.native = this.managed.GetNativeTableCreate2(); }
/// <summary> /// Creates the table. /// </summary> /// <param name="tableName">Name of the table.</param> /// <returns>The newly created table.</returns> private JET_TABLECREATE CreateTable(string tableName) { const string ColumnKey1Name = "columnkey1"; string clustIndexKey = string.Format("+{0}\0\0", ColumnKey1Name); string secIndexWithPrimaryKey = string.Format("+{0}\0\0", ColumnKey1Name); JET_COLUMNCREATE[] columnCreates = { new JET_COLUMNCREATE { szColumnName = ColumnKey1Name, coltyp = VistaColtyp.GUID }, }; JET_SPACEHINTS spaceHint = new JET_SPACEHINTS { cbInitial = GuidDotNetSortOrderTest.PageSize * 50 }; JET_INDEXCREATE[] indexCreates = { new JET_INDEXCREATE { szIndexName = this.clustIndexName, szKey = clustIndexKey, cbKey = clustIndexKey.Length, grbit = CreateIndexGrbit.IndexPrimary | Windows8Grbits.IndexDotNetGuid, pSpaceHints = spaceHint }, new JET_INDEXCREATE { szIndexName = this.secIndexName, szKey = clustIndexKey, cbKey = clustIndexKey.Length, grbit = Windows8Grbits.IndexDotNetGuid, pSpaceHints = spaceHint } }; JET_TABLECREATE tc = new JET_TABLECREATE { szTableName = tableName, rgcolumncreate = columnCreates, cColumns = columnCreates.Length, rgindexcreate = indexCreates, cIndexes = indexCreates.Length, grbit = CreateTableColumnIndexGrbit.None, ulPages = 110 }; Api.JetCreateTableColumnIndex3(this.sesId, this.databaseId, tc); Assert.AreEqual <int>(4, tc.cCreated); // 1 table + 1 colummns + 2 indexes. Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tc.tableid); this.columnIdKey1 = Api.GetTableColumnid(this.sesId, tc.tableid, ColumnKey1Name); Assert.AreNotEqual <JET_COLUMNID>(JET_COLUMNID.Nil, this.columnIdKey1); return(tc); }
public override void Create(JET_SESID sessionId, JET_DBID databaseId) { var projectColumnCreate = new JET_COLUMNCREATE() { szColumnName = ProjectColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnNotNULL }; var nameColumnCreate = new JET_COLUMNCREATE() { szColumnName = NameColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnNotNULL }; var valueColumnCreate = new JET_COLUMNCREATE() { szColumnName = ValueColumnName, coltyp = JET_coltyp.LongBinary, grbit = ColumndefGrbit.None }; var columns = new JET_COLUMNCREATE[] { projectColumnCreate, nameColumnCreate, valueColumnCreate }; var projectAndNameIndexKey = "+" + ProjectColumnName + "\0+" + NameColumnName + "\0\0"; var indexes = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = ProjectAndNameIndexName, szKey = projectAndNameIndexKey, cbKey = projectAndNameIndexKey.Length, grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull, ulDensity = 80 } }; var tableCreate = new JET_TABLECREATE() { szTableName = TableName, ulPages = 16, ulDensity = 80, rgcolumncreate = columns, cColumns = columns.Length, rgindexcreate = indexes, cIndexes = indexes.Length }; Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate); _projectColumnId = projectColumnCreate.columnid; _nameColumnId = nameColumnCreate.columnid; _valueColumnId = valueColumnCreate.columnid; Api.JetCloseTable(sessionId, tableCreate.tableid); }
public override void Create(JET_SESID sessionId, JET_DBID databaseId) { var projectColumnCreate = new JET_COLUMNCREATE() { szColumnName = ProjectColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnNotNULL }; var nameColumnCreate = new JET_COLUMNCREATE() { szColumnName = NameColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnNotNULL }; var valueColumnCreate = new JET_COLUMNCREATE() { szColumnName = ValueColumnName, coltyp = JET_coltyp.LongBinary, grbit = ColumndefGrbit.None }; var columns = new JET_COLUMNCREATE[] { projectColumnCreate, nameColumnCreate, valueColumnCreate }; var projectAndNameIndexKey = "+" + ProjectColumnName + "\0+" + NameColumnName + "\0\0"; var indexes = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = ProjectAndNameIndexName, szKey = projectAndNameIndexKey, cbKey = projectAndNameIndexKey.Length, grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull, ulDensity = 80 } }; var tableCreate = new JET_TABLECREATE() { szTableName = TableName, ulPages = 16, ulDensity = 80, rgcolumncreate = columns, cColumns = columns.Length, rgindexcreate = indexes, cIndexes = indexes.Length }; Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate); _projectColumnId = projectColumnCreate.columnid; _nameColumnId = nameColumnCreate.columnid; _valueColumnId = valueColumnCreate.columnid; Api.JetCloseTable(sessionId, tableCreate.tableid); }
public void VerifyValidityCatchesNonZeroCColumnsWithNullArray() { var x = new JET_TABLECREATE() { rgcolumncreate = null, cColumns = 10, }; x.CheckMembersAreValid(); }
public void VerifyValidityCatchesNonZeroCIndexesWithNullArray() { var x = new JET_TABLECREATE() { rgindexcreate = null, cIndexes = 10, }; x.CheckMembersAreValid(); }
public void JetTableCreateToString() { var tablecreate = new JET_TABLECREATE { szTableName = "BoringTableName", cColumns = 33, cIndexes = 71, }; Assert.AreEqual("JET_TABLECREATE(BoringTableName:33 columns:71 indices)", tablecreate.ToString()); }
/// <summary> /// Creates a table, adds columns, and indices on that table. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to which to add the new table.</param> /// <param name="tablecreate">Object describing the table to create.</param> /// <returns>An error if the call fails.</returns> public int JetCreateTableColumnIndex4( JET_SESID sesid, JET_DBID dbid, JET_TABLECREATE tablecreate) { TraceFunctionCall(); this.CheckSupportsWindows8Features("JetCreateTableColumnIndex4"); CheckNotNull(tablecreate, "tablecreate"); return(CreateTableColumnIndex4(sesid, dbid, tablecreate)); }
public void VerifyValidityCatchesNegativeCIndexes() { var x = new JET_TABLECREATE() { rgcolumncreate = null, cIndexes = -1, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
public void VerifyValidityCatchesCIndexesTooBig() { var x = new JET_TABLECREATE() { rgindexcreate = new JET_INDEXCREATE[] { new JET_INDEXCREATE(), new JET_INDEXCREATE(), }, cIndexes = 10, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
public void VerifyValidityCatchesCColumnsTooBig() { var x = new JET_TABLECREATE() { rgcolumncreate = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE(), new JET_COLUMNCREATE(), }, cColumns = 10, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
/// <summary> /// Create table with 4 records per page /// </summary> private void CreatePopulateAndTestTable() { Api.JetBeginTransaction(this.sesId); EseInteropTestHelper.ConsoleWriteLine("Create and popluate table."); JET_TABLECREATE tc = this.CreateTable(this.tableName); for (int i = 0; i < 10000; i++) { this.InsertRecord(tc.tableid, System.Guid.NewGuid()); if ((i % 100) == 0) { if ((i % 2000) == 0) { EseInteropTestHelper.ConsoleWriteLine("Added another 2000 Guids."); } Api.JetCommitTransaction(this.sesId, CommitTransactionGrbit.None); Api.JetBeginTransaction(this.sesId); } } EseInteropTestHelper.ConsoleWriteLine("Finished inserting first set of values in index."); Guid guidPrev; Guid guidCur; Api.JetMove(this.sesId, tc.tableid, JET_Move.First, MoveGrbit.None); int bytesRead; byte[] data = new byte[16]; Api.JetRetrieveColumn(this.sesId, tc.tableid, this.columnIdKey1, data, data.Length, out bytesRead, 0, null); guidPrev = new System.Guid(data); for (int i = 1; i < 10000; i++) { Api.JetMove(this.sesId, tc.tableid, JET_Move.Next, MoveGrbit.None); Api.JetRetrieveColumn(this.sesId, tc.tableid, this.columnIdKey1, data, data.Length, out bytesRead, 0, null); guidCur = new System.Guid(data); Assert.IsTrue(guidCur.CompareTo(guidPrev) > 0); guidPrev = guidCur; } Api.JetCommitTransaction(this.sesId, CommitTransactionGrbit.None); EseInteropTestHelper.ConsoleWriteLine("Finished testing .Net Guid sort order on inserted values"); Api.JetCloseTable(this.sesId, tc.tableid); }
/// <summary> /// Create table with 4 records per page /// </summary> private void CreatePopulateAndTestTable() { EseInteropTestHelper.ConsoleWriteLine("Create and popluate table."); JET_TABLECREATE tc = this.CreateTable(this.tableName); // make sure full range is covered this.InsertRecord(tc.tableid, 0); this.InsertRecord(tc.tableid, 0x7fffffffffffffff); this.InsertRecord(tc.tableid, 0xffffffffffffffff); // add many random values for (int i = 0; i < this.cuint64Random; i++) { this.InsertRecord(tc.tableid, this.RandomULong()); } EseInteropTestHelper.ConsoleWriteLine("Finished inserting records in table."); // validate order ulong ulongPrev; ulong ulongCur; Api.JetMove(this.sesId, tc.tableid, JET_Move.First, MoveGrbit.None); int bytesRead; byte[] data = new byte[8]; Api.JetRetrieveColumn(this.sesId, tc.tableid, this.columnIdKey1, data, data.Length, out bytesRead, 0, null); ulongPrev = BitConverter.ToUInt64(data, 0); for (int i = 1; i < this.cuint64Random + 3; i++) { Api.JetMove(this.sesId, tc.tableid, JET_Move.Next, MoveGrbit.None); Api.JetRetrieveColumn(this.sesId, tc.tableid, this.columnIdKey1, data, data.Length, out bytesRead, 0, null); ulongCur = BitConverter.ToUInt64(data, 0); EseInteropTestHelper.ConsoleWriteLine("Unsigned long long {0} is larger than {1}.", ulongCur, ulongPrev); Assert.IsTrue(ulongCur.CompareTo(ulongPrev) > 0); ulongPrev = ulongCur; } EseInteropTestHelper.ConsoleWriteLine("UInt64 order is correct and same value is retrieved from secondary index key."); EseInteropTestHelper.ConsoleWriteLine("Finished testing ULongLong sort order on inserted values"); Api.JetCloseTable(this.sesId, tc.tableid); }
public void NavigationMoveSecondaryNotSupported() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 1, 10); this.InsertRecord(tc.tableid, 2, 10); this.InsertRecord(tc.tableid, -3, 30); Api.JetSetCurrentIndex(this.sesId, tc.tableid, this.secIndexWithPrimaryName); JET_INDEX_COLUMN filter = this.CreateFilter(this.columnIdKey, 2, JetRelop.Equals); JET_INDEX_COLUMN[] filters = { filter }; this.MoveCursor(tc.tableid, JET_Move.First, filters, typeof(EsentFilteredMoveNotSupportedException)); }
public void NavigationMoveLastClustered() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 2); this.InsertRecord(tc.tableid, 3); this.InsertRecord(tc.tableid, 1); JET_INDEX_COLUMN filter1 = this.CreateFilter(this.columnIdKey, 2, JetRelop.LessThan); JET_INDEX_COLUMN[] filters = { filter1 }; this.MoveCursor(tc.tableid, JET_Move.Last, filters); this.VerifyCurrentRecord(tc.tableid, 1); }
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); }
public void NavigationMoveNextByteOrder() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 1, 10); this.InsertRecord(tc.tableid, 2, 260); this.InsertRecord(tc.tableid, 3, 20); JET_INDEX_COLUMN filter1 = this.CreateFilter(this.columnIdData1, 15, JetRelop.LessThan); JET_INDEX_COLUMN[] filters = { filter1 }; this.MoveCursor(tc.tableid, JET_Move.First, filters); this.VerifyCurrentRecord(tc.tableid, 1); this.MoveCursor(tc.tableid, JET_Move.Next, filters, typeof(EsentNoCurrentRecordException)); }
public void NavigationMultipleFilters() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 1, 20); this.InsertRecord(tc.tableid, 2, 30); this.InsertRecord(tc.tableid, 3, 30); JET_INDEX_COLUMN filter1 = this.CreateFilter(this.columnIdKey, 2, JetRelop.NotEquals); JET_INDEX_COLUMN filter2 = this.CreateFilter(this.columnIdData1, 30, JetRelop.GreaterThanOrEqual); JET_INDEX_COLUMN[] filters = { filter1, filter2 }; this.MoveCursor(tc.tableid, JET_Move.First, filters); this.VerifyCurrentRecord(tc.tableid, 3); }
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) { } } } } }
public void NavigationBitmask() { if (!EsentVersion.SupportsWindows8Features) { return; } JET_TABLECREATE tc = this.CreateTable(this.tableName); this.InsertRecord(tc.tableid, 1, 15); this.InsertRecord(tc.tableid, 3, 11); this.InsertRecord(tc.tableid, 5, 10); this.InsertRecord(tc.tableid, 9, 8); JET_INDEX_COLUMN filter1 = this.CreateFilter(this.columnIdKey, 8, JetRelop.BitmaskEqualsZero); JET_INDEX_COLUMN filter2 = this.CreateFilter(this.columnIdData1, 1, JetRelop.BitmaskNotEqualsZero); JET_INDEX_COLUMN[] filters = { filter1, filter2 }; this.MoveCursor(tc.tableid, JET_Move.Last, filters); this.VerifyCurrentRecord(tc.tableid, 3, 11); }
public void Setup() { this.directory = SetupHelper.CreateRandomDirectory(); this.database = Path.Combine(this.directory, "database.edb"); 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); this.columncreatesBase = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, grbit = ColumndefGrbit.ColumnFixed, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; this.columncreatesChild = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short_child", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext_child", coltyp = JET_coltyp.LongText, grbit = ColumndefGrbit.ColumnTagged, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; this.tablecreateTemplate = new JET_TABLECREATE() { szTableName = "tableBase", ulPages = 23, ulDensity = 75, cColumns = this.columncreatesBase.Length, rgcolumncreate = this.columncreatesBase, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.TemplateTable, }; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, this.tablecreateTemplate); var columndef = new JET_COLUMNDEF() { cp = JET_CP.Unicode, coltyp = JET_coltyp.LongText, }; var tableCreated = new JET_TABLEID() { Value = this.tablecreateTemplate.tableid.Value }; Api.JetCloseTable(this.sesid, tableCreated); this.tablecreateChild = new JET_TABLECREATE() { szTableName = "tableChild", szTemplateTableName = "tableBase", ulPages = 23, ulDensity = 75, rgcolumncreate = this.columncreatesChild, cColumns = this.columncreatesChild.Length, rgindexcreate = null, cIndexes = 0, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, }; Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, this.tablecreateChild); this.tableidChild = new JET_TABLEID() { Value = this.tablecreateChild.tableid.Value }; Api.JetCloseTable(this.sesid, this.tableidChild); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); Api.JetOpenTable(this.sesid, this.dbid, this.tablecreateTemplate.szTableName, null, 0, OpenTableGrbit.None, out this.tableidParent); Api.JetOpenTable(this.sesid, this.dbid, this.tablecreateChild.szTableName, null, 0, OpenTableGrbit.None, out this.tableidChild); }
public void JetCreateTemplateTableColumnIndex() { var columncreates = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreateTemplate = new JET_TABLECREATE() { szTableName = "tableOld", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.TemplateTable, }; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreateTemplate); var tableCreated = new JET_TABLEID() { Value = tablecreateTemplate.tableid.Value }; Assert.AreNotEqual<JET_TABLEID>(JET_TABLEID.Nil, tableCreated); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual<int>(tablecreateTemplate.cCreated, 5); Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil); Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil); var tablecreateChild = new JET_TABLECREATE() { szTableName = "tableNew", szTemplateTableName = "tableOld", ulPages = 23, ulDensity = 75, rgcolumncreate = null, cColumns = 0, rgindexcreate = null, cIndexes = 0, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, }; Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreateChild); var tableidChild = new JET_TABLEID() { Value = tablecreateChild.tableid.Value }; Assert.AreNotEqual<JET_TABLEID>(JET_TABLEID.Nil, tableidChild); // 1 table = 1 object Assert.AreEqual<int>(tablecreateChild.cCreated, 1); Api.JetCloseTable(this.sesid, tableCreated); Api.JetCloseTable(this.sesid, tableidChild); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); }
public void JetCreateTableColumnIndexSpaceHints() { var columncreates = new[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, pvDefault = BitConverter.GetBytes((short)37), cbDefault = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; 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 spacehintsSeq = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLv = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndex, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreate = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, pSeqSpacehints = spacehintsSeq, pLVSpacehints = spacehintsLv, }; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreate); var tableCreated = new JET_TABLEID() { Value = tablecreate.tableid.Value }; Assert.AreNotEqual<JET_TABLEID>(JET_TABLEID.Nil, tableCreated); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual<int>(tablecreate.cCreated, 5); Api.JetCloseTable(this.sesid, tableCreated); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); }
public override void Create(JET_SESID sessionId, JET_DBID databaseId) { var idColumnCreate = new JET_COLUMNCREATE() { szColumnName = IdColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL }; var nameColumnCreate = new JET_COLUMNCREATE() { szColumnName = NameColumnName, coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, grbit = ColumndefGrbit.ColumnNotNULL }; var columns = new JET_COLUMNCREATE[] { idColumnCreate, nameColumnCreate }; var idIndexKey = "+" + IdColumnName + "\0\0"; var nameIndexKey = "+" + NameColumnName + "\0\0"; var indexes = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = IdIndexName, szKey = idIndexKey, cbKey = idIndexKey.Length, grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull, ulDensity = 80 }, new JET_INDEXCREATE { szIndexName = NameIndexName, szKey = nameIndexKey, cbKey = nameIndexKey.Length, grbit = CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull | VistaGrbits.IndexDisallowTruncation, ulDensity = 80, // this should be 2000 bytes Max after vista cbKeyMost = SystemParameters.KeyMost } }; var tableCreate = new JET_TABLECREATE() { szTableName = TableName, ulPages = 16, ulDensity = 80, rgcolumncreate = columns, cColumns = columns.Length, rgindexcreate = indexes, cIndexes = indexes.Length }; Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate); _idColumnId = idColumnCreate.columnid; _nameColumnId = nameColumnCreate.columnid; Api.JetCloseTable(sessionId, tableCreate.tableid); }
public void JetTableCreateToString() { var tablecreate = new JET_TABLECREATE { szTableName = "BoringTableName", cColumns = 33, cIndexes = 71, }; Assert.AreEqual("JET_TABLECREATE(BoringTableName:33 columns:71 indices)", tablecreate.ToString()); }
public void VerifyValidityCatchesNegativeCIndexes() { var x = new JET_TABLECREATE() { rgcolumncreate = null, cIndexes = -1, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
public void VerifyValidityCatchesNonZeroCIndexesWithNullArray() { var x = new JET_TABLECREATE() { rgindexcreate = null, cIndexes = 10, }; x.CheckMembersAreValid(); }
/// <summary> /// Creates a table, adds columns, and indices on that table. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to which to add the new table.</param> /// <param name="tablecreate">Object describing the table to create.</param> /// <returns>An error if the call fails.</returns> public int JetCreateTableColumnIndex4( JET_SESID sesid, JET_DBID dbid, JET_TABLECREATE tablecreate) { TraceFunctionCall("JetCreateTableColumnIndex4"); this.CheckSupportsWindows8Features("JetCreateTableColumnIndex4"); CheckNotNull(tablecreate, "tablecreate"); return CreateTableColumnIndex4(sesid, dbid, tablecreate); }
public void JetCreateTemplateTableColumnIndex() { var columncreates = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreateTemplate = new JET_TABLECREATE() { szTableName = "tableOld", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.TemplateTable, }; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreateTemplate); var tableCreated = new JET_TABLEID() { Value = tablecreateTemplate.tableid.Value }; Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableCreated); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual <int>(tablecreateTemplate.cCreated, 5); Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil); Assert.AreNotEqual(tablecreateTemplate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil); var tablecreateChild = new JET_TABLECREATE() { szTableName = "tableNew", szTemplateTableName = "tableOld", ulPages = 23, ulDensity = 75, rgcolumncreate = null, cColumns = 0, rgindexcreate = null, cIndexes = 0, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, }; Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreateChild); var tableidChild = new JET_TABLEID() { Value = tablecreateChild.tableid.Value }; Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableidChild); // 1 table = 1 object Assert.AreEqual <int>(tablecreateChild.cCreated, 1); Api.JetCloseTable(this.sesid, tableCreated); Api.JetCloseTable(this.sesid, tableidChild); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); }
public void VerifyJetTablecreateInequality() { var columncreates = new[] { new JET_COLUMNCREATE { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var spacehintsIndex = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintHotpointSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsSeq = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLv = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanBackward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreates = new[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndex, }, null, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; JET_TABLEID tableidTemp = new JET_TABLEID() { Value = (IntPtr)2, }; var tablecreates = new JET_TABLECREATE[21]; for (int i = 0; i < tablecreates.Length; ++i) { tablecreates[i] = new JET_TABLECREATE { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.NoFixedVarColumnsInDerivedTables, pSeqSpacehints = spacehintsSeq, pLVSpacehints = spacehintsLv, tableid = tableidTemp, cCreated = 7, }; } int j = 1; tablecreates[j++].szTableName = "different"; tablecreates[j++].ulPages = 57; tablecreates[j++].ulDensity = 98; tablecreates[j++].cColumns = 1; tablecreates[j++].rgcolumncreate = new[] { null, columncreates[0], }; tablecreates[j].rgcolumncreate = null; tablecreates[j++].cColumns = 0; tablecreates[j++].cIndexes--; tablecreates[j++].cbSeparateLV = 24; tablecreates[j++].rgindexcreate = new[] { indexcreates[1], indexcreates[0], indexcreates[0], }; tablecreates[j++].rgindexcreate = new[] { indexcreates[1], null, indexcreates[0], }; tablecreates[j].rgindexcreate = null; tablecreates[j++].cIndexes = 0; tablecreates[j++].cbtyp = JET_cbtyp.AfterInsert; tablecreates[j++].grbit = CreateTableColumnIndexGrbit.FixedDDL; tablecreates[j++].pSeqSpacehints = spacehintsLv; tablecreates[j++].pSeqSpacehints = null; tablecreates[j++].pLVSpacehints = spacehintsSeq; tablecreates[j++].pLVSpacehints = null; tableidTemp.Value = new IntPtr(63); tablecreates[j++].tableid = tableidTemp; tablecreates[j++].cCreated--; tablecreates[j++] = new JET_TABLECREATE(); Debug.Assert(j == tablecreates.Length, "Didn't fill in all entries of tablecreates"); VerifyAll(tablecreates); }
public void VerifyJetTablecreateEquality() { var columncreatesX = new[] { new JET_COLUMNCREATE { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1NameX = "firstIndex"; const string Index1DescriptionX = "+col1_short\0-col2_longtext\0"; const string Index2NameX = "secondIndex"; const string Index2DescriptionX = "+col2_longtext\0-col1_short\0"; var spacehintsIndexX = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsSeqX = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLvX = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreatesX = new[] { new JET_INDEXCREATE { szIndexName = Index1NameX, szKey = Index1DescriptionX, cbKey = Index1DescriptionX.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndexX, }, new JET_INDEXCREATE { szIndexName = Index2NameX, szKey = Index2DescriptionX, cbKey = Index2DescriptionX.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; JET_TABLEID tableidTemp = new JET_TABLEID() { Value = (IntPtr)2, }; var tablecreateX = new JET_TABLECREATE { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreatesX.Length, rgcolumncreate = columncreatesX, rgindexcreate = indexcreatesX, cIndexes = indexcreatesX.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.NoFixedVarColumnsInDerivedTables, pSeqSpacehints = spacehintsSeqX, pLVSpacehints = spacehintsLvX, tableid = tableidTemp, cCreated = 7, }; var columncreatesY = new[] { new JET_COLUMNCREATE { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, new JET_COLUMNCREATE { szColumnName = "col3_ignored", }, }; const string Index1NameY = "firstIndex"; const string Index1DescriptionY = "+col1_short\0-col2_longtext\0"; const string Index2NameY = "secondIndex"; const string Index2DescriptionY = "+col2_longtext\0-col1_short\0"; var spacehintsIndexY = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsSeqY = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLvY = new JET_SPACEHINTS { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreatesY = new[] { new JET_INDEXCREATE { szIndexName = Index1NameY, szKey = Index1DescriptionY, cbKey = Index1DescriptionY.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndexY, }, new JET_INDEXCREATE { szIndexName = Index2NameY, szKey = Index2DescriptionY, cbKey = Index2DescriptionY.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, null, }; var tablecreateY = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreatesX.Length, rgcolumncreate = columncreatesY, rgindexcreate = indexcreatesY, cIndexes = indexcreatesX.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.NoFixedVarColumnsInDerivedTables, pSeqSpacehints = spacehintsSeqY, pLVSpacehints = spacehintsLvY, tableid = tableidTemp, cCreated = 7, }; TestContentEquals(tablecreateX, tablecreateY); }
public void CreateTableColumnIndex3OnXp() { var columncreates = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreate = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, }; string directory = SetupHelper.CreateRandomDirectory(); string database = Path.Combine(directory, "test.db"); using (var instance = new Instance("XpCreateTableColumnIndex3")) { 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); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual(tablecreate.cCreated, 5); Assert.AreNotEqual(tablecreate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil); Assert.AreNotEqual(tablecreate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil); Api.JetCloseTable(session, tablecreate.tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } } } }
/// <summary> /// Creates a table, adds columns, and indices on that table. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to which to add the new table.</param> /// <param name="tablecreate">Object describing the table to create.</param> public static void JetCreateTableColumnIndex3( JET_SESID sesid, JET_DBID dbid, JET_TABLECREATE tablecreate) { Api.Check(Impl.JetCreateTableColumnIndex3(sesid, dbid, tablecreate)); }
private void JetCreateTableColumnIndex() { Console.WriteLine("\tJetCreateTableColumnIndex()"); var columncreates = new JET_COLUMNCREATE[13]; for (int i = 0; i < columncreates.Length; ++i) { columncreates[i] = new JET_COLUMNCREATE(); } columncreates[0] = new JET_COLUMNCREATE { szColumnName = "recordID", coltyp = JET_coltyp.Long }; columncreates[1].szColumnName = "tagged"; columncreates[1].coltyp = VistaColtyp.LongLong; columncreates[1].grbit = ColumndefGrbit.ColumnTagged; columncreates[2].szColumnName = "separated_lv"; columncreates[2].coltyp = JET_coltyp.LongBinary; columncreates[3].szColumnName = "compressed_unicode"; columncreates[3].coltyp = JET_coltyp.LongText; columncreates[3].cp = JET_CP.Unicode; columncreates[3].grbit = Windows7Grbits.ColumnCompressed; columncreates[4].szColumnName = "compressed_ascii"; columncreates[4].coltyp = JET_coltyp.LongText; columncreates[4].cp = JET_CP.ASCII; columncreates[4].grbit = Windows7Grbits.ColumnCompressed; columncreates[5].szColumnName = "compressed_binary"; columncreates[5].coltyp = JET_coltyp.LongBinary; columncreates[5].grbit = Windows7Grbits.ColumnCompressed; columncreates[6].szColumnName = "columntodelete"; columncreates[6].coltyp = JET_coltyp.Long; columncreates[7].szColumnName = "autoinc"; columncreates[7].coltyp = JET_coltyp.Long; columncreates[7].grbit = ColumndefGrbit.ColumnAutoincrement; columncreates[8].szColumnName = "version"; columncreates[8].coltyp = JET_coltyp.Long; columncreates[8].grbit = ColumndefGrbit.ColumnVersion; columncreates[9].szColumnName = "unicode"; columncreates[9].coltyp = JET_coltyp.LongText; columncreates[9].cp = JET_CP.Unicode; columncreates[9].pvDefault = Encoding.Unicode.GetBytes( "This is the default value for the unicode column"); columncreates[9].cbDefault = columncreates[9].pvDefault.Length; columncreates[10].szColumnName = "ascii"; columncreates[10].coltyp = JET_coltyp.LongText; columncreates[10].cp = JET_CP.ASCII; columncreates[10].pvDefault = Encoding.ASCII.GetBytes("This is the default value for the ASCII column"); columncreates[10].cbDefault = columncreates[10].pvDefault.Length; columncreates[11].szColumnName = "columntodelete2"; columncreates[11].coltyp = JET_coltyp.Long; columncreates[12].szColumnName = "fixed"; columncreates[12].coltyp = VistaColtyp.LongLong; columncreates[12].grbit = ColumndefGrbit.ColumnFixed; var primarySpaceHints = new JET_SPACEHINTS(); primarySpaceHints.ulInitialDensity = 100; primarySpaceHints.cbInitial = 512 * 1024; var secondarySpaceHints = new JET_SPACEHINTS(); secondarySpaceHints.ulInitialDensity = 80; secondarySpaceHints.cbInitial = 96 * 1024; secondarySpaceHints.ulGrowth = 150; secondarySpaceHints.cbMinExtent = 64 * 1024; secondarySpaceHints.cbMaxExtent = 256 * 1024; var indexcreates = new JET_INDEXCREATE[14]; for (int i = 0; i < indexcreates.Length; ++i) { indexcreates[i] = new JET_INDEXCREATE(); } indexcreates[0].szIndexName = "index_recordID"; indexcreates[0].szKey = "+recordID\0\0"; indexcreates[0].cbKey = indexcreates[0].szKey.Length; indexcreates[0].grbit = CreateIndexGrbit.IndexPrimary; indexcreates[0].pSpaceHints = primarySpaceHints; indexcreates[1] = this.MakeIndexcreate("tagged"); indexcreates[2] = this.MakeIndexcreate("separated_lv"); indexcreates[3] = this.MakeIndexcreate("compressed_unicode"); indexcreates[4] = this.MakeIndexcreate("compressed_ascii"); indexcreates[5] = this.MakeIndexcreate("compressed_binary"); indexcreates[6] = this.MakeIndexcreate("autoinc"); indexcreates[7] = this.MakeIndexcreate("version"); indexcreates[8] = this.MakeIndexcreate("unicode"); indexcreates[9] = this.MakeIndexcreate("ascii"); indexcreates[10] = this.MakeIndexcreate("fixed"); indexcreates[11].szIndexName = "secondary"; indexcreates[11].szKey = "+autoinc\0+compressed_unicode\0+recordID\0\0"; indexcreates[11].cbKey = indexcreates[11].szKey.Length; indexcreates[11].grbit = CreateIndexGrbit.IndexUnique; indexcreates[11].pSpaceHints = secondarySpaceHints; indexcreates[12].szIndexName = "indextodelete"; indexcreates[12].szKey = "+autoinc\0+recordID\0\0"; indexcreates[12].cbKey = indexcreates[12].szKey.Length; indexcreates[13] = this.MakeIndexcreate("columntodelete2"); var tablecreate = new JET_TABLECREATE(); tablecreate.szTableName = this.table; tablecreate.ulPages = 1; tablecreate.ulDensity = 100; tablecreate.rgcolumncreate = columncreates; tablecreate.cColumns = tablecreate.rgcolumncreate.Length; tablecreate.rgindexcreate = indexcreates; tablecreate.cIndexes = tablecreate.rgindexcreate.Length; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreate); Api.JetCloseTable(this.sesid, tablecreate.tableid); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); }
public void VerifyValidityCatchesCColumnsTooBig() { var x = new JET_TABLECREATE() { rgcolumncreate = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE(), new JET_COLUMNCREATE(), }, cColumns = 10, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
public void JetCreateTableColumnIndexSpaceHints() { var columncreates = new[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, pvDefault = BitConverter.GetBytes((short)37), cbDefault = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; 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 spacehintsSeq = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLv = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndex, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreate = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, pSeqSpacehints = spacehintsSeq, pLVSpacehints = spacehintsLv, }; Api.JetBeginTransaction(this.sesid); Api.JetCreateTableColumnIndex3(this.sesid, this.dbid, tablecreate); var tableCreated = new JET_TABLEID() { Value = tablecreate.tableid.Value }; Assert.AreNotEqual <JET_TABLEID>(JET_TABLEID.Nil, tableCreated); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual <int>(tablecreate.cCreated, 5); Api.JetCloseTable(this.sesid, tableCreated); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); }
public void VerifyValidityCatchesCIndexesTooBig() { var x = new JET_TABLECREATE() { rgindexcreate = new JET_INDEXCREATE[] { new JET_INDEXCREATE(), new JET_INDEXCREATE(), }, cIndexes = 10, }; var y = new JET_TABLECREATE(); Assert.IsFalse(x.ContentEquals(y)); }
public override void Create(JET_SESID sessionId, JET_DBID databaseId) { var idColumnCreate = new JET_COLUMNCREATE() { szColumnName = IdColumnName, coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL }; var nameColumnCreate = new JET_COLUMNCREATE() { szColumnName = NameColumnName, coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, grbit = ColumndefGrbit.ColumnNotNULL }; var columns = new JET_COLUMNCREATE[] { idColumnCreate, nameColumnCreate }; var idIndexKey = "+" + IdColumnName + "\0\0"; var nameIndexKey = "+" + NameColumnName + "\0\0"; var indexes = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = IdIndexName, szKey = idIndexKey, cbKey = idIndexKey.Length, grbit = CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull, ulDensity = 80 }, new JET_INDEXCREATE { szIndexName = NameIndexName, szKey = nameIndexKey, cbKey = nameIndexKey.Length, grbit = CreateIndexGrbit.IndexUnique | CreateIndexGrbit.IndexDisallowNull | VistaGrbits.IndexDisallowTruncation, ulDensity = 80, cbKeyMost = SystemParameters.KeyMost } }; var tableCreate = new JET_TABLECREATE() { szTableName = TableName, ulPages = 16, ulDensity = 80, rgcolumncreate = columns, cColumns = columns.Length, rgindexcreate = indexes, cIndexes = indexes.Length }; Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate); _idColumnId = idColumnCreate.columnid; _nameColumnId = nameColumnCreate.columnid; Api.JetCloseTable(sessionId, tableCreate.tableid); }
public void VerifyValidityCatchesNonZeroCColumnsWithNullArray() { var x = new JET_TABLECREATE() { rgcolumncreate = null, cColumns = 10, }; x.CheckMembersAreValid(); }
public void CreateTableColumnIndex3OnXp() { var columncreates = new JET_COLUMNCREATE[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var tablecreate = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, }; string directory = SetupHelper.CreateRandomDirectory(); string database = Path.Combine(directory, "test.db"); using (var instance = new Instance("XpCreateTableColumnIndex3")) { 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); // 1 table, 2 columns, 2 indices = 5 objects. Assert.AreEqual(tablecreate.cCreated, 5); Assert.AreNotEqual(tablecreate.rgcolumncreate[0].columnid, JET_COLUMNID.Nil); Assert.AreNotEqual(tablecreate.rgcolumncreate[1].columnid, JET_COLUMNID.Nil); Api.JetCloseTable(session, tablecreate.tableid); transaction.Commit(CommitTransactionGrbit.LazyFlush); } } } }
/// <summary> /// Creates a table, adds columns, and indices on that table. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="dbid">The database to which to add the new table.</param> /// <param name="tablecreate">Object describing the table to create.</param> /// <returns>An error if the call fails.</returns> private static int CreateTableColumnIndex4( JET_SESID sesid, JET_DBID dbid, JET_TABLECREATE tablecreate) { NATIVE_TABLECREATE4 nativeTableCreate = tablecreate.GetNativeTableCreate4(); unsafe { var handles = new GCHandleCollection(); try { // Convert/pin the column definitions. nativeTableCreate.rgcolumncreate = (NATIVE_COLUMNCREATE*)GetNativeColumnCreates(tablecreate.rgcolumncreate, true, ref handles); // Convert/pin the index definitions. NATIVE_INDEXCREATE3[] nativeIndexCreates = GetNativeIndexCreate3s(tablecreate.rgindexcreate, ref handles); nativeTableCreate.rgindexcreate = handles.Add(nativeIndexCreates); // Convert/pin the space hints. if (tablecreate.pSeqSpacehints != null) { NATIVE_SPACEHINTS nativeSpaceHints = tablecreate.pSeqSpacehints.GetNativeSpaceHints(); nativeTableCreate.pSeqSpacehints = (NATIVE_SPACEHINTS*)handles.Add(nativeSpaceHints); } if (tablecreate.pLVSpacehints != null) { NATIVE_SPACEHINTS nativeSpaceHints = tablecreate.pLVSpacehints.GetNativeSpaceHints(); nativeTableCreate.pLVSpacehints = (NATIVE_SPACEHINTS*)handles.Add(nativeSpaceHints); } int err = NativeMethods.JetCreateTableColumnIndex4W(sesid.Value, dbid.Value, ref nativeTableCreate); // Modified fields. tablecreate.tableid = new JET_TABLEID { Value = nativeTableCreate.tableid }; tablecreate.cCreated = checked((int)nativeTableCreate.cCreated); if (tablecreate.rgcolumncreate != null) { for (int i = 0; i < tablecreate.rgcolumncreate.Length; ++i) { tablecreate.rgcolumncreate[i].SetFromNativeColumnCreate(nativeTableCreate.rgcolumncreate[i]); } } if (tablecreate.rgindexcreate != null) { for (int i = 0; i < tablecreate.rgindexcreate.Length; ++i) { tablecreate.rgindexcreate[i].SetFromNativeIndexCreate(nativeIndexCreates[i]); } } return Err(err); } finally { handles.Dispose(); } } }
public void VerifyTableCreateCanBeSerialized() { var columncreates = new[] { new JET_COLUMNCREATE() { szColumnName = "col1_short", coltyp = JET_coltyp.Short, cbMax = 2, pvDefault = BitConverter.GetBytes((short)37), cbDefault = 2, }, new JET_COLUMNCREATE() { szColumnName = "col2_longtext", coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, }, }; const string Index1Name = "firstIndex"; const string Index1Description = "+col1_short\0-col2_longtext\0"; const string Index2Name = "secondIndex"; const string Index2Description = "+col2_longtext\0-col1_short\0"; 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 spacehintsSeq = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var spacehintsLv = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; var indexcreates = new JET_INDEXCREATE[] { new JET_INDEXCREATE { szIndexName = Index1Name, szKey = Index1Description, cbKey = Index1Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 99, pSpaceHints = spacehintsIndex, }, new JET_INDEXCREATE { szIndexName = Index2Name, szKey = Index2Description, cbKey = Index2Description.Length + 1, grbit = CreateIndexGrbit.None, ulDensity = 79, }, }; var expected = new JET_TABLECREATE() { szTableName = "tableBigBang", ulPages = 23, ulDensity = 75, cColumns = columncreates.Length, rgcolumncreate = columncreates, rgindexcreate = indexcreates, cIndexes = indexcreates.Length, cbSeparateLV = 100, cbtyp = JET_cbtyp.Null, grbit = CreateTableColumnIndexGrbit.None, pSeqSpacehints = spacehintsSeq, pLVSpacehints = spacehintsLv, }; SerializeAndCompareContent(expected); }