public void Setup() { this.managed = new JET_OPENTEMPORARYTABLE() { prgcolumndef = new JET_COLUMNDEF[2], prgcolumnid = new JET_COLUMNID[2], ccolumn = 2, grbit = TempTableGrbit.SortNullsHigh, cbKeyMost = 3, cbVarSegMac = 4, }; this.native = this.managed.GetNativeOpenTemporaryTable(); }
public void VerifyXpThrowsExceptionOnJetOpenTemporaryTable() { var sesid = new JET_SESID(); var temporarytable = new JET_OPENTEMPORARYTABLE(); VistaApi.JetOpenTemporaryTable(sesid, temporarytable); }
/// <summary> /// Creates a temporary table with a single index. A temporary table /// stores and retrieves records just like an ordinary table created /// using JetCreateTableColumnIndex. However, temporary tables are /// much faster than ordinary tables due to their volatile nature. /// They can also be used to very quickly sort and perform duplicate /// removal on record sets when accessed in a purely sequential manner. /// </summary> /// <param name="sesid">The session to use.</param> /// <param name="temporarytable"> /// Description of the temporary table to create on input. After a /// successful call, the structure contains the handle to the temporary /// table and column identifications. /// </param> /// <returns>An error code.</returns> public int JetOpenTemporaryTable2(JET_SESID sesid, JET_OPENTEMPORARYTABLE temporarytable) { TraceFunctionCall("JetOpenTemporaryTable2"); this.CheckSupportsWindows8Features("JetOpenTemporaryTable2"); CheckNotNull(temporarytable, "temporarytable"); NATIVE_OPENTEMPORARYTABLE2 nativetemporarytable = temporarytable.GetNativeOpenTemporaryTable2(); var nativecolumnids = new uint[nativetemporarytable.ccolumn]; NATIVE_COLUMNDEF[] nativecolumndefs = GetNativecolumndefs(temporarytable.prgcolumndef, temporarytable.ccolumn); unsafe { using (var gchandlecollection = new GCHandleCollection()) { // Pin memory nativetemporarytable.prgcolumndef = (NATIVE_COLUMNDEF*)gchandlecollection.Add(nativecolumndefs); nativetemporarytable.rgcolumnid = (uint*)gchandlecollection.Add(nativecolumnids); if (null != temporarytable.pidxunicode) { NATIVE_UNICODEINDEX2 unicode = temporarytable.pidxunicode.GetNativeUnicodeIndex2(); unicode.szLocaleName = gchandlecollection.Add(Util.ConvertToNullTerminatedUnicodeByteArray(temporarytable.pidxunicode.GetEffectiveLocaleName())); nativetemporarytable.pidxunicode = (NATIVE_UNICODEINDEX2*)gchandlecollection.Add(unicode); } // Call the interop method int err = Err(NativeMethods.JetOpenTemporaryTable2(sesid.Value, ref nativetemporarytable)); // Convert the return values SetColumnids(temporarytable.prgcolumndef, temporarytable.prgcolumnid, nativecolumnids, temporarytable.ccolumn); temporarytable.tableid = new JET_TABLEID { Value = nativetemporarytable.tableid }; return err; } } }
public void SortDataCaseSensitiveWithJetOpenTemporaryTable() { if (!EsentVersion.SupportsVistaFeatures) { return; } 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), lcid = 1033, }; var opentemporarytable = new JET_OPENTEMPORARYTABLE { cbKeyMost = SystemParameters.KeyMost, ccolumn = columns.Length, grbit = TempTableGrbit.Scrollable, pidxunicode = idxunicode, prgcolumndef = columns, prgcolumnid = columnids, }; VistaApi.JetOpenTemporaryTable(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); CollectionAssert.AreEqual( data, this.RetrieveAllRecordsAsString(opentemporarytable.tableid, columnids[0]).ToArray()); Api.JetCloseTable(this.session, opentemporarytable.tableid); }
public void VerifyJetOpenTemporaryTableThrowsExceptionWhenColumnCountIsTooLong() { if (!EsentVersion.SupportsVistaFeatures) { throw new ArgumentOutOfRangeException(); } var opentemporarytable = new JET_OPENTEMPORARYTABLE { prgcolumndef = new[] { new JET_COLUMNDEF() }, ccolumn = 2, prgcolumnid = new JET_COLUMNID[1], }; VistaApi.JetOpenTemporaryTable(this.sesid, opentemporarytable); }
public void VerifyJetOpenTemporaryTableThrowsExceptionWhenColumnidsIsNull() { if (!EsentVersion.SupportsVistaFeatures) { throw new ArgumentNullException(); } var opentemporarytable = new JET_OPENTEMPORARYTABLE { prgcolumndef = new[] { new JET_COLUMNDEF() }, ccolumn = 1, }; VistaApi.JetOpenTemporaryTable(this.sesid, opentemporarytable); }
// create a temp table and insert some records private void CreateTempTable() { Console.WriteLine("\tTemporary Table"); Api.JetBeginTransaction(this.sesid); var ci = new CultureInfo("en-us"); var tt = new JET_OPENTEMPORARYTABLE(); tt.prgcolumndef = new JET_COLUMNDEF[2]; tt.ccolumn = 2; tt.pidxunicode = new JET_UNICODEINDEX(); tt.pidxunicode.lcid = ci.LCID; tt.pidxunicode.dwMapFlags = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.IgnoreCase); tt.grbit = TempTableGrbit.Indexed; tt.prgcolumndef[0] = new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey }; tt.prgcolumndef[1] = new JET_COLUMNDEF { coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, grbit = ColumndefGrbit.TTKey }; tt.prgcolumnid = new JET_COLUMNID[tt.prgcolumndef.Length]; VistaApi.JetOpenTemporaryTable(this.sesid, tt); JET_TABLEID tableid = tt.tableid; for (int i = 0; i <= 5; ++i) { int key = 5 - i; string s = String.Format("Record {0}", i); Api.JetPrepareUpdate(this.sesid, tableid, JET_prep.Insert); Api.SetColumn(this.sesid, tableid, tt.prgcolumnid[0], key); Api.SetColumn(this.sesid, tableid, tt.prgcolumnid[1], s, Encoding.Unicode); Api.JetUpdate(this.sesid, tableid); } int expectedKey = 0; Api.MoveBeforeFirst(this.sesid, tableid); while (Api.TryMoveNext(this.sesid, tableid)) { int actualKey = Api.RetrieveColumnAsInt32(this.sesid, tableid, tt.prgcolumnid[0]).Value; BasicClass.Assert( expectedKey == actualKey, String.Format("Temp table isn't sorted correctly (expected = {0}, actual = {1})", expectedKey, actualKey)); expectedKey++; } Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); Api.JetCloseTable(this.sesid, tableid); }
public void JetOpentemporarytableToString() { var value = new JET_OPENTEMPORARYTABLE { grbit = TempTableGrbit.Indexed }; Assert.AreEqual("JET_OPENTEMPORARYTABLE(Indexed, 0 columns)", value.ToString()); }
/// <summary> /// Creates a temporary table with a single index. A temporary table /// stores and retrieves records just like an ordinary table created /// using JetCreateTableColumnIndex. However, temporary tables are /// much faster than ordinary tables due to their volatile nature. /// They can also be used to very quickly sort and perform duplicate /// removal on record sets when accessed in a purely sequential manner. /// Also see /// <seealso cref="Api.JetOpenTempTable"/>, /// "Api.JetOpenTempTable2", /// <seealso cref="Api.JetOpenTempTable3"/>. /// <seealso cref="VistaApi.JetOpenTemporaryTable"/>. /// </summary> /// <remarks> /// Use <see cref="VistaApi.JetOpenTemporaryTable"/> /// for earlier versions of Esent. /// </remarks> /// <param name="sesid">The session to use.</param> /// <param name="temporarytable"> /// Description of the temporary table to create on input. After a /// successful call, the structure contains the handle to the temporary /// table and column identifications. Use <see cref="Api.JetCloseTable"/> /// to free the temporary table when finished. /// </param> public static void JetOpenTemporaryTable2(JET_SESID sesid, JET_OPENTEMPORARYTABLE temporarytable) { Api.Check(Api.Impl.JetOpenTemporaryTable2(sesid, temporarytable)); }