public void TestEnumerateZeroLengthColumn() { Api.JetBeginTransaction(this.sesid); Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert); Api.SetColumn(this.sesid, this.tableid, this.columnidDict["binary"], new byte[0]); Api.JetUpdate(this.sesid, this.tableid); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None); int numValues; JET_ENUMCOLUMN[] values; JET_PFNREALLOC allocator = (context, pv, cb) => IntPtr.Zero == pv?EseInteropTestHelper.MarshalAllocHGlobal(new IntPtr(cb)) : EseInteropTestHelper.MarshalReAllocHGlobal(pv, new IntPtr(cb)); Api.JetEnumerateColumns( this.sesid, this.tableid, 0, null, out numValues, out values, allocator, IntPtr.Zero, 0, EnumerateColumnsGrbit.EnumerateCompressOutput); Assert.AreEqual(1, numValues); Assert.IsNotNull(values); Assert.AreEqual(this.columnidDict["binary"], values[0].columnid); Assert.AreEqual(JET_wrn.ColumnSingleValue, values[0].err); Assert.AreEqual(0, values[0].cbData); allocator(IntPtr.Zero, values[0].pvData, 0); // free the memory }
public void TestEnumerateOneMultivalueColumn() { const int Expected1 = 123; const int Expected2 = 456; Api.JetBeginTransaction(this.sesid); Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert); this.SetColumn(this.columnidDict["int32"], BitConverter.GetBytes(Expected1), 0); this.SetColumn(this.columnidDict["int32"], BitConverter.GetBytes(Expected2), 0); Api.JetUpdate(this.sesid, this.tableid); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None); int numValues; JET_ENUMCOLUMN[] values; JET_PFNREALLOC allocator = (context, pv, cb) => IntPtr.Zero == pv?EseInteropTestHelper.MarshalAllocHGlobal(new IntPtr(cb)) : EseInteropTestHelper.MarshalReAllocHGlobal(pv, new IntPtr(cb)); Api.JetEnumerateColumns( this.sesid, this.tableid, 0, null, out numValues, out values, allocator, IntPtr.Zero, 0, EnumerateColumnsGrbit.None); Assert.AreEqual(1, numValues); Assert.IsNotNull(values); Assert.AreEqual(this.columnidDict["int32"], values[0].columnid); Assert.AreEqual(JET_wrn.Success, values[0].err); Assert.AreEqual(2, values[0].cEnumColumnValue); int actual1 = Marshal.ReadInt32(values[0].rgEnumColumnValue[0].pvData); allocator(IntPtr.Zero, values[0].rgEnumColumnValue[0].pvData, 0); // free the memory int actual2 = Marshal.ReadInt32(values[0].rgEnumColumnValue[1].pvData); allocator(IntPtr.Zero, values[0].rgEnumColumnValue[1].pvData, 0); // free the memory Assert.AreEqual(Expected1, actual1); Assert.AreEqual(Expected2, actual2); }
/// <summary> /// Repeatedly retrieve one record using /// <see cref="Api.JetEnumerateColumns(JET_SESID, JET_TABLEID, /// int, JET_ENUMCOLUMNID[], out int, out JET_ENUMCOLUMN[], /// JET_PFNREALLOC, IntPtr, int, EnumerateColumnsGrbit)"/>. /// </summary> /// <param name="numRetrieves">The number of times to retrieve the record.</param> public void RepeatedlyRetrieveOneRecordWithEnumColumns(int numRetrieves) { this.SeekToLastRecordInserted(); var columnids = new[] { new JET_ENUMCOLUMNID { columnid = this.columnidKey }, new JET_ENUMCOLUMNID { columnid = this.columnidData }, }; JET_PFNREALLOC allocator = (context, pv, cb) => IntPtr.Zero == pv?EseInteropTestHelper.MarshalAllocHGlobal(new IntPtr(cb)) : EseInteropTestHelper.MarshalReAllocHGlobal(pv, new IntPtr(cb)); for (int i = 0; i < numRetrieves; ++i) { Api.JetBeginTransaction(this.session); int numValues; JET_ENUMCOLUMN[] values; Api.JetEnumerateColumns( this.session, this.table, columnids.Length, columnids, out numValues, out values, allocator, IntPtr.Zero, 0, EnumerateColumnsGrbit.EnumerateCompressOutput); Marshal.ReadInt32(values[0].pvData); allocator(IntPtr.Zero, values[0].pvData, 0); allocator(IntPtr.Zero, values[1].pvData, 0); Api.JetCommitTransaction(this.session, CommitTransactionGrbit.None); } }
public void TestEnumerateSpecificColumnsAndTags() { const short Expected16 = 2; const int Expected32 = 100; const long Expected64 = 9999; Api.JetBeginTransaction(this.sesid); Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert); this.SetColumn(this.columnidDict["int16"], BitConverter.GetBytes(short.MinValue), 0); // itag 1 this.SetColumn(this.columnidDict["int16"], BitConverter.GetBytes(Expected16), 0); // itag 2 this.SetColumn(this.columnidDict["int16"], BitConverter.GetBytes(short.MaxValue), 0); // itag 3 this.SetColumn(this.columnidDict["int32"], BitConverter.GetBytes(Expected32), 0); this.SetColumn(this.columnidDict["int64"], BitConverter.GetBytes(long.MinValue), 0); // itag 1 this.SetColumn(this.columnidDict["int64"], BitConverter.GetBytes(long.MaxValue), 0); // itag 2 this.SetColumn(this.columnidDict["int64"], BitConverter.GetBytes(Expected64), 0); // itag 3 this.SetColumn(this.columnidDict["unicode"], Encoding.Unicode.GetBytes("test"), 0); this.SetColumn(this.columnidDict["ascii"], LibraryHelpers.EncodingASCII.GetBytes("test"), 0); Api.JetUpdate(this.sesid, this.tableid); Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush); Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None); var columnids = new[] { new JET_ENUMCOLUMNID { columnid = this.columnidDict["int16"], ctagSequence = 1, rgtagSequence = new[] { 2 } }, new JET_ENUMCOLUMNID { columnid = this.columnidDict["int64"], ctagSequence = 1, rgtagSequence = new[] { 3 } }, }; int numValues; JET_ENUMCOLUMN[] values; JET_PFNREALLOC allocator = (context, pv, cb) => IntPtr.Zero == pv?EseInteropTestHelper.MarshalAllocHGlobal(new IntPtr(cb)) : EseInteropTestHelper.MarshalReAllocHGlobal(pv, new IntPtr(cb)); Api.JetEnumerateColumns( this.sesid, this.tableid, columnids.Length, columnids, out numValues, out values, allocator, IntPtr.Zero, 0, EnumerateColumnsGrbit.None); Assert.AreEqual(2, numValues); Assert.IsNotNull(values); Assert.AreEqual(this.columnidDict["int16"], values[0].columnid); Assert.AreEqual(this.columnidDict["int64"], values[1].columnid); Assert.AreEqual(JET_wrn.Success, values[0].err); Assert.AreEqual(JET_wrn.Success, values[1].err); Assert.AreEqual(1, values[0].cEnumColumnValue); Assert.AreEqual(1, values[1].cEnumColumnValue); Assert.AreEqual(2, values[0].rgEnumColumnValue[0].itagSequence); Assert.AreEqual(3, values[1].rgEnumColumnValue[0].itagSequence); short actual16 = Marshal.ReadInt16(values[0].rgEnumColumnValue[0].pvData); allocator(IntPtr.Zero, values[0].rgEnumColumnValue[0].pvData, 0); // free the memory long actual64 = Marshal.ReadInt64(values[1].rgEnumColumnValue[0].pvData); allocator(IntPtr.Zero, values[1].rgEnumColumnValue[0].pvData, 0); // free the memory Assert.AreEqual(Expected16, actual16); Assert.AreEqual(Expected64, actual64); }