public void Create(JET_SESID session, JET_DBID dbid)
        {
            using (var tran = new Transaction(session))
            {
                JET_TABLEID tblID;
                Api.JetCreateTable(session, dbid, tableName, 1, 80, out tblID);

                JET_COLUMNID c;
                Api.JetAddColumn(session, tblID, colName_ID, new JET_COLUMNDEF()
                {
                    coltyp = JET_coltyp.Currency,
                    grbit = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL,
                }, null, 0, out c);

                Api.JetAddColumn(session, tblID, colName_LogID, new JET_COLUMNDEF()
                {
                    coltyp = JET_coltyp.Currency,
                    grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL,
                }, null, 0, out c);

                var indexDef = "+" + colName_ID + "\0\0";
                Api.JetCreateIndex(session, tblID, idxName_Primary, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 80);

                tran.Commit(CommitTransactionGrbit.None);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the Table class. The table is
 /// opened from the given database.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="dbid">The database to open the table in.</param>
 /// <param name="name">The name of the table.</param>
 /// <param name="grbit">JetOpenTable options.</param>
 public Table(JET_SESID sesid, JET_DBID dbid, string name, OpenTableGrbit grbit)
 {
     this.sesid = sesid;
     this.name = name;
     Api.JetOpenTable(this.sesid, dbid, this.name, null, 0, grbit, out this.tableid);
     this.ResourceWasAllocated();
 }
Beispiel #3
0
        /// <summary>
        /// The JetSetColumn function modifies a single column value in a modified record to be inserted or to
        /// update the current record. It can overwrite an existing value, add a new value to a sequence of
        /// values in a multi-valued column, remove a value from a sequence of values in a multi-valued column,
        /// or update all or part of a long value (a column of type <see cref="JET_coltyp.LongText"/>
        /// or <see cref="JET_coltyp.LongBinary"/>). 
        /// </summary>
        /// <remarks>
        /// This is an internal-only version of the API that takes a data buffer and an offset into the buffer.
        /// </remarks>
        /// <param name="sesid">The session which is performing the update.</param>
        /// <param name="tableid">The cursor to update. An update should be prepared.</param>
        /// <param name="columnid">The columnid to set.</param>
        /// <param name="data">The data to set.</param>
        /// <param name="dataSize">The size of data to set.</param>
        /// <param name="dataOffset">The offset in the data buffer to set data from.</param>
        /// <param name="grbit">SetColumn options.</param>
        /// <param name="setinfo">Used to specify itag or long-value offset.</param>
        /// <returns>A warning value.</returns>
        public static JET_wrn JetSetColumn(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, byte[] data, int dataSize, int dataOffset, SetColumnGrbit grbit, JET_SETINFO setinfo)
        {
            if (dataOffset < 0
                || (null != data && 0 != dataSize && dataOffset >= data.Length)
                || (null == data && dataOffset != 0))
            {
                throw new ArgumentOutOfRangeException(
                    "dataOffset",
                    dataOffset,
                    "must be inside the data buffer");                    
            }

            if (null != data && dataSize > checked(data.Length - dataOffset) && (SetColumnGrbit.SizeLV != (grbit & SetColumnGrbit.SizeLV)))
            {
                throw new ArgumentOutOfRangeException(
                    "dataSize",
                    dataSize,
                    "cannot be greater than the length of the data (unless the SizeLV option is used)");
            }

            unsafe
            {
                fixed (byte* pointer = data)
                {
                    return Api.JetSetColumn(sesid, tableid, columnid, new IntPtr(pointer + dataOffset), dataSize, grbit, setinfo);
                }
            }
        }
Beispiel #4
0
		private static void CreateIndexingEtagsTable(JET_DBID dbid, JET_SESID session)
		{
			JET_TABLEID tableid;
			Api.JetCreateTable(session, dbid, "indexes_etag", 16, 100, out tableid);
			JET_COLUMNID columnid;

			Api.JetAddColumn(session, tableid, "key", new JET_COLUMNDEF
			{
				cbMax = 255,
				coltyp = JET_coltyp.Text,
				cp = JET_CP.Unicode,
				grbit = ColumndefGrbit.ColumnTagged
			}, null, 0, out columnid);

			var defaultValue = BitConverter.GetBytes(0);
			Api.JetAddColumn(session, tableid, "touches", new JET_COLUMNDEF
			{
				coltyp = JET_coltyp.Long,
				grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnEscrowUpdate
			}, defaultValue, defaultValue.Length, out columnid);

			const string indexDef = "+key\0\0";
			Api.JetCreateIndex(session, tableid, "by_key", CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length,
							   100);
		}
        internal static void CreateTable(JET_SESID sesid, JET_DBID dbid)
        {
            JET_TABLEID tableid;
            Api.JetCreateTable(sesid, dbid, GeometryTableName, 8, 80, out tableid);

            using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid))
            {
                JET_COLUMNID columnid;

                var columndef = new JET_COLUMNDEF
                {
                    coltyp = JET_coltyp.Long,
                    grbit = ColumndefGrbit.ColumnAutoincrement
                };

                Api.JetAddColumn(sesid, tableid, colNameGeometryLabel, columndef, null, 0, out columnid);

                columndef.grbit = ColumndefGrbit.ColumnNotNULL;

                Api.JetAddColumn(sesid, tableid, colNameProductLabel, columndef, null, 0, out columnid);

                columndef.coltyp = JET_coltyp.UnsignedByte;
                Api.JetAddColumn(sesid, tableid, colNameGeomType, columndef, null, 0, out columnid);
                
                columndef.coltyp = JET_coltyp.Short;
                Api.JetAddColumn(sesid, tableid, colNameProductIfcTypeId, columndef, null, 0, out columnid);
                Api.JetAddColumn(sesid, tableid, colNameSubPart, columndef, null, 0, out columnid);
               

                columndef.coltyp = JET_coltyp.Binary;
                columndef.grbit = ColumndefGrbit.ColumnMaybeNull;
                Api.JetAddColumn(sesid, tableid, colNameTransformMatrix, columndef, null, 0, out columnid);
               
                columndef.coltyp = JET_coltyp.LongBinary;
                //if (EsentVersion.SupportsWindows7Features)
                //    columndef.grbit |= Windows7Grbits.ColumnCompressed;
                Api.JetAddColumn(sesid, tableid, colNameShapeData, columndef, null, 0, out columnid);

                columndef.coltyp = JET_coltyp.Long;
                columndef.grbit = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameGeometryHash, columndef, null, 0, out columnid);
                columndef.grbit = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameStyleLabel, columndef, null, 0, out columnid);
                // The primary index is the type and the entity label.
                string indexDef = string.Format("+{0}\0\0", colNameGeometryLabel);
                Api.JetCreateIndex(sesid, tableid, geometryTablePrimaryIndex, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100);
                //create index by geometry hashes    
                indexDef = string.Format("+{0}\0\0", colNameGeometryHash);
                Api.JetCreateIndex(sesid, tableid, geometryTableHashIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100);
                //Create index by product
                indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0{4}\0\0", colNameGeomType, colNameProductIfcTypeId, colNameProductLabel, colNameSubPart, colNameStyleLabel);
                Api.JetCreateIndex(sesid, tableid, geometryTableGeomTypeIndex, CreateIndexGrbit.IndexUnique, indexDef, indexDef.Length, 100);
                //create index by style
                indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0{4}\0\0", colNameGeomType, colNameStyleLabel, colNameProductIfcTypeId, colNameProductLabel, colNameGeometryLabel);
                Api.JetCreateIndex(sesid, tableid, geometryTableStyleIndex, CreateIndexGrbit.None, indexDef, indexDef.Length, 100);
                Api.JetCloseTable(sesid, tableid);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }
           
        }
