public void Setup() { this.managedSource = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; this.nativeTarget = this.managedSource.GetNativeSpaceHints(); this.nativeSource = new NATIVE_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = 0x12, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; this.managedTarget = new JET_SPACEHINTS(); this.managedTarget.SetFromNativeSpaceHints(this.nativeSource); }
public void Setup() { this.managedSource = new JET_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = SpaceHintsGrbit.CreateHintAppendSequential | SpaceHintsGrbit.RetrieveHintTableScanForward, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; this.nativeTarget = this.managedSource.GetNativeSpaceHints(); this.nativeSource = new NATIVE_SPACEHINTS() { ulInitialDensity = 33, cbInitial = 4096, grbit = 0x12, ulMaintDensity = 44, ulGrowth = 144, cbMinExtent = 1024 * 1024, cbMaxExtent = 3 * 1024 * 1024, }; this.managedTarget = new JET_SPACEHINTS(); this.managedTarget.SetFromNativeSpaceHints(this.nativeSource); }
/// <summary> /// Make native indexcreate structures from the managed ones. /// </summary> /// <param name="managedIndexCreates">Index create structures to convert.</param> /// <param name="handles">The handle collection used to pin the data.</param> /// <returns>Pinned native versions of the index creates.</returns> private static unsafe NATIVE_INDEXCREATE3[] GetNativeIndexCreate3s( IList <JET_INDEXCREATE> managedIndexCreates, ref GCHandleCollection handles) { NATIVE_INDEXCREATE3[] nativeIndices = null; if (managedIndexCreates != null && managedIndexCreates.Count > 0) { nativeIndices = new NATIVE_INDEXCREATE3[managedIndexCreates.Count]; for (int i = 0; i < managedIndexCreates.Count; ++i) { nativeIndices[i] = managedIndexCreates[i].GetNativeIndexcreate3(); if (null != managedIndexCreates[i].pidxUnicode) { NATIVE_UNICODEINDEX2 unicode = managedIndexCreates[i].pidxUnicode.GetNativeUnicodeIndex2(); unicode.szLocaleName = handles.Add(Util.ConvertToNullTerminatedUnicodeByteArray(managedIndexCreates[i].pidxUnicode.GetEffectiveLocaleName())); nativeIndices[i].pidxUnicode = (NATIVE_UNICODEINDEX2 *)handles.Add(unicode); nativeIndices[i].grbit |= (uint)VistaGrbits.IndexUnicode; } nativeIndices[i].szKey = handles.Add(Util.ConvertToNullTerminatedUnicodeByteArray(managedIndexCreates[i].szKey)); nativeIndices[i].szIndexName = handles.Add(Util.ConvertToNullTerminatedUnicodeByteArray(managedIndexCreates[i].szIndexName)); nativeIndices[i].rgconditionalcolumn = GetNativeConditionalColumns(managedIndexCreates[i].rgconditionalcolumn, true, ref handles); // Convert pSpaceHints. if (managedIndexCreates[i].pSpaceHints != null) { NATIVE_SPACEHINTS nativeSpaceHints = managedIndexCreates[i].pSpaceHints.GetNativeSpaceHints(); nativeIndices[i].pSpaceHints = handles.Add(nativeSpaceHints); } } } return(nativeIndices); }
/// <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(ref nativeTableCreate.rgcolumncreate[i]); } } if (tablecreate.rgindexcreate != null) { for (int i = 0; i < tablecreate.rgindexcreate.Length; ++i) { tablecreate.rgindexcreate[i].SetFromNativeIndexCreate(ref nativeIndexCreates[i]); } } return(Err(err)); } finally { handles.Dispose(); } } }