Beispiel #6
0
        /// <summary>
        /// Intersect a group of index ranges and return the bookmarks of the records which are found
        /// in all the index ranges. 
        /// Also see <see cref="JetIntersectIndexes"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableids">
        /// The tableids to use. Each tableid must be from a different index on the same table and
        /// have an active index range. Use <see cref="JetSetIndexRange"/>
        /// to create an index range.
        /// </param>
        /// <returns>
        /// The bookmarks of the records which are found in all the index ranges. The bookmarks 
        /// are returned in primary key order.
        /// </returns>
        public static IEnumerable<byte[]> IntersectIndexes(JET_SESID sesid, params JET_TABLEID[] tableids)
        {
            if (null == tableids)
            {
                throw new ArgumentNullException("tableids");
            }

            JET_RECORDLIST recordlist;

            var ranges = new JET_INDEXRANGE[tableids.Length];
            for (int i = 0; i < tableids.Length; ++i)
            {
                ranges[i] = new JET_INDEXRANGE { tableid = tableids[i] };
            }

            Api.JetIntersectIndexes(sesid, ranges, ranges.Length, out recordlist, IntersectIndexesGrbit.None);

            try
            {
                Api.MoveBeforeFirst(sesid, recordlist.tableid);
                while (Api.TryMoveNext(sesid, recordlist.tableid))
                {
                    yield return Api.RetrieveColumn(sesid, recordlist.tableid, recordlist.columnidBookmark);
                }
            }
            finally
            {
                Api.JetCloseTable(sesid, recordlist.tableid);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Sets a parameter on the provided session state, used for the lifetime of this session or until reset.
 /// </summary>
 /// <param name="sesid">The session to set the parameter on.</param>
 /// <param name="sesparamid">The ID of the session parameter to retrieve.</param>
 /// <param name="operationContext">An operation context to retrieve.</param>
 /// <seealso cref="JET_OPERATIONCONTEXT"/>
 public static void JetGetSessionParameter(
     JET_SESID sesid,
     JET_sesparam sesparamid,
     out JET_OPERATIONCONTEXT operationContext)
 {
     Api.Check(Api.Impl.JetGetSessionParameter(sesid, sesparamid, out operationContext));
 }
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var identifierColumnCreate = CreateIdColumn(IdentifierColumnName);
                var locationsColumnCreate = CreateBinaryColumn(LocationsColumnName);

                var columns = CreateProjectDocumentColumns(identifierColumnCreate, locationsColumnCreate);

                var primaryIndexKey = CreateProjectDocumentIndexKey(IdentifierColumnName);

                var indexes = new JET_INDEXCREATE[]
                {
                    CreatePrimaryIndex(primaryIndexKey)
                };

                var tableCreate = CreateTable(TableName, columns, indexes);

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                GetColumnIds(columns, out _projectColumnId, out _projectNameColumnId, out _documentColumnId);

                _identifierColumnId = identifierColumnCreate.columnid;
                _locationsColumnId = locationsColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
Beispiel #9
0
        /// <summary>
        /// Retrieves a single column value from the current record. The record is that
        /// record associated with the index entry at the current position of the cursor.
        /// Alternatively, this function can retrieve a column from a record being created
        /// in the cursor copy buffer. This function can also retrieve column data from an
        /// index entry that references the current record. In addition to retrieving the
        /// actual column value, JetRetrieveColumn can also be used to retrieve the size
        /// of a column, before retrieving the column data itself so that application
        /// buffers can be sized appropriately.  
        /// </summary>
        /// <remarks>
        /// This is an internal method that takes a buffer offset as well as size.
        /// </remarks>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to retrieve the column from.</param>
        /// <param name="columnid">The columnid to retrieve.</param>
        /// <param name="data">The data buffer to be retrieved into.</param>
        /// <param name="dataSize">The size of the data buffer.</param>
        /// <param name="dataOffset">Offset into the data buffer to read data into.</param>
        /// <param name="actualDataSize">Returns the actual size of the data buffer.</param>
        /// <param name="grbit">Retrieve column options.</param>
        /// <param name="retinfo">
        /// If pretinfo is give as NULL then the function behaves as though an itagSequence
        /// of 1 and an ibLongValue of 0 (zero) were given. This causes column retrieval to
        /// retrieve the first value of a multi-valued column, and to retrieve long data at
        /// offset 0 (zero).
        /// </param>
        /// <returns>An ESENT warning code.</returns>
        public static JET_wrn JetRetrieveColumn(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, byte[] data, int dataSize, int dataOffset, out int actualDataSize, RetrieveColumnGrbit grbit, JET_RETINFO retinfo)
        {
            if (dataOffset < 0
                || (null != data && 0 != dataSize && dataOffset >= data.Length)
                || (null == data && dataOffset != 0))
            {
                throw new ArgumentOutOfRangeException(
                    "dataOffset",
                    dataOffset,
                    "must be inside the data buffer");
            }

            if ((null == data && dataSize > 0) || (null != data && dataSize > data.Length))
            {
                throw new ArgumentOutOfRangeException(
                    "dataSize",
                    dataSize,
                    "cannot be greater than the length of the data");
            }

            unsafe
            {
                fixed (byte* pointer = data)
                {
                    return Api.JetRetrieveColumn(
                        sesid, tableid, columnid, new IntPtr(pointer + dataOffset), dataSize, out actualDataSize, grbit, retinfo);
                }
            }
        }
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, (IntPtr) buffer, data.Length * sizeof(char), grbit);
                    }
                }
            }
            else
            {
                byte[] bytes = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, bytes, bytes.Length, grbit);
            }
        }
Beispiel #11
0
        public bool Add(JET_SESID session, JET_TABLEID table, int level)
        {
            byte[] buffer;
            int actualBookmarkSize;

            var largeBuffer = IndexReaderBuffers.Buffers.TakeBuffer(bookmarkMost);
            try
            {
                Api.JetGetBookmark(session, table, largeBuffer,
                                   largeBuffer.Length, out actualBookmarkSize);

                buffer = new byte[actualBookmarkSize];
                Buffer.BlockCopy(largeBuffer, 0, buffer, 0, actualBookmarkSize);
            }
            finally
            {
                IndexReaderBuffers.Buffers.ReturnBuffer(largeBuffer);
            }
            var res = itemsToDelete.TryAdd(new Key(buffer, actualBookmarkSize));
            if (res)
            {
                itemsToDeletePerViewAndLevel.DecrementPerLevelCounters(level);
            }
            return res;
        }
 protected void GetColumnIds(
     JET_SESID sessionId, Table table, out JET_COLUMNID projectColumnId, out JET_COLUMNID projectNameColumnId, out JET_COLUMNID documentColumnId)
 {
     projectColumnId = Api.GetTableColumnid(sessionId, table, ProjectColumnName);
     projectNameColumnId = Api.GetTableColumnid(sessionId, table, ProjectNameColumnName);
     documentColumnId = Api.GetTableColumnid(sessionId, table, DocumentColumnName);
 }
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                var idColumnCreate = CreateAutoIncrementIdColumn(IdColumnName);
                var identifierColumnCreate = CreateTextColumn(IdentifierColumnName);

                var columns = new JET_COLUMNCREATE[] { idColumnCreate, identifierColumnCreate };

                var primaryIndexKey = CreateIndexKey(IdColumnName);
                var identifierIndexKey = CreateIndexKey(IdentifierColumnName);

                var indexes = new JET_INDEXCREATE[]
                {
                    CreatePrimaryIndex(primaryIndexKey),
                    CreateUniqueTextIndex(IdentifierIndexName, identifierIndexKey)
                };

                var tableCreate = CreateTable(TableName, columns, indexes);

                Api.JetCreateTableColumnIndex3(sessionId, databaseId, tableCreate);

                _idColumnId = idColumnCreate.columnid;
                _identifierColumnId = identifierColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
            private JET_DBID OpenExistingDatabase(JET_SESID session, string databaseFile)
            {
                JET_DBID databaseId;
                Api.JetOpenDatabase(SessionId, databaseFile, null, out databaseId, OpenDatabaseGrbit.None);

                return databaseId;
            }
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked(data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
            #if MANAGEDESENT_ON_WSA
                // Encoding.GetBytes(char*, int, byte*, int) overload is missing in new Windows UI.
                // So we can't use the ColumnCache. We'll just use a different GetBytes() overload.
                byte[] buffer = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, buffer, buffer.Length, grbit);
            #else
                // Convert the string using a cached column buffer. The column buffer is far larger
                // than the maximum key size, so any data truncation here won't matter.
                byte[] buffer = null;
                try
                {
                    buffer = Caches.ColumnCache.Allocate();
                    int dataSize;
                    unsafe
                    {
                        fixed (char* chars = data)
                        fixed (byte* bytes = buffer)
                        {
                            dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                        }
                    }

                    JetMakeKey(sesid, tableid, buffer, dataSize, grbit);
                }
                finally
                {
                    if (buffer != null)
                    {
                        Caches.ColumnCache.Free(ref buffer);
                    }
                }
            #endif
            }
        }
Beispiel #16
0
 /// <summary>
 /// Creates indexes over data in an ESE database.
 /// </summary>
 /// <remarks>
 /// When creating multiple indexes (i.e. with numIndexCreates
 /// greater than 1) this method MUST be called
 /// outside of any transactions and with exclusive access to the
 /// table. The JET_TABLEID returned by "Api.JetCreateTable"
 /// will have exlusive access or the table can be opened for
 /// exclusive access by passing <see cref="OpenTableGrbit.DenyRead"/>
 /// to <see cref="Api.JetOpenTable"/>.
 /// </remarks>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table to create the index on.</param>
 /// <param name="indexcreates">Array of objects describing the indexes to be created.</param>
 /// <param name="numIndexCreates">Number of index description objects.</param>
 public static void JetCreateIndex4(
     JET_SESID sesid,
     JET_TABLEID tableid,
     JET_INDEXCREATE[] indexcreates,
     int numIndexCreates)
 {
     Api.Check(Api.Impl.JetCreateIndex4(sesid, tableid, indexcreates, numIndexCreates));
 }
Beispiel #17
0
 /// <summary>
 /// Retrieves information about a table column.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table containing the column.</param>
 /// <param name="columnid">The columnid of the column.</param>
 /// <param name="columnbase">Filled in with information about the column.</param>
 public static void JetGetTableColumnInfo(
     JET_SESID sesid,
     JET_TABLEID tableid,
     JET_COLUMNID columnid,
     out JET_COLUMNBASE columnbase)
 {
     Api.Check(Api.Impl.JetGetTableColumnInfo(sesid, tableid, columnid, out columnbase));
 }
Beispiel #18
0
 /// <summary>
 /// Commits the changes made to the state of the database during the current save point
 /// and migrates them to the previous save point. If the outermost save point is committed
 /// then the changes made during that save point will be committed to the state of the
 /// database and the session will exit the transaction.
 /// </summary>
 /// <param name="sesid">The session to commit the transaction for.</param>
 /// <param name="grbit">Commit options.</param>
 /// <param name="durableCommit">Duration to commit lazy transaction.</param>
 /// <param name="commitId">Commit-id associated with this commit record.</param>
 public static void JetCommitTransaction2(
     JET_SESID sesid,
     CommitTransactionGrbit grbit,
     TimeSpan durableCommit,
     out JET_COMMIT_ID commitId)
 {
     Api.Check(Api.Impl.JetCommitTransaction2(sesid, grbit, durableCommit, out commitId));
 }
 /// <summary>
 /// Retrieves information about indexes on a table.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="indexname">The name of the index.</param>
 /// <param name="result">Filled in with information about indexes on the table.</param>
 /// <param name="infoLevel">The type of information to retrieve.</param>
 protected override void GetIndexInfo(
         JET_SESID sesid,
         string indexname,
         out string result,
         JET_IdxInfo infoLevel)
 {
     Api.JetGetTableIndexInfo(sesid, this.tableid, indexname, out result, infoLevel);
 }
 public override void Initialize(JET_SESID sessionId, JET_DBID databaseId)
 {
     using (var table = new Table(sessionId, databaseId, TableName, OpenTableGrbit.ReadOnly))
     {
         _idColumnId = Api.GetTableColumnid(sessionId, table, IdColumnName);
         _identifierColumnId = Api.GetTableColumnid(sessionId, table, IdentifierColumnName);
     }
 }
Beispiel #21
0
 public static void JetGetTableIndexInfo(
     JET_SESID sesid,
     JET_TABLEID tableid,
     string indexname,
     out JET_INDEXLIST indexlist)
 {
     Api.JetGetTableIndexInfo(sesid, tableid, indexname, out indexlist, JET_IdxInfo.List);
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the ColumnStream class.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to use.</param>
 /// <param name="columnid">The columnid of the column to set/retrieve data from.</param>
 public ColumnStream(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid)
 {
     this.sesid = sesid;
     this.tableid = tableid;
     this.columnid = columnid;
     this.ibLongValue = 0;
     this.Itag = 1;
 }
Beispiel #23
0
        public static JET_TABLEID CreateTable(JET_DBID dbId, JET_SESID session, string tableName)
        {
            JET_TABLEID tableId;

            Api.JetCreateTable(session, dbId, tableName, 16, 100, out tableId);
            
            return 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);
            }
Beispiel #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TempTableHandle"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="sesid">The sesid.</param>
 /// <param name="tableid">The tableid.</param>
 /// <param name="inInsertMode">if set to <c>true</c> [in insert mode].</param>
 internal TempTableHandle(string name, JET_SESID sesid, JET_TABLEID tableid, bool inInsertMode)
 {
     this.guid = Guid.NewGuid();
     this.name = name;
     this.sesid = sesid;
     this.tableid = tableid;
     this.inInsertMode = inInsertMode;
     this.cursorCount = 0;
 }
 public void DeleteIndexRow(JET_SESID session, Transaction tran, long id)
 {
     Api.JetSetCurrentIndex(session, indexTable, idxName_Primary);
     Api.MakeKey(session, indexTable, id, MakeKeyGrbit.NewKey);
     if (Api.TrySeek(session, indexTable, SeekGrbit.SeekEQ))
     {
         Api.JetDelete(session, indexTable);
     }
 }
Beispiel #27
0
 /// <summary>
 /// Retrieves information about a column in a table.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="dbid">The database that contains the table.</param>
 /// <param name="tablename">The name of the table containing the column.</param>
 /// <param name="columnid">The ID of the column.</param>
 /// <param name="columnbase">Filled in with information about the columns in the table.</param>
 public static void JetGetColumnInfo(
         JET_SESID sesid,
         JET_DBID dbid,
         string tablename,
         JET_COLUMNID columnid,
         out JET_COLUMNBASE columnbase)
 {
     Api.Check(Api.Impl.JetGetColumnInfo(sesid, dbid, tablename, columnid, out columnbase));
 }
 public override void Initialize(JET_SESID sessionId, JET_DBID databaseId)
 {
     using (var table = new Table(sessionId, databaseId, TableName, OpenTableGrbit.ReadOnly))
     {
         GetColumnIds(sessionId, table, out _projectColumnId, out _projectNameColumnId);
         _nameColumnId = Api.GetTableColumnid(sessionId, table, NameColumnName);
         _valueColumnId = Api.GetTableColumnid(sessionId, table, ValueColumnName);
     }
 }
Beispiel #29
0
 public static void JetGetIndexInfo(
     JET_SESID sesid,
     JET_DBID dbid,
     string tablename,
     string ignored,
     out JET_INDEXLIST indexlist)
 {
     Api.JetGetIndexInfo(sesid, dbid, tablename, ignored, out indexlist, JET_IdxInfo.List);
 }
Beispiel #30
0
        private Table OpenSchema(JET_SESID sesid, JET_DBID dbid, out JET_COLUMNID primaryColumnId, out JET_COLUMNID secondaryColumnId)
        {
            var table = new Table(sesid, dbid, "table", OpenTableGrbit.None);

            primaryColumnId = Api.GetTableColumnid(sesid, table, "key");
            secondaryColumnId = Api.GetTableColumnid(sesid, table, "data");

            return table;
        }
Beispiel #31
0
 // find a record with the given recordID
 private void SeekRecord(JET_SESID sesid, JET_TABLEID tableid, int recordID)
 {
     Api.MakeKey(sesid, tableid, recordID, MakeKeyGrbit.NewKey);
     Api.JetSeek(sesid, tableid, SeekGrbit.SeekEQ);
 }
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="Api.JetSeek"/>
 /// and <see cref="Api.JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 private static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data, Encoding.Unicode, grbit);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableIndexInfoEnumerator"/> class.
 /// </summary>
 /// <param name="sesid">
 /// The session to use.
 /// </param>
 /// <param name="dbid">
 /// The database containing the table.
 /// </param>
 /// <param name="tablename">
 /// The name of the table.
 /// </param>
 public TableIndexInfoEnumerator(JET_SESID sesid, JET_DBID dbid, string tablename)
     : base(sesid)
 {
     this.dbid = dbid;
     this.tablename = tablename;
 }
Beispiel #34
0
 /// <summary>
 /// Dump all records from the index.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table to dump.</param>
 /// <param name="index">The index to use.</param>
 private static void DumpByIndex(JET_SESID sesid, JET_TABLEID tableid, string index)
 {
     Api.JetSetCurrentIndex(sesid, tableid, index);
     PrintAllRecords(sesid, tableid);
     Console.WriteLine();
 }
Beispiel #35
0
        /// <summary>
        /// Create the globals table.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="dbid">The database to create the table in.</param>
        public static void CreateGlobalsTable(JET_SESID sesid, JET_DBID dbid)
        {
            using (var transaction = new Transaction(sesid))
            {
                JET_TABLEID tableid;
                Api.JetCreateTable(sesid, dbid, GlobalsTableName, 1, 100, out tableid);
                JET_COLUMNID versionColumnid;
                Api.JetAddColumn(
                    sesid,
                    tableid,
                    VersionColumnName,
                    new JET_COLUMNDEF {
                    coltyp = JET_coltyp.LongText
                },
                    null,
                    0,
                    out versionColumnid);

                var defaultValue = BitConverter.GetBytes(0);

                JET_COLUMNID countColumnid;
                Api.JetAddColumn(
                    sesid,
                    tableid,
                    EntityCountColumnName,
                    new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate
                },
                    defaultValue,
                    defaultValue.Length,
                    out countColumnid);

                Api.JetAddColumn(
                    sesid,
                    tableid,
                    GeometryCountColumnName,
                    new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate
                },
                    defaultValue,
                    defaultValue.Length,
                    out countColumnid);

                Api.JetAddColumn(
                    sesid,
                    tableid,
                    FlushColumnName,
                    new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.ColumnEscrowUpdate
                },
                    defaultValue,
                    defaultValue.Length,
                    out countColumnid);

                Api.JetAddColumn(
                    sesid,
                    tableid,
                    ifcHeaderColumnName,
                    new JET_COLUMNDEF {
                    coltyp = JET_coltyp.LongBinary
                },
                    null,
                    0,
                    out countColumnid);

                using (var update = new Update(sesid, tableid, JET_prep.Insert))
                {
                    Api.SetColumn(sesid, tableid, versionColumnid, Version, Encoding.Unicode);
                    update.Save();
                }

                Api.JetCloseTable(sesid, tableid);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }
        }
Beispiel #36
0
 private byte[][] GetColumnsWithJetRetrieveColumn(JET_SESID sesid, JET_TABLEID tableid)
 {
     return(this.GetColumnsWithJetRetrieveColumn(sesid, tableid, RetrieveColumnGrbit.None));
 }
Beispiel #37
0
 private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     output(string.Format("Esent Restore: {0} {1} {2}", snp, snt, data));
     Console.WriteLine("Esent Restore: {0} {1} {2}", snp, snt, data);
     return(JET_err.Success);
 }
Beispiel #38
0
        private JET_err DefragmentationStatusCallback(JET_SESID sesid, JET_DBID dbId, JET_TABLEID tableId, JET_cbtyp cbtyp, object data1, object data2, IntPtr ptr1, IntPtr ptr2)
        {
            defragmentationCompleted = cbtyp == JET_cbtyp.OnlineDefragCompleted;

            return(JET_err.Success);
        }
Beispiel #39
0
        /// <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();
                }
            }
        }
Beispiel #40
0
        /// <summary>
        /// If the records with the specified key ranges are not in the
        /// buffer cache then start asynchronous reads to bring the records
        /// into the database buffer cache.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The table to issue the prereads against.</param>
        /// <param name="keysStart">The start of key ranges to preread.</param>
        /// <param name="keyStartLengths">The lengths of the start keys to preread.</param>
        /// <param name="keysEnd">The end of key rangess to preread.</param>
        /// <param name="keyEndLengths">The lengths of the end keys to preread.</param>
        /// <param name="rangeIndex">The index of the first key range in the array to read.</param>
        /// <param name="rangeCount">The maximum number of key ranges to preread.</param>
        /// <param name="rangesPreread">Returns the number of keys actually preread.</param>
        /// <param name="columnsPreread">List of column ids for long value columns to preread.</param>
        /// <param name="grbit">Preread options. Used to specify the direction of the preread.</param>
        /// <returns>An error or warning.</returns>
        public int JetPrereadKeyRanges(
            JET_SESID sesid,
            JET_TABLEID tableid,
            byte[][] keysStart,
            int[] keyStartLengths,
            byte[][] keysEnd,
            int[] keyEndLengths,
            int rangeIndex,
            int rangeCount,
            out int rangesPreread,
            JET_COLUMNID[] columnsPreread,
            PrereadIndexRangesGrbit grbit)
        {
            TraceFunctionCall("JetPrereadKeyRanges");
            this.CheckSupportsWindows8Features("JetPrereadKeyRanges");
            CheckDataSize(keysStart, rangeIndex, "rangeIndex", rangeCount, "rangeCount");
            CheckDataSize(keyStartLengths, rangeIndex, "rangeIndex", rangeCount, "rangeCount");
            CheckNotNull(keysStart, "keysStart");
            if (keysEnd != null)
            {
                CheckNotNull(keyEndLengths, "keyEndLengths");
                CheckDataSize(keysEnd, rangeIndex, "rangeIndex", rangeCount, "rangeCount");
            }

            if (keyEndLengths != null)
            {
                CheckNotNull(keysEnd, "keysEnd");
                CheckDataSize(keyEndLengths, rangeIndex, "rangeIndex", rangeCount, "rangeCount");
            }

            grbit = grbit | PrereadIndexRangesGrbit.NormalizedKey;

            using (var handles = new GCHandleCollection())
            {
                NATIVE_INDEX_COLUMN[] startColumn;
                NATIVE_INDEX_COLUMN[] endColumn;
                NATIVE_INDEX_RANGE[]  ranges = new NATIVE_INDEX_RANGE[rangeCount];
                for (int i = 0; i < rangeCount; i++)
                {
                    startColumn              = new NATIVE_INDEX_COLUMN[1];
                    startColumn[0].pvData    = handles.Add(keysStart[i + rangeIndex]);
                    startColumn[0].cbData    = (uint)keyStartLengths[i + rangeIndex];
                    ranges[i].rgStartColumns = handles.Add(startColumn);
                    ranges[i].cStartColumns  = 1;
                    if (keysEnd != null)
                    {
                        endColumn              = new NATIVE_INDEX_COLUMN[1];
                        endColumn[0].pvData    = handles.Add(keysEnd[i + rangeIndex]);
                        endColumn[0].cbData    = (uint)keyEndLengths[i + rangeIndex];
                        ranges[i].rgEndColumns = handles.Add(endColumn);
                        ranges[i].cEndColumns  = 1;
                    }
                }

                if (columnsPreread != null)
                {
                    var nativecolumnids = new uint[columnsPreread.Length];
                    for (int i = 0; i < columnsPreread.Length; i++)
                    {
                        nativecolumnids[i] = (uint)columnsPreread[i].Value;
                    }

                    return(Err(NativeMethods.JetPrereadIndexRanges(sesid.Value, tableid.Value, ranges, (uint)rangeCount, out rangesPreread, nativecolumnids, (uint)columnsPreread.Length, checked ((uint)grbit))));
                }
                else
                {
                    return(Err(NativeMethods.JetPrereadIndexRanges(sesid.Value, tableid.Value, ranges, (uint)rangeCount, out rangesPreread, null, (uint)0, checked ((uint)grbit))));
                }
            }
        }
Beispiel #41
0
 /// <summary>
 /// Causes a session to enter a transaction or create a new save point in an existing
 /// transaction.
 /// </summary>
 /// <param name="sesid">The session to begin the transaction for.</param>
 /// <param name="userTransactionId">An optional identifier supplied by the user for identifying the transaction.</param>
 /// <param name="grbit">Transaction options.</param>
 /// <returns>An error if the call fails.</returns>
 public int JetBeginTransaction3(JET_SESID sesid, long userTransactionId, BeginTransactionGrbit grbit)
 {
     TraceFunctionCall("JetBeginTransaction3");
     return(Err(NativeMethods.JetBeginTransaction3(sesid.Value, userTransactionId, unchecked ((uint)grbit))));
 }
Beispiel #42
0
 /// <summary>
 /// Retrieves record size information from the desired location.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">
 /// The cursor that will be used for the API call. The cursor must be
 /// positioned on a record, or have an update prepared.
 /// </param>
 /// <param name="recsize">Returns the size of the record.</param>
 /// <param name="grbit">Call options.</param>
 public static void JetGetRecordSize(JET_SESID sesid, JET_TABLEID tableid, ref JET_RECSIZE recsize, GetRecordSizeGrbit grbit)
 {
     Api.Check(Api.Impl.JetGetRecordSize(sesid, tableid, ref recsize, grbit));
 }
Beispiel #43
0
 /// <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"/>,
 /// <seealso cref="Api.JetOpenTempTable2"/>,
 /// <seealso cref="Api.JetOpenTempTable3"/>.
 /// </summary>
 /// <remarks>
 /// Introduced in Windows Vista. Use <see cref="Api.JetOpenTempTable3"/>
 /// 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 JetOpenTemporaryTable(JET_SESID sesid, JET_OPENTEMPORARYTABLE temporarytable)
 {
     Api.Check(Api.Impl.JetOpenTemporaryTable(sesid, temporarytable));
 }
Beispiel #44
0
 private JET_err StatusCallback(JET_SESID sesid, JET_SNP snp, JET_SNT snt, object data)
 {
     Notify(string.Format("Esent {0} {1} {2}", snp, snt, data).Trim(), null, BackupStatus.BackupMessageSeverity.Informational);
     return(JET_err.Success);
 }
Beispiel #45
0
        /// <summary>
        /// The seek with temp table.
        /// </summary>
        /// <param name="sesid">
        /// The sesid.
        /// </param>
        private static void SeekWithTempTable(JET_SESID sesid)
        {
            var tt = new JET_OPENTEMPORARYTABLE
            {
                ccolumn      = 1,
                prgcolumndef = new[] { new JET_COLUMNDEF {
                                           coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey
                                       } },
                prgcolumnid = new JET_COLUMNID[1],
                grbit       = TempTableGrbit.Indexed,
            };

            VistaApi.JetOpenTemporaryTable(sesid, tt);

            // Insert records 0, 10, 20, 30, ... 90);
            foreach (int i in Enumerable.Range(0, 10))
            {
                Api.JetPrepareUpdate(sesid, tt.tableid, JET_prep.Insert);
                Api.SetColumn(sesid, tt.tableid, tt.prgcolumnid[0], i * 10);
                Api.JetUpdate(sesid, tt.tableid);
            }

            try
            {
                // Boundary: before start of table
                ////VerifySeekFails(sesid, tt.tableid, -1, SeekGrbit.SeekLT);
                ////VerifySeekFails(sesid, tt.tableid, -1, SeekGrbit.SeekLE);
                VerifySeekFails(sesid, tt.tableid, -1, SeekGrbit.SeekEQ);
                VerifySeekFindRecord(sesid, tt.tableid, -1, SeekGrbit.SeekGE, tt.prgcolumnid[0], 0);
                VerifySeekFindRecord(sesid, tt.tableid, -1, SeekGrbit.SeekGT, tt.prgcolumnid[0], 0);

                // Boundary: at start of table
                VerifySeekFails(sesid, tt.tableid, 0, SeekGrbit.SeekLT);
                VerifySeekFindRecord(sesid, tt.tableid, 0, SeekGrbit.SeekLE, tt.prgcolumnid[0], 0);
                VerifySeekFindRecord(sesid, tt.tableid, 0, SeekGrbit.SeekEQ, tt.prgcolumnid[0], 0);
                ////VerifySeekFindRecord(sesid, tt.tableid, 0, SeekGrbit.SeekGE, tt.prgcolumnid[0], 0);
                VerifySeekFindRecord(sesid, tt.tableid, 0, SeekGrbit.SeekGT, tt.prgcolumnid[0], 10);

                // Normal case: middle of table, key exists
                VerifySeekFindRecord(sesid, tt.tableid, 50, SeekGrbit.SeekLT, tt.prgcolumnid[0], 40);
                VerifySeekFindRecord(sesid, tt.tableid, 50, SeekGrbit.SeekLE, tt.prgcolumnid[0], 50);
                VerifySeekFindRecord(sesid, tt.tableid, 50, SeekGrbit.SeekEQ, tt.prgcolumnid[0], 50);
                ////VerifySeekFindRecord(sesid, tt.tableid, 50, SeekGrbit.SeekGE, tt.prgcolumnid[0], 50);
                VerifySeekFindRecord(sesid, tt.tableid, 50, SeekGrbit.SeekGT, tt.prgcolumnid[0], 60);

                // Normal case: middle of table, key doesn't exist
                ////VerifySeekFindRecord(sesid, tt.tableid, 75, SeekGrbit.SeekLT, tt.prgcolumnid[0], 70);
                ////VerifySeekFindRecord(sesid, tt.tableid, 75, SeekGrbit.SeekLE, tt.prgcolumnid[0], 70);
                VerifySeekFails(sesid, tt.tableid, 75, SeekGrbit.SeekEQ);
                VerifySeekFindRecord(sesid, tt.tableid, 75, SeekGrbit.SeekGE, tt.prgcolumnid[0], 80);
                VerifySeekFindRecord(sesid, tt.tableid, 75, SeekGrbit.SeekGT, tt.prgcolumnid[0], 80);

                // Boundary: at end of table
                VerifySeekFindRecord(sesid, tt.tableid, 90, SeekGrbit.SeekLT, tt.prgcolumnid[0], 80);
                VerifySeekFindRecord(sesid, tt.tableid, 90, SeekGrbit.SeekLE, tt.prgcolumnid[0], 90);
                VerifySeekFindRecord(sesid, tt.tableid, 90, SeekGrbit.SeekEQ, tt.prgcolumnid[0], 90);
                ////VerifySeekFindRecord(sesid, tt.tableid, 90, SeekGrbit.SeekGE, tt.prgcolumnid[0], 90);
                VerifySeekFails(sesid, tt.tableid, 90, SeekGrbit.SeekGT);

                // Boundary: past end of table
                ////VerifySeekFindRecord(sesid, tt.tableid, 99, SeekGrbit.SeekLT, tt.prgcolumnid[0], 90);
                ////VerifySeekFindRecord(sesid, tt.tableid, 99, SeekGrbit.SeekLE, tt.prgcolumnid[0], 90);
                VerifySeekFails(sesid, tt.tableid, 99, SeekGrbit.SeekEQ);
                VerifySeekFails(sesid, tt.tableid, 99, SeekGrbit.SeekGE);
                VerifySeekFails(sesid, tt.tableid, 99, SeekGrbit.SeekGT);
            }
            finally
            {
                Api.JetCloseTable(sesid, tt.tableid);
            }
        }
Beispiel #46
0
 /// <summary>
 /// Set a timespan.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table to set the value in.</param>
 /// <param name="columnid">The column to set.</param>
 /// <param name="value">The value to set.</param>
 private static void SetColumn(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, TimeSpan value)
 {
     Api.SetColumn(sesid, tableid, columnid, value.Ticks);
 }
Beispiel #47
0
 /// <summary>
 /// The JetUpdate function performs an update operation including inserting a new row into
 /// a table or updating an existing row. Deleting a table row is performed by calling
 /// <see cref="Api.JetDelete"/>.
 /// </summary>
 /// <param name="sesid">The session which started the update.</param>
 /// <param name="tableid">The cursor to update. An update should be prepared.</param>
 /// <param name="bookmark">Returns the bookmark of the updated record. This can be null.</param>
 /// <param name="bookmarkSize">The size of the bookmark buffer.</param>
 /// <param name="actualBookmarkSize">Returns the actual size of the bookmark.</param>
 /// <param name="grbit">Update options.</param>
 /// <remarks>
 /// JetUpdate is the final step in performing an insert or an update. The update is begun by
 /// calling <see cref="Api.JetPrepareUpdate"/> and then by calling
 /// <see cref="Api.JetSetColumn(JET_SESID,JET_TABLEID,JET_COLUMNID,byte[],int,SetColumnGrbit,JET_SETINFO)"/>
 /// one or more times to set the record state. Finally, <see cref="JetUpdate2"/>
 /// is called to complete the update operation. Indexes are updated only by JetUpdate or and not during JetSetColumn.
 /// </remarks>
 public static void JetUpdate2(JET_SESID sesid, JET_TABLEID tableid, byte[] bookmark, int bookmarkSize, out int actualBookmarkSize, UpdateGrbit grbit)
 {
     Api.Check(Api.Impl.JetUpdate2(sesid, tableid, bookmark, bookmarkSize, out actualBookmarkSize, grbit));
 }
Beispiel #48
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyTransaction"/> struct.
 /// </summary>
 /// <param name="sesid">
 /// The sesid.
 /// </param>
 public LazyTransaction(JET_SESID sesid)
 {
     this.sesid = sesid;
     Api.JetBeginTransaction(this.sesid);
     this.inTransaction = true;
 }
Beispiel #49
0
        /// <summary>
        /// Setup the meta-data for the given table.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">
        /// The table to add the columns/indexes to. This table must be opened exclusively.
        /// </param>
        private static void CreateColumnsAndIndexes(JET_SESID sesid, JET_TABLEID tableid)
        {
            using (var transaction = new Transaction(sesid))
            {
                JET_COLUMNID columnid;

                // Stock symbol : text column
                var columndef = new JET_COLUMNDEF
                {
                    coltyp = JET_coltyp.LongText,
                    cp     = JET_CP.Unicode
                };

                Api.JetAddColumn(sesid, tableid, "symbol", columndef, null, 0, out columnid);

                // Name of the company : text column
                Api.JetAddColumn(sesid, tableid, "name", columndef, null, 0, out columnid);

                // Current price, stored in cents : 32-bit integer
                columndef = new JET_COLUMNDEF
                {
                    coltyp = JET_coltyp.Long,

                    // Be careful with ColumndefGrbit.ColumnNotNULL. Older versions of ESENT
                    // (e.g. Windows XP) do not support this grbit for tagged or variable columns
                    // (JET_coltyp.Text, JET_coltyp.LongText, JET_coltyp.Binary, JET_coltyp.LongBinary)
                    grbit = ColumndefGrbit.ColumnNotNULL
                };

                Api.JetAddColumn(sesid, tableid, "price", columndef, null, 0, out columnid);

                // Number of shares owned (this column may be null) : 32-bit integer
                columndef.grbit = ColumndefGrbit.None;
                Api.JetAddColumn(sesid, tableid, "shares_owned", columndef, null, 0, out columnid);

                // Now add indexes. An index consists of several index segments (see
                // EsentVersion.Capabilities.ColumnsKeyMost to determine the maximum number of
                // segments). Each segment consists of a sort direction ('+' for ascending,
                // '-' for descending), a column name, and a '\0' separator. The index definition
                // must end with "\0\0". The count of characters should include all terminators.

                // The primary index is the stock symbol. The primary index is always unique.
                string indexDef = "+symbol\0\0";
                Api.JetCreateIndex(sesid, tableid, "primary", CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100);

                // An index on the company name.
                indexDef = "+name\0+symbol\0\0";
                Api.JetCreateIndex(sesid, tableid, "name", CreateIndexGrbit.IndexUnique, indexDef, indexDef.Length, 100);

                // An index on the price. This index is not unique.
                indexDef = "+price\0\0";
                Api.JetCreateIndex(sesid, tableid, "price", CreateIndexGrbit.None, indexDef, indexDef.Length, 100);

                // Create 2 indexes that contain either companies where we own shares or companies
                // where we don't own shares. To do this we make the indexes conditional on the
                // 'shares_owned' column being null or non-null. When the 'shares_owned' column
                // is null entries will only appear in the 'noshares' index. When the 'shares_owned'
                // column is non-null (i.e. it has a value) entries will only appear in the 'shares'
                // index. Here we don't index the 'shares_owned' column (that would be valid too),
                // we just use it to determine membership in the index.
                const string      IndexKey     = "+name\0\0";
                JET_INDEXCREATE[] indexcreates = new[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName         = "shares",
                        szKey               = IndexKey,
                        cbKey               = IndexKey.Length,
                        rgconditionalcolumn = new[]
                        {
                            new JET_CONDITIONALCOLUMN
                            {
                                szColumnName = "shares_owned",
                                grbit        = ConditionalColumnGrbit.ColumnMustBeNonNull
                            }
                        },
                        cConditionalColumn = 1
                    },
                };

                // This is important: only create one index at a time with JetCreateIndex2!
                // The API takes an array of JET_INDEXCREATE objects, but if more than one
                // index is passed in then the API operates in batch mode, which requires
                // the caller NOT be in a transaction.
                Api.JetCreateIndex2(sesid, tableid, indexcreates, indexcreates.Length);

                // Now the first index has been created we change the name and invert the
                // condition and create a second index.
                indexcreates[0].szIndexName = "noshares";
                indexcreates[0].rgconditionalcolumn[0].grbit = ConditionalColumnGrbit.ColumnMustBeNull;
                Api.JetCreateIndex2(sesid, tableid, indexcreates, indexcreates.Length);

                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableidIndexInfoEnumerator"/> class.
 /// </summary>
 /// <param name="sesid">
 /// The session to use.
 /// </param>
 /// <param name="tableid">
 /// The table to get column information from.
 /// </param>
 public TableidIndexInfoEnumerator(JET_SESID sesid, JET_TABLEID tableid)
     : base(sesid)
 {
     this.tableid = tableid;
 }
Beispiel #51
0
        /// <summary>
        /// Creates a standard temp table with a column for each type.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="grbit">Temporary table options.</param>
        /// <param name="tableid">Returns the temporary table.</param>
        /// <returns>A dictionary mapping types to columns.</returns>
        public static Dictionary <string, JET_COLUMNID> CreateTempTableWithAllColumns(JET_SESID sesid, TempTableGrbit grbit, out JET_TABLEID tableid)
        {
            var columnDefs  = new List <JET_COLUMNDEF>();
            var columnNames = new List <string>();

            columnDefs.Add(new JET_COLUMNDEF {
                coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey
            });
            columnNames.Add("key");

            foreach (KeyValuePair <string, JET_COLUMNDEF> def in ColumndefDictionary)
            {
                columnNames.Add(def.Key);
                columnDefs.Add(def.Value);
            }

            JET_COLUMNDEF[] columns = columnDefs.ToArray();

            // Make all the columns tagged so they don't appear by default
            for (int i = 0; i < columns.Length; ++i)
            {
                columns[i].grbit |= ColumndefGrbit.ColumnTagged;
            }

            var columnids = new JET_COLUMNID[columns.Length];

            Api.JetOpenTempTable(sesid, columns, columns.Length, grbit, out tableid, columnids);
            var columnidDict = new Dictionary <string, JET_COLUMNID>(StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < columnids.Length; i++)
            {
                columnidDict[columnNames[i]] = columnids[i];
            }

            return(columnidDict);
        }
        internal static void CreateTable(JET_SESID sesid, JET_DBID dbid)
        {
            JET_TABLEID tableid;

            Api.JetCreateTable(sesid, dbid, InstanceTableName, 8, 80, out tableid);

            using (var transaction = new Microsoft.Isam.Esent.Interop.Transaction(sesid))
            {
                JET_COLUMNID columnid;

                //Unique instanceData label
                var columndef = new JET_COLUMNDEF
                {
                    coltyp = JET_coltyp.Long,
                    grbit  = ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
                };
                Api.JetAddColumn(sesid, tableid, colNameInstanceLabel, columndef, null, 0, out columnid);

                //IFC type ID
                columndef.coltyp = JET_coltyp.Short;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameIfcTypeId, columndef, null, 0, out columnid);

                //ifc Product label
                columndef.coltyp = JET_coltyp.Long;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameIfcProductLabel, columndef, null, 0, out columnid);

                //style label
                columndef.coltyp = JET_coltyp.Long;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameStyleLabel, columndef, null, 0, out columnid);

                //shape label
                columndef.coltyp = JET_coltyp.Long;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameShapeLabel, columndef, null, 0, out columnid);

                //Representation Context
                columndef.coltyp = JET_coltyp.Long;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameRepresentationContext, columndef, null, 0, out columnid);

                //Representation Context
                columndef.coltyp = JET_coltyp.UnsignedByte;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameRepType, columndef, null, 0, out columnid);

                //Transformation data
                columndef.coltyp = JET_coltyp.Binary;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                columndef.cbMax  = MaxSizeOfTransformation;
                Api.JetAddColumn(sesid, tableid, colNameTransformation, columndef, null, 0, out columnid);

                //Bounding Box data
                columndef.coltyp = JET_coltyp.Binary;
                columndef.grbit  = ColumndefGrbit.ColumnNotNULL;
                Api.JetAddColumn(sesid, tableid, colNameBoundingBox, columndef, null, 0, out columnid);

                string indexDef;
                // The  index on the shape geometry label.
                indexDef = string.Format("+{0}\0\0", colNameShapeLabel);
                Api.JetCreateIndex(sesid, tableid, geometryShapeIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100);

                //create index by ifc product label..  ..
                indexDef = string.Format("+{0}\0\0", colNameIfcProductLabel);
                Api.JetCreateIndex(sesid, tableid, productIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100);

                //create index by ifc product type label..  ..
                indexDef = string.Format("+{0}\0\0", colNameIfcTypeId);
                Api.JetCreateIndex(sesid, tableid, productTypeIndex, CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length, 100);

                //create by context,then ifc style...
                indexDef = string.Format("+{0}\0{1}\0{2}\0{3}\0\0", colNameRepresentationContext, colNameStyleLabel, colNameIfcTypeId, colNameInstanceLabel);
                Api.JetCreateIndex(sesid, tableid, instanceTablePrimaryIndex, CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length, 100);

                Api.JetCloseTable(sesid, tableid);

                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }
        }
Beispiel #53
0
 protected void GetColumnIds(
     JET_SESID sessionId, Table table, out JET_COLUMNID projectColumnId, out JET_COLUMNID projectNameColumnId)
 {
     projectColumnId     = Api.GetTableColumnid(sessionId, table, ProjectColumnName);
     projectNameColumnId = Api.GetTableColumnid(sessionId, table, ProjectNameColumnName);
 }
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="Api.JetSeek"/>
 /// and <see cref="Api.JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 private static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, DateTime data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data.Ticks, grbit);
 }
 public abstract void Create(JET_SESID sessionId, JET_DBID databaseId);
        /// <summary>
        /// Retrieves information about indexes on a table.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="dbid">The database to use.</param>
        /// <param name="tablename">The name of the table to retrieve index information about.</param>
        /// <param name="indexname">The name of the index to retrieve information about.</param>
        /// <param name="result">Filled in with information about indexes on the table.</param>
        /// <param name="infoLevel">The type of information to retrieve.</param>
        /// <returns>An error if the call fails.</returns>
        public int JetGetIndexInfo(
            JET_SESID sesid,
            JET_DBID dbid,
            string tablename,
            string indexname,
            out JET_INDEXCREATE result,
            JET_IdxInfo infoLevel)
        {
            TraceFunctionCall("JetGetIndexInfo");
            CheckNotNull(tablename, "tablename");
            int err;

            switch (infoLevel)
            {
            case Microsoft.Isam.Esent.Interop.Windows7.Windows7IdxInfo.CreateIndex:
            case Microsoft.Isam.Esent.Interop.Windows7.Windows7IdxInfo.CreateIndex2:
            case Microsoft.Isam.Esent.Interop.Windows8.Windows8IdxInfo.InfoCreateIndex3:
                break;

            default:
                throw new ArgumentException(string.Format("{0} is not a valid value JET_IdxInfo for this JET_INDEXCREATE overload."));
            }

            if (this.Capabilities.SupportsWindows8Features)
            {
                {
                    int    bufferSize      = 10 * Marshal.SizeOf(typeof(NATIVE_INDEXCREATE3));
                    IntPtr unmanagedBuffer = Marshal.AllocHGlobal(bufferSize);
                    try
                    {
                        // var nativeIndexcreate = new NATIVE_INDEXCREATE3();
                        // nativeIndexcreate.cbStruct = checked((uint)bufferSize);
                        infoLevel = Windows8IdxInfo.InfoCreateIndex3;

                        err = Err(NativeMethods.JetGetIndexInfoW(
                                      sesid.Value,
                                      dbid.Value,
                                      tablename,
                                      indexname,
                                      unmanagedBuffer,
                                      (uint)bufferSize,
                                      (uint)infoLevel));

                        NATIVE_INDEXCREATE3 nativeIndexcreate = (NATIVE_INDEXCREATE3)Marshal.PtrToStructure(unmanagedBuffer, typeof(NATIVE_INDEXCREATE3));

                        result = new JET_INDEXCREATE();
                        result.SetAllFromNativeIndexCreate(ref nativeIndexcreate);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(unmanagedBuffer);
                    }
                }
            }
            else
            {
                result = null;
                err    = Err((int)JET_err.FeatureNotAvailable);
            }

            return(err);
        }
Beispiel #57
0
        public IEnumerable <RevaleeTask> ListAllTasks()
        {
            if (_EseInstance == null)
            {
                throw new InvalidOperationException("Storage provider has not been opened.");
            }

            EseConnection connection = this._ConnectionPool.OpenConnection();

            try
            {
                using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.DenyWrite | OpenTableGrbit.Preread | OpenTableGrbit.ReadOnly | OpenTableGrbit.Sequential))
                {
                    IDictionary <string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks);

                    if (Api.TryMoveFirst(connection, table))
                    {
                        JET_SESID    jetSession                   = connection;
                        JET_TABLEID  jetTable                     = table;
                        JET_COLUMNID jetColumnCallbackId          = columnIds[_ColumnNameCallbackId];
                        JET_COLUMNID jetColumnCreatedTime         = columnIds[_ColumnNameCreatedTime];
                        JET_COLUMNID jetColumnCallbackTime        = columnIds[_ColumnNameCallbackTime];
                        JET_COLUMNID jetColumnCallbackUrl         = columnIds[_ColumnNameCallbackUrl];
                        JET_COLUMNID jetColumnAttemptsRemaining   = columnIds[_ColumnNameAttemptsRemaining];
                        JET_COLUMNID jetColumnAuthorizationCipher = columnIds[_ColumnNameAuthorizationCipher];

                        do
                        {
                            Guid?    callbackId              = Api.RetrieveColumnAsGuid(jetSession, jetTable, jetColumnCallbackId);
                            DateTime?createdTime             = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCreatedTime);
                            DateTime?callbackTime            = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCallbackTime);
                            string   callbackUrl             = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnCallbackUrl);
                            int?     attemptsRemainingColumn = Api.RetrieveColumnAsInt32(jetSession, jetTable, jetColumnAttemptsRemaining);
                            string   authorizationCipher     = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnAuthorizationCipher);

                            Uri callbackUri = null;

                            if (callbackTime.HasValue &&
                                Uri.TryCreate(callbackUrl, UriKind.Absolute, out callbackUri) &&
                                createdTime.HasValue &&
                                callbackId.HasValue &&
                                attemptsRemainingColumn.HasValue)
                            {
                                RevaleeTask revivedTask = RevaleeTask.Revive(
                                    DateTime.SpecifyKind(callbackTime.Value, DateTimeKind.Utc),
                                    callbackUri,
                                    DateTime.SpecifyKind(createdTime.Value, DateTimeKind.Utc),
                                    callbackId.Value,
                                    attemptsRemainingColumn.Value,
                                    string.IsNullOrEmpty(authorizationCipher) ? null : authorizationCipher);

                                yield return(revivedTask);
                            }
                        } while (Api.TryMoveNext(jetSession, jetTable));
                    }
                }
            }
            finally
            {
                _ConnectionPool.CloseConnection(connection);
            }

            yield break;
        }
 public abstract void Initialize(JET_SESID sessionId, JET_DBID databaseId);
Beispiel #59
0
        public IEnumerable <RevaleeTask> ListTasksDueBetween(DateTime startTime, DateTime endTime)
        {
            if (_EseInstance == null)
            {
                throw new InvalidOperationException("Storage provider has not been opened.");
            }

            DateTime rangeStartTime = EnforceMinimumDateTime(NormalizeDateTime(startTime));
            DateTime rangeEndTime   = EnforceMinimumDateTime(NormalizeDateTime(endTime));

            // Inclusive Upper Limit does not work properly for the CLR DateTime type.
            // Add the smallest amount of time that the Esent engine will detect to include the ending range inclusively.
            rangeEndTime = rangeEndTime.AddMilliseconds(1.0);

            EseConnection connection = this._ConnectionPool.OpenConnection();

            try
            {
                using (Table table = connection.GetTable(_TableNameCallbacks, OpenTableGrbit.DenyWrite | OpenTableGrbit.Preread | OpenTableGrbit.ReadOnly | OpenTableGrbit.Sequential))
                {
                    IDictionary <string, JET_COLUMNID> columnIds = connection.GetSchema(_TableNameCallbacks);
                    Api.JetSetCurrentIndex(connection, table, "due");
                    Api.MakeKey(connection, table, rangeStartTime, MakeKeyGrbit.NewKey);

                    if (Api.TrySeek(connection, table, SeekGrbit.SeekGE))
                    {
                        Api.MakeKey(connection, table, rangeEndTime, MakeKeyGrbit.NewKey);
                        if (Api.TrySetIndexRange(connection, table, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit))
                        {
                            JET_SESID    jetSession                   = connection;
                            JET_TABLEID  jetTable                     = table;
                            JET_COLUMNID jetColumnCallbackId          = columnIds[_ColumnNameCallbackId];
                            JET_COLUMNID jetColumnCreatedTime         = columnIds[_ColumnNameCreatedTime];
                            JET_COLUMNID jetColumnCallbackTime        = columnIds[_ColumnNameCallbackTime];
                            JET_COLUMNID jetColumnCallbackUrl         = columnIds[_ColumnNameCallbackUrl];
                            JET_COLUMNID jetColumnAttemptsRemaining   = columnIds[_ColumnNameAttemptsRemaining];
                            JET_COLUMNID jetColumnAuthorizationCipher = columnIds[_ColumnNameAuthorizationCipher];

                            do
                            {
                                Guid?    callbackId              = Api.RetrieveColumnAsGuid(jetSession, jetTable, jetColumnCallbackId);
                                DateTime?createdTime             = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCreatedTime);
                                DateTime?callbackTime            = Api.RetrieveColumnAsDateTime(jetSession, jetTable, jetColumnCallbackTime);
                                string   callbackUrl             = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnCallbackUrl);
                                int?     attemptsRemainingColumn = Api.RetrieveColumnAsInt32(jetSession, jetTable, jetColumnAttemptsRemaining);
                                string   authorizationCipher     = Api.RetrieveColumnAsString(jetSession, jetTable, jetColumnAuthorizationCipher);

                                Uri callbackUri = null;

                                if (callbackTime.HasValue &&
                                    Uri.TryCreate(callbackUrl, UriKind.Absolute, out callbackUri) &&
                                    createdTime.HasValue &&
                                    callbackId.HasValue &&
                                    attemptsRemainingColumn.HasValue)
                                {
                                    RevaleeTask revivedTask = RevaleeTask.Revive(
                                        DateTime.SpecifyKind(callbackTime.Value, DateTimeKind.Utc),
                                        callbackUri,
                                        DateTime.SpecifyKind(createdTime.Value, DateTimeKind.Utc),
                                        callbackId.Value,
                                        attemptsRemainingColumn.Value,
                                        string.IsNullOrEmpty(authorizationCipher) ? null : authorizationCipher);

                                    yield return(revivedTask);
                                }
                            } while (Api.TryMoveNext(jetSession, jetTable));
                        }
                    }
                }
            }
            finally
            {
                _ConnectionPool.CloseConnection(connection);
            }

            yield break;
        }
Beispiel #60
0
 /// <summary>
 /// Set a string.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table to set the value in.</param>
 /// <param name="columnid">The column to set.</param>
 /// <param name="value">The value to set.</param>
 private static void SetColumn(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, string value)
 {
     Api.SetColumn(sesid, tableid, columnid, value, Encoding.Unicode, SetColumnGrbit.IntrinsicLV);
 }