コード例 #1
0
ファイル: InternalApi.cs プロジェクト: 925coder/ravendb
        /// <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);
                }
            }
        }
コード例 #2
0
 public StringNameTableAccessor(
     OpenSession session, string tableName, string indexName, JET_COLUMNID idColumnId, JET_COLUMNID nameColumnId) : base(session, tableName)
 {
     _indexName = indexName;
     _idColumnId = idColumnId;
     _nameColumnId = nameColumnId;
 }
コード例 #3
0
ファイル: InternalApi.cs プロジェクト: j2jensen/ravendb
        /// <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);
                }
            }
        }
コード例 #4
0
ファイル: SeekTests.cs プロジェクト: Rationalle/ravendb
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);

            var columns = new[] { new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey } };
            var columnids = new JET_COLUMNID[columns.Length];

            // BUG: use TempTableGrbit.Indexed once in-memory TT bugs are fixed
            Api.JetOpenTempTable(this.sesid, columns, columns.Length, TempTableGrbit.ForceMaterialization, out this.tableid, columnids);
            this.columnid = columnids[0];

            for (int i = 10; i <= 30; i += 10)
            {
                Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
                Api.JetSetColumn(this.sesid, this.tableid, this.columnid, BitConverter.GetBytes(i), 4, SetColumnGrbit.None, null);
                int ignored;
                Api.JetUpdate(this.sesid, this.tableid, null, 0, out ignored);
            }
        }
コード例 #5
0
        public void ConvertObjectlistFromNative()
        {
            var tableid = new JET_TABLEID { Value = (IntPtr)0x1000 };
            var col1 = new JET_COLUMNID { Value = 1 };
            var col2 = new JET_COLUMNID { Value = 2 };
            var col3 = new JET_COLUMNID { Value = 3 };
            var col4 = new JET_COLUMNID { Value = 4 };
            var col5 = new JET_COLUMNID { Value = 5 };
            var col6 = new JET_COLUMNID { Value = 6 };

            var native = new NATIVE_OBJECTLIST()
            {
                tableid = tableid.Value,
                cRecord = 100,
                columnidobjectname = col1.Value,
                columnidobjtyp = col2.Value,
                columnidgrbit = col3.Value,
                columnidflags = col4.Value,
                columnidcRecord = col5.Value,
                columnidcPage = col6.Value,
            };

            var objectlist = new JET_OBJECTLIST();
            objectlist.SetFromNativeObjectlist(native);

            Assert.AreEqual(tableid, objectlist.tableid);
            Assert.AreEqual(100, objectlist.cRecord);
            Assert.AreEqual(col1, objectlist.columnidobjectname);
            Assert.AreEqual(col2, objectlist.columnidobjtyp);
            Assert.AreEqual(col3, objectlist.columnidgrbit);
            Assert.AreEqual(col4, objectlist.columnidflags);
            Assert.AreEqual(col5, objectlist.columnidcRecord);
            Assert.AreEqual(col6, objectlist.columnidcPage);
        }
コード例 #6
0
            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);
            }
コード例 #7
0
            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);
            }
コード例 #8
0
        public void SortDataWithJetOpenTempTable()
        {
            JET_TABLEID tableid;
            var columns = new[]
            {
                new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey },
                new JET_COLUMNDEF { coltyp = JET_coltyp.Text, cp = JET_CP.Unicode },
            };
            var columnids = new JET_COLUMNID[columns.Length];

            Api.JetOpenTempTable(this.session, columns, columns.Length, TempTableGrbit.Scrollable, out tableid, columnids);

            for (int i = 5; i >= 0; --i)
            {
                using (var update = new Update(this.session, tableid, JET_prep.Insert))
                {
                    Api.SetColumn(this.session, tableid, columnids[0], i);
                    Api.SetColumn(this.session, tableid, columnids[1], i.ToString(), Encoding.Unicode);
                    update.Save();
                }
            }

            var expected = new[] { "0", "1", "2", "3", "4", "5" };
            CollectionAssert.AreEqual(expected, this.RetrieveAllRecordsAsString(tableid, columnids[1]).ToArray());
            Api.JetCloseTable(this.session, tableid);
        }
コード例 #9
0
 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);
 }
コード例 #10
0
 protected void GetColumnIds(
     JET_COLUMNCREATE[] columns, out JET_COLUMNID projectColumnId, out JET_COLUMNID projectNameColumnId, out JET_COLUMNID documentColumnId)
 {
     projectColumnId = columns[0].columnid;
     projectNameColumnId = columns[1].columnid;
     documentColumnId = columns[2].columnid;
 }
コード例 #11
0
 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);
     }
 }
コード例 #12
0
ファイル: EsentStorage.Pool.cs プロジェクト: Rickinio/roslyn
            public static Int32ColumnValue GetInt32Column(JET_COLUMNID columnId, int value)
            {
                var column = SharedPools.Default<Int32ColumnValue>().Allocate();
                column.Columnid = columnId;
                column.Value = value;

                return column;
            }
コード例 #13
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;
 }
コード例 #14
0
            public SolutionTableAccessor(
                OpenSession session, string tableName, string indexName, JET_COLUMNID nameColumnId, JET_COLUMNID valueColumnId) : base(session, tableName)
            {
                _indexName = indexName;

                _nameColumnId = nameColumnId;
                _valueColumnId = valueColumnId;
            }
コード例 #15
0
 public ProjectTableAccessor(
     OpenSession session, string tableName, string indexName,
     JET_COLUMNID projectColumnId, JET_COLUMNID projectNameColumnId, JET_COLUMNID nameColumnId, JET_COLUMNID valueColumnId) :
     base(session, tableName, indexName, projectColumnId, projectNameColumnId, default(JET_COLUMNID))
 {
     _nameColumnId = nameColumnId;
     _valueColumnId = valueColumnId;
 }
コード例 #16
0
ファイル: jet_retinfo.cs プロジェクト: Rationalle/ravendb
        /// <summary>
        /// Sets the fields of the object from a NATIVE_RETINFO structure.
        /// </summary>
        /// <param name="value">The NATIVE_RETINFO which will be used to set the fields.</param>
        internal void SetFromNativeRetinfo(NATIVE_RETINFO value)
        {
            this.ibLongValue = checked((int)value.ibLongValue);
            this.itagSequence = checked((int)value.itagSequence);

            var columnid = new JET_COLUMNID { Value = value.columnidNextTagged };
            this.columnidNextTagged = columnid;
        }
コード例 #17
0
 public void Setup()
 {
     this.converter = Dependencies.Container.Resolve<InteropConversion>();
     this.columnid = new JET_COLUMNID
         {
             Value = Any.UInt16
         };
 }
コード例 #18
0
ファイル: VistaApi.cs プロジェクト: nick121212/xima_desktop3
 /// <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));
 }
コード例 #19
0
            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);
            }
コード例 #20
0
 public IdentifierLocationTableAccessor(
     OpenSession session, string tableName, string primaryIndexName,
     JET_COLUMNID projectColumnId, JET_COLUMNID projectNameColumnId, JET_COLUMNID documentColumnId,
     JET_COLUMNID identifierColumnId, JET_COLUMNID valueColumnId) :
     base(session, tableName, primaryIndexName, projectColumnId, projectNameColumnId, documentColumnId)
 {
     _identifierColumnId = identifierColumnId;
     _valueColumnId = valueColumnId;
 }
コード例 #21
0
 public DocumentTableAccessor(
     OpenSession session, string tableName, string primaryIndexName,
     JET_COLUMNID projectColumnId, JET_COLUMNID projectNameColumnId,
     JET_COLUMNID documentColumnId, JET_COLUMNID nameColumnId, JET_COLUMNID valueColumnId) :
     base(session, tableName, primaryIndexName, projectColumnId, projectNameColumnId, documentColumnId)
 {
     _nameColumnId = nameColumnId;
     _valueColumnId = valueColumnId;
 }
コード例 #22
0
ファイル: VistaApi.cs プロジェクト: jtmueller/ravendb
 /// <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));
 }
コード例 #23
0
 public ProjectDocumentTableAccessor(
     OpenSession session, string tableName, string indexName,
     JET_COLUMNID projectColumnId, JET_COLUMNID projectNameColumnId, JET_COLUMNID documentColumnId) : base(session, tableName)
 {
     IndexName = indexName;
     ProjectColumnId = projectColumnId;
     ProjectNameColumnId = projectNameColumnId;
     DocumentColumnId = documentColumnId;
 }
コード例 #24
0
 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);
     }
 }
コード例 #25
0
            protected ColumnValue[] GetColumnValues(Key key, JET_COLUMNID columnId1, int id1)
            {
                if (key.DocumentIdOpt.HasValue)
                {
                    return Pool.GetInt32Columns(ProjectColumnId, key.ProjectId, ProjectNameColumnId, key.ProjectNameId, DocumentColumnId, key.DocumentIdOpt.Value, columnId1, id1);
                }

                return Pool.GetInt32Columns(ProjectColumnId, key.ProjectId, ProjectNameColumnId, key.ProjectNameId, columnId1, id1);
            }
コード例 #26
0
ファイル: EsentTest.cs プロジェクト: WimVergouwe/ravendb
        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;
        }
コード例 #27
0
 public DocumentTableAccessor(
     OpenSession session, string tableName, string indexName,
     JET_COLUMNID projectColumnId, JET_COLUMNID documentColumnId, JET_COLUMNID nameColumnId, JET_COLUMNID valueColumnId) : base(session, tableName)
 {
     _indexName = indexName;
     _projectColumnId = projectColumnId;
     _documentColumnId = documentColumnId;
     _nameColumnId = nameColumnId;
     _valueColumnId = valueColumnId;
 }
コード例 #28
0
ファイル: EsentStorage.Pool.cs プロジェクト: Rickinio/roslyn
            public static ColumnValue[] GetInt32Columns(JET_COLUMNID columnId1, int value1, JET_COLUMNID columnId2, int value2, JET_COLUMNID columnId3, int value3)
            {
                var array = s_columnValuePool[0].Allocate();

                array[0] = GetInt32Column(columnId1, value1);
                array[1] = GetInt32Column(columnId2, value2);
                array[2] = GetInt32Column(columnId3, value3);

                return array;
            }
コード例 #29
0
            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, out _documentColumnId);

                    _identifierColumnId = Api.GetTableColumnid(sessionId, table, IdentifierColumnName);
                    _locationsColumnId = Api.GetTableColumnid(sessionId, table, LocationsColumnName);
                }
            }
コード例 #30
0
ファイル: ColumnStream.cs プロジェクト: 925coder/ravendb
        /// <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)
        {
            // In some cases we rely on Int32 arithmetic overflow checking to catch
            // errors, which assumes that a long-value can store Int32.MaxValue bytes.
            Debug.Assert(MaxLongValueSize == Int32.MaxValue, "Expected maximum long value size to be Int32.MaxValue");

            this.sesid = sesid;
            this.tableid = tableid;
            this.columnid = columnid;
            this.Itag = 1;
        }
コード例 #31
0
        public void VerifyUpdateFromNativeRetrievecolumnSetsColumnidNextTagged()
        {
            var setcolumn = new JET_RETRIEVECOLUMN();
            var native    = new NATIVE_RETRIEVECOLUMN {
                columnidNextTagged = 0x20
            };

            setcolumn.UpdateFromNativeRetrievecolumn(ref native);
            var expected = new JET_COLUMNID {
                Value = 0x20
            };

            Assert.AreEqual(expected, setcolumn.columnidNextTagged);
        }
コード例 #32
0
        /// <summary>
        /// Attach the database, open the global and data tables and get the required columnids.
        /// </summary>
        private void AttachDatabase()
        {
            Api.JetAttachDatabase(this.sesid, this.database, AttachDatabaseGrbit.None);
            Api.JetOpenDatabase(this.sesid, this.database, String.Empty, out this.dbid, OpenDatabaseGrbit.None);
            Api.JetOpenTable(
                this.sesid, this.dbid, this.config.GlobalsTableName, null, 0, OpenTableGrbit.None, out this.globalsTable);
            this.countColumn = Api.GetTableColumnid(this.sesid, this.globalsTable, this.config.CountColumnName);
            this.flushColumn = Api.GetTableColumnid(this.sesid, this.globalsTable, this.config.FlushColumnName);

            Api.JetOpenTable(
                this.sesid, this.dbid, this.config.DataTableName, null, 0, OpenTableGrbit.None, out this.dataTable);
            this.keyColumn   = Api.GetTableColumnid(this.sesid, this.dataTable, this.config.KeyColumnName);
            this.valueColumn = Api.GetTableColumnid(this.sesid, this.dataTable, this.config.ValueColumnName);
        }
コード例 #33
0
        /// <summary>Construct the object</summary>
        /// <param name="cur"></param>
        /// <param name="_idColumn"></param>
        public EseStreamValue(EseCursorBase cur, JET_COLUMNID _idColumn)
        {
            idColumn  = _idColumn;
            bk        = cur.getBookmark();
            tableName = cur.tableName;

            // Fetch the length.
            // Copy-pasted from Microsoft.Isam.Esent.Interop.ColumnStream.Length get
            var retinfo = new JET_RETINFO {
                itagSequence = 1, ibLongValue = 0
            };

            Api.JetRetrieveColumn(cur.idSession, cur.idTable, idColumn, null, 0, out length, RetrieveColumnGrbit.RetrieveCopy, retinfo);
        }
コード例 #34
0
ファイル: SimplePerfTest.cs プロジェクト: xinix00/ravendb
            /// <summary>
            /// Initializes a new instance of the <see cref="PerfTestWorker"/> class.
            /// </summary>
            /// <param name="instance">
            /// The instance to use.
            /// </param>
            /// <param name="database">
            /// Path to the database. The database should already be created.
            /// </param>
            public PerfTestWorker(JET_INSTANCE instance, string database)
            {
                Thread.BeginThreadAffinity();
                this.instance = instance;
                this.database = database;
                this.session  = new Session(this.instance);
                Api.JetOpenDatabase(this.session, this.database, String.Empty, out this.dbid, OpenDatabaseGrbit.None);
                this.table        = new Table(this.session, this.dbid, SimplePerfTest.TableName, OpenTableGrbit.None);
                this.columnidKey  = Api.GetTableColumnid(this.session, this.table, SimplePerfTest.KeyColumnName);
                this.columnidData = Api.GetTableColumnid(this.session, this.table, SimplePerfTest.DataColumnName);

                this.data    = new byte[SimplePerfTest.DataSize];
                this.dataBuf = new byte[SimplePerfTest.DataSize];
            }
コード例 #35
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            double?res = Api.RetrieveColumnAsDouble(cur.idSession, cur.idTable, idColumn);

            if (null == res)
            {
                if (bFieldNullable)
                {
                    return(null);
                }
                throw new SerializationException("The column is marked 'ColumnNotNULL', however the NULL value was pulled from the database.");
            }
            return(res.Value);
        }
コード例 #36
0
            public override void Create(JET_SESID sessionId, JET_DBID databaseId)
            {
                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[] { nameColumnCreate, valueColumnCreate };

                var nameIndexKey = "+" + NameColumnName + "\0\0";

                var indexes = new JET_INDEXCREATE[]
                {
                    new JET_INDEXCREATE
                    {
                        szIndexName = NameIndexName,
                        szKey       = nameIndexKey,
                        cbKey       = nameIndexKey.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);

                _nameColumnId  = nameColumnCreate.columnid;
                _valueColumnId = valueColumnCreate.columnid;

                Api.JetCloseTable(sessionId, tableCreate.tableid);
            }
コード例 #37
0
        public void ConvertObjectlistFromNative()
        {
            var tableid = new JET_TABLEID {
                Value = (IntPtr)0x1000
            };
            var col1 = new JET_COLUMNID {
                Value = 1
            };
            var col2 = new JET_COLUMNID {
                Value = 2
            };
            var col3 = new JET_COLUMNID {
                Value = 3
            };
            var col4 = new JET_COLUMNID {
                Value = 4
            };
            var col5 = new JET_COLUMNID {
                Value = 5
            };
            var col6 = new JET_COLUMNID {
                Value = 6
            };

            var native = new NATIVE_OBJECTLIST()
            {
                tableid            = tableid.Value,
                cRecord            = 100,
                columnidobjectname = col1.Value,
                columnidobjtyp     = col2.Value,
                columnidgrbit      = col3.Value,
                columnidflags      = col4.Value,
                columnidcRecord    = col5.Value,
                columnidcPage      = col6.Value,
            };

            var objectlist = new JET_OBJECTLIST();

            objectlist.SetFromNativeObjectlist(native);

            Assert.AreEqual(tableid, objectlist.tableid);
            Assert.AreEqual(100, objectlist.cRecord);
            Assert.AreEqual(col1, objectlist.columnidobjectname);
            Assert.AreEqual(col2, objectlist.columnidobjtyp);
            Assert.AreEqual(col3, objectlist.columnidgrbit);
            Assert.AreEqual(col4, objectlist.columnidflags);
            Assert.AreEqual(col5, objectlist.columnidcRecord);
            Assert.AreEqual(col6, objectlist.columnidcPage);
        }
コード例 #38
0
        public void SortLongValueDataWithJetOpenTempTable3()
        {
            JET_TABLEID tableid;
            var         columns = new[]
            {
                new JET_COLUMNDEF {
                    coltyp = JET_coltyp.LongText, 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       = 1041, // ja-JP
            };

            Api.JetOpenTempTable3(this.session, columns, columns.Length, idxunicode, TempTableGrbit.Scrollable, out tableid, columnids);

            var data = new[]
            {
                Any.StringOfLength(1999),
                Any.StringOfLength(2000),
                Any.StringOfLength(1999),
                Any.StringOfLength(2000),
                Any.StringOfLength(2001),
                Any.StringOfLength(2000),
                Any.StringOfLength(1999)
            };

            using (var transaction = new Transaction(this.session))
            {
                foreach (string s in data)
                {
                    using (var update = new Update(this.session, tableid, JET_prep.Insert))
                    {
                        Api.SetColumn(this.session, tableid, columnids[0], s, Encoding.Unicode);
                        update.Save();
                    }
                }

                transaction.Commit(CommitTransactionGrbit.None);
            }

            Array.Sort(data, new CultureInfo("ja-JP").CompareInfo.Compare);

            CollectionAssert.AreEqual(data, this.RetrieveAllRecordsAsString(tableid, columnids[0]).ToArray());
            Api.JetCloseTable(this.session, tableid);
        }
コード例 #39
0
        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.None,
                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);
        }
コード例 #40
0
 public XbimCursor(XbimModel model, string database, OpenDatabaseGrbit mode)
 {
     this.lockObject = new Object();
     this.model      = model;
     this.instance   = model.Cache.JetInstance;
     sesid           = new Session(instance);
     Api.JetOpenDatabase(sesid, database, String.Empty, out this.dbId, mode);
     Api.JetOpenTable(this.sesid, this.dbId, globalsTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                      out this.globalsTable);
     this.entityCountColumn   = Api.GetTableColumnid(this.sesid, this.globalsTable, entityCountColumnName);
     this.geometryCountColumn = Api.GetTableColumnid(this.sesid, this.globalsTable, geometryCountColumnName);
     this.flushColumn         = Api.GetTableColumnid(this.sesid, this.globalsTable, flushColumnName);
     this.ifcHeaderColumn     = Api.GetTableColumnid(this.sesid, this.globalsTable, ifcHeaderColumnName);
     ReadOnly = (mode == OpenDatabaseGrbit.ReadOnly);
 }
コード例 #41
0
        public void VerifyColumnidIsInvalidWorksAsExpected()
        {
            var zero     = JET_COLUMNID.Nil;
            var minusOne = new JET_COLUMNID()
            {
                Value = unchecked ((uint)~0)
            };
            var shouldBeValid = new JET_COLUMNID()
            {
                Value = 4
            };

            Assert.IsTrue(zero.IsInvalid);
            Assert.IsTrue(minusOne.IsInvalid);
            Assert.IsFalse(shouldBeValid.IsInvalid);
        }
コード例 #42
0
 protected EsentCursor(EsentModel model, string database, OpenDatabaseGrbit mode)
 {
     LockObject = new Object();
     Model      = model;
     Instance   = model.Cache.JetInstance;
     Sesid      = new Session(Instance);
     Api.JetOpenDatabase(Sesid, database, String.Empty, out DbId, mode);
     Api.JetOpenTable(Sesid, DbId, GlobalsTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                      out GlobalsTable);
     EntityCountColumn   = Api.GetTableColumnid(Sesid, GlobalsTable, EntityCountColumnName);
     GeometryCountColumn = Api.GetTableColumnid(Sesid, GlobalsTable, GeometryCountColumnName);
     FlushColumn         = Api.GetTableColumnid(Sesid, GlobalsTable, FlushColumnName);
     IfcHeaderColumn     = Api.GetTableColumnid(Sesid, GlobalsTable, ifcHeaderColumnName);
     ReadOnly            = (mode == OpenDatabaseGrbit.ReadOnly);
 }
コード例 #43
0
        /// <summary>Store the column value in the database.</summary>
        public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
        {
            if (serializeNull(cur, idColumn, value))
            {
                return;
            }
            int[] bits = Decimal.GetBits((decimal)(value));

            byte[] byteArray = new byte[16];
            Array.Copy(BitConverter.GetBytes(bits[0]), 0, byteArray, 0, 4);
            Array.Copy(BitConverter.GetBytes(bits[1]), 4, byteArray, 0, 4);
            Array.Copy(BitConverter.GetBytes(bits[2]), 8, byteArray, 0, 4);
            Array.Copy(BitConverter.GetBytes(bits[3]), 12, byteArray, 0, 4);

            Api.SetColumn(cur.idSession, cur.idTable, idColumn, byteArray);
        }
コード例 #44
0
        private void OpenCursor(string jetDatabase, Instance jetInstance, bool readOnly,
                                out Session jetSession,
                                out JET_DBID blockDbId,
                                out JET_TABLEID globalsTableId,
                                out JET_COLUMNID blockCountColumnId,
                                out JET_COLUMNID flushColumnId,
                                out JET_TABLEID blockIdsTableId,
                                out JET_COLUMNID blockIdsHashColumnId,
                                out JET_COLUMNID blockIdsIdColumnId,
                                out JET_TABLEID blocksTableId,
                                out JET_COLUMNID blockIdColumnId,
                                out JET_COLUMNID blockTxIndexColumnId,
                                out JET_COLUMNID blockDepthColumnId,
                                out JET_COLUMNID blockTxHashColumnId,
                                out JET_COLUMNID blockTxBytesColumnId)
        {
            jetSession = new Session(jetInstance);
            try
            {
                Api.JetOpenDatabase(jetSession, jetDatabase, "", out blockDbId, readOnly ? OpenDatabaseGrbit.ReadOnly : OpenDatabaseGrbit.None);

                Api.JetOpenTable(jetSession, blockDbId, "Globals", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out globalsTableId);
                blockCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "BlockCount");
                flushColumnId      = Api.GetTableColumnid(jetSession, globalsTableId, "Flush");

                if (!Api.TryMoveFirst(jetSession, globalsTableId))
                {
                    throw new InvalidOperationException();
                }

                Api.JetOpenTable(jetSession, blockDbId, "BlockIds", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blockIdsTableId);
                blockIdsHashColumnId = Api.GetTableColumnid(jetSession, blockIdsTableId, "BlockHash");
                blockIdsIdColumnId   = Api.GetTableColumnid(jetSession, blockIdsTableId, "BlockId");

                Api.JetOpenTable(jetSession, blockDbId, "Blocks", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blocksTableId);
                blockIdColumnId      = Api.GetTableColumnid(jetSession, blocksTableId, "BlockId");
                blockTxIndexColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "TxIndex");
                blockDepthColumnId   = Api.GetTableColumnid(jetSession, blocksTableId, "Depth");
                blockTxHashColumnId  = Api.GetTableColumnid(jetSession, blocksTableId, "TxHash");
                blockTxBytesColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "TxBytes");
            }
            catch (Exception)
            {
                jetSession.Dispose();
                throw;
            }
        }
コード例 #45
0
        /// <summary>Store the column value in the database.</summary>
        public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
        {
            using (var stm = new ColumnStream(cur.idSession, cur.idTable, idColumn))
            {
                using (XmlDictionaryWriter bw = XmlDictionaryWriter.CreateBinaryWriter(stm, this.dict))
                {
                    this.m_serializer.WriteObject(bw, value);
                    bw.Flush();
                }

                // TODO [low]: if the ( current size - new size < 4kb ), then append spaces/zeros instead of resizing the column. The comments inside the SetLength method suggest that shrinking the column is very inefficient for large values.
                if (stm.Position < stm.Length)
                {
                    stm.SetLength(stm.Position);
                }
            }
        }
コード例 #46
0
        private void OpenCursor(string jetDatabase, Instance jetInstance, bool readOnly,
                                out Session jetSession,
                                out JET_DBID blockDbId,
                                out JET_TABLEID globalsTableId,
                                out JET_COLUMNID flushColumnId,
                                out JET_TABLEID blockHeadersTableId,
                                out JET_COLUMNID blockHeaderHashColumnId,
                                out JET_COLUMNID blockHeaderPreviousHashColumnId,
                                out JET_COLUMNID blockHeaderHeightColumnId,
                                out JET_COLUMNID blockHeaderTotalWorkColumnId,
                                out JET_COLUMNID blockHeaderValidColumnId,
                                out JET_COLUMNID blockHeaderBytesColumnId)
        {
            jetSession = new Session(jetInstance);
            var success = false;

            try
            {
                Api.JetOpenDatabase(jetSession, jetDatabase, "", out blockDbId, readOnly ? OpenDatabaseGrbit.ReadOnly : OpenDatabaseGrbit.None);

                Api.JetOpenTable(jetSession, blockDbId, "Globals", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out globalsTableId);
                flushColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "Flush");

                if (!Api.TryMoveFirst(jetSession, globalsTableId))
                {
                    throw new InvalidOperationException();
                }

                Api.JetOpenTable(jetSession, blockDbId, "BlockHeaders", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blockHeadersTableId);
                blockHeaderHashColumnId         = Api.GetTableColumnid(jetSession, blockHeadersTableId, "BlockHash");
                blockHeaderPreviousHashColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "PreviousBlockHash");
                blockHeaderHeightColumnId       = Api.GetTableColumnid(jetSession, blockHeadersTableId, "Height");
                blockHeaderTotalWorkColumnId    = Api.GetTableColumnid(jetSession, blockHeadersTableId, "TotalWork");
                blockHeaderValidColumnId        = Api.GetTableColumnid(jetSession, blockHeadersTableId, "Valid");
                blockHeaderBytesColumnId        = Api.GetTableColumnid(jetSession, blockHeadersTableId, "BlockHeaderBytes");

                success = true;
            }
            finally
            {
                if (!success)
                {
                    jetSession.Dispose();
                }
            }
        }
コード例 #47
0
ファイル: ColumnInfo.cs プロジェクト: niratch/managed-esent
 /// <summary>
 /// Initializes a new instance of the ColumnInfo class.
 /// </summary>
 /// <param name="name">Name of the column.</param>
 /// <param name="columnid">ID of the column.</param>
 /// <param name="coltyp">Type of the column.</param>
 /// <param name="cp">Codepage of the column.</param>
 /// <param name="maxLength">Maximum length of the column.</param>
 /// <param name="defaultValue">Column default value.</param>
 /// <param name="grbit">Column option.</param>
 internal ColumnInfo(
     string name,
     JET_COLUMNID columnid,
     JET_coltyp coltyp,
     JET_CP cp,
     int maxLength,
     byte[] defaultValue,
     ColumndefGrbit grbit)
 {
     this.Name         = name;
     this.Columnid     = columnid;
     this.Coltyp       = coltyp;
     this.Cp           = cp;
     this.MaxLength    = maxLength;
     this.DefaultValue = defaultValue;
     this.Grbit        = grbit;
 }
コード例 #48
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);

            var columns = new[] { new JET_COLUMNDEF {
                                      coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey
                                  } };
            var columnids = new JET_COLUMNID[columns.Length];

            // BUG: use TempTableGrbit.Indexed once in-memory TT bugs are fixed
            Api.JetOpenTempTable(this.sesid, columns, columns.Length, TempTableGrbit.Scrollable, out this.tableid, columnids);
        }
コード例 #49
0
        /// <summary>
        /// Check the database files have been restored.
        /// </summary>
        /// <param name="databaseFile">The database file to verify.</param>
        private void CheckDatabase(string databaseFile)
        {
            using (var instance = this.CreateInstance())
            {
                instance.Init();
                using (var session = new Session(instance))
                {
                    Api.JetAttachDatabase(session, databaseFile, AttachDatabaseGrbit.ReadOnly);
                    JET_DBID dbid;
                    Api.JetOpenDatabase(session, databaseFile, string.Empty, out dbid, OpenDatabaseGrbit.ReadOnly);

                    JET_TABLEID tableid;
                    Api.JetOpenTable(session, dbid, "table", null, 0, OpenTableGrbit.ReadOnly, out tableid);
                    JET_COLUMNID columnid = Api.GetTableColumnid(session, tableid, "column");
                    Assert.IsTrue(Api.TryMoveFirst(session, tableid));
                    Assert.AreEqual(17, Api.RetrieveColumnAsInt32(session, tableid, columnid));
                }
            }
        }
コード例 #50
0
ファイル: Cursor.cs プロジェクト: stgwilli/ravendb
        /// <summary>
        /// Set a column in a record. An update must be prepared.
        /// </summary>
        /// <param name="columnid">The columnid to set.</param>
        /// <param name="data">The data to set.</param>
        /// <param name="grbit">Options for JetSetColumn.</param>
        public virtual void SetColumn(JET_COLUMNID columnid, byte[] data, SetColumnGrbit grbit)
        {
            this.Tracer.TraceVerbose("SetColumn");
            this.CheckNotDisposed();
            this.CheckInUpdate();

            if (null == data)
            {
                Api.JetSetColumn(this.session, this.table, columnid, null, 0, grbit, null);
            }
            else if (data.Length == 0)
            {
                Api.JetSetColumn(this.session, this.table, columnid, null, 0, grbit | SetColumnGrbit.ZeroLength, null);
            }
            else
            {
                Api.JetSetColumn(this.session, this.table, columnid, data, data.Length, grbit, null);
            }
        }
コード例 #51
0
        private void InitColumns()
        {
            _colIdShapeLabel     = Api.GetTableColumnid(Sesid, Table, colNameShapeLabel);
            _colIdIfcShapeLabel  = Api.GetTableColumnid(Sesid, Table, colNameIfcShapeLabel);
            _colIdGeometryHash   = Api.GetTableColumnid(Sesid, Table, colNameGeometryHash);
            _colIdCost           = Api.GetTableColumnid(Sesid, Table, colNameCost);
            _colIdReferenceCount = Api.GetTableColumnid(Sesid, Table, colNameReferenceCount);
            _colIdLOD            = Api.GetTableColumnid(Sesid, Table, colNameLOD);
            _colIdFormat         = Api.GetTableColumnid(Sesid, Table, colNameFormat);
            _colIdBoundingBox    = Api.GetTableColumnid(Sesid, Table, colNameBoundingBox);
            _colIdShapeData      = Api.GetTableColumnid(Sesid, Table, colNameShapeData);

            _colValShapeLabel = new Int32ColumnValue {
                Columnid = _colIdShapeLabel
            };
            _colValIfcShapeLabel = new Int32ColumnValue {
                Columnid = _colIdIfcShapeLabel
            };
            _colValGeometryHash = new Int32ColumnValue {
                Columnid = _colIdGeometryHash
            };
            _colValCost = new Int32ColumnValue {
                Columnid = _colIdCost
            };
            _colValReferenceCount = new Int32ColumnValue {
                Columnid = _colIdReferenceCount
            };
            _colValLOD = new ByteColumnValue {
                Columnid = _colIdLOD
            };
            _colValFormat = new ByteColumnValue {
                Columnid = _colIdFormat
            };
            _colValBoundingBox = new BytesColumnValue {
                Columnid = _colIdBoundingBox
            };
            _colValShapeData = new BytesColumnValue {
                Columnid = _colIdShapeData
            };


            _colValues = new ColumnValue[] { _colValIfcShapeLabel, _colValGeometryHash, _colValCost, _colValReferenceCount, _colValLOD, _colValFormat, _colValBoundingBox, _colValShapeData };
        }
コード例 #52
0
        private void InitColumns()
        {
            _colIdInstanceLabel         = Api.GetTableColumnid(Sesid, Table, colNameInstanceLabel);
            _colIdIfcTypeId             = Api.GetTableColumnid(Sesid, Table, colNameIfcTypeId);
            _colIdIfcProductLabel       = Api.GetTableColumnid(Sesid, Table, colNameIfcProductLabel);
            _colIdStyleLabel            = Api.GetTableColumnid(Sesid, Table, colNameStyleLabel);
            _colIdShapeLabel            = Api.GetTableColumnid(Sesid, Table, colNameShapeLabel);
            _colIdRepresentationContext = Api.GetTableColumnid(Sesid, Table, colNameRepresentationContext);
            _colIdRepType        = Api.GetTableColumnid(Sesid, Table, colNameRepType);
            _colIdTransformation = Api.GetTableColumnid(Sesid, Table, colNameTransformation);
            _colIdBoundingBox    = Api.GetTableColumnid(Sesid, Table, colNameBoundingBox);

            _colValInstanceLabel = new Int32ColumnValue {
                Columnid = _colIdInstanceLabel
            };
            _colValIfcTypeId = new Int16ColumnValue {
                Columnid = _colIdIfcTypeId
            };
            _colValIfcProductLabel = new Int32ColumnValue {
                Columnid = _colIdIfcProductLabel
            };
            _colValStyleLabel = new Int32ColumnValue {
                Columnid = _colIdStyleLabel
            };
            _colValShapeLabel = new Int32ColumnValue {
                Columnid = _colIdShapeLabel
            };
            _colValRepresentationContext = new Int32ColumnValue {
                Columnid = _colIdRepresentationContext
            };
            _colValRepType = new ByteColumnValue {
                Columnid = _colIdRepType
            };
            _colValTransformation = new BytesColumnValue {
                Columnid = _colIdTransformation
            };
            _colValBoundingBox = new BytesColumnValue {
                Columnid = _colIdBoundingBox
            };


            _colValues = new ColumnValue[] { _colValIfcTypeId, _colValIfcProductLabel, _colValStyleLabel, _colValShapeLabel, _colValRepresentationContext, _colValRepType, _colValTransformation, _colValBoundingBox, };
        }
コード例 #53
0
        /// <summary>
        /// Retrieve columns using the basic JetRetrieveColumn API.
        /// </summary>
        private void RetrieveWithJetRetrieveColumn()
        {
            var boolBuffer   = new byte[sizeof(bool)];
            var int32Buffer  = new byte[sizeof(int)];
            var int64Buffer  = new byte[sizeof(long)];
            var guidBuffer   = new byte[16];
            var stringBuffer = new byte[512];

            JET_COLUMNID boolColumn   = this.columnidDict["boolean"];
            JET_COLUMNID int32Column  = this.columnidDict["int32"];
            JET_COLUMNID int64Column  = this.columnidDict["int64"];
            JET_COLUMNID guidColumn   = this.columnidDict["guid"];
            JET_COLUMNID stringColumn = this.columnidDict["unicode"];

            for (int i = 0; i < NumRetrieves; ++i)
            {
                Api.JetBeginTransaction(this.session);

                int actualSize;
                Api.JetRetrieveColumn(this.session, this.tableid, boolColumn, boolBuffer, boolBuffer.Length, out actualSize, RetrieveColumnGrbit.None, null);
                Api.JetRetrieveColumn(this.session, this.tableid, int32Column, int32Buffer, int32Buffer.Length, out actualSize, RetrieveColumnGrbit.None, null);
                Api.JetRetrieveColumn(this.session, this.tableid, int64Column, int64Buffer, int64Buffer.Length, out actualSize, RetrieveColumnGrbit.None, null);
                Api.JetRetrieveColumn(this.session, this.tableid, guidColumn, guidBuffer, guidBuffer.Length, out actualSize, RetrieveColumnGrbit.None, null);

                int stringSize;
                Api.JetRetrieveColumn(this.session, this.tableid, stringColumn, stringBuffer, stringBuffer.Length, out stringSize, RetrieveColumnGrbit.None, null);

                bool   actualBool   = BitConverter.ToBoolean(boolBuffer, 0);
                int    actualInt32  = BitConverter.ToInt32(int32Buffer, 0);
                long   actualInt64  = BitConverter.ToInt64(int64Buffer, 0);
                Guid   actualGuid   = new Guid(guidBuffer);
                string actualString = Encoding.Unicode.GetString(stringBuffer, 0, stringSize);

                Assert.AreEqual(this.expectedBool, actualBool);
                Assert.AreEqual(this.expectedInt32, actualInt32);
                Assert.AreEqual(this.expectedInt64, actualInt64);
                Assert.AreEqual(this.expectedGuid, actualGuid);
                Assert.AreEqual(this.expectedString, actualString);

                Api.JetCommitTransaction(this.session, CommitTransactionGrbit.None);
            }
        }
コード例 #54
0
        /// <summary>
        /// Retrieves the column.
        /// </summary>
        /// <param name="columnid">The columnid.</param>
        /// <param name="coltyp">The coltyp.</param>
        /// <param name="isAscii">Whether a textual column is Ascii.</param>
        /// <param name="index">The index.</param>
        /// <returns>The value stored within.</returns>
        /// <remarks>
        /// Itags start at 1, so we add 1 to the index
        /// </remarks>
        private object RetrieveColumn(JET_COLUMNID columnid, JET_coltyp coltyp, bool isAscii, int index)
        {
            lock (this.isamSession)
            {
                this.cursor.CheckDisposed();

                if ((this.grbit & RetrieveColumnGrbit.RetrieveCopy) == 0)
                {
                    this.cursor.CheckRecord();
                }

                JET_RETINFO retinfo = new JET_RETINFO();
                retinfo.ibLongValue  = 0;
                retinfo.itagSequence = index + 1;
                byte[] bytes = Api.RetrieveColumn(this.isamSession.Sesid, this.tableid, columnid, this.grbit, retinfo);

                object obj = Converter.ObjectFromBytes(coltyp, isAscii, bytes);
                return(obj);
            }
        }
コード例 #55
0
            /// <summary></summary>
            /// <param name="_name">The name of the column.</param>
            /// <param name="member">Either FieldInfo or PropertyInfo of the member who has the _attr attribute applied.</param>
            /// <param name="_attr">The attribute.</param>
            /// <param name="obsolete">True if the column is also marked with [Obsolete] attribute.</param>
            public ColumnInfo(string _name, MemberInfo member, EseColumnAttrubuteBase _attr, bool obsolete)
            {
                m_columnName    = _name;
                m_attribute     = _attr;
                m_idColumn      = JET_COLUMNID.Nil;
                this.isObsolete = obsolete;

                // http://www.palmmedia.de/Blog/2012/2/4/reflection-vs-compiled-expressions-vs-delegates-performance-comparision

                ParameterExpression targetExpObject = Expression.Parameter(typeof(object), "record");                       //  object record
                UnaryExpression     targetExp       = Expression.Convert(targetExpObject, member.DeclaringType);            //  (RecordType)record

                MemberExpression memberExp = null;

                if (member is FieldInfo)
                {
                    FieldInfo field = member as FieldInfo;
                    tpValue   = field.FieldType;
                    memberExp = Expression.Field(targetExp, field);                          //  (((RecordType)record).field)
                }
                else if (member is PropertyInfo)
                {
                    PropertyInfo property = member as PropertyInfo;
                    tpValue   = property.PropertyType;
                    memberExp = Expression.Property(targetExp, property);                         //  (((RecordType)record).property)
                }
                else
                {
                    throw new ArgumentException();
                }

                UnaryExpression memberExpObject = Expression.Convert(memberExp, typeof(object));                          //  (object)(((RecordType)record).property)

                this.getValue = Expression.Lambda <Func <object, object> >(memberExpObject, targetExpObject).Compile();

                ParameterExpression valueExpObject = Expression.Parameter(typeof(object), "value");         //  object value
                UnaryExpression     valueExp       = Expression.Convert(valueExpObject, tpValue);           //  (PropertyType)value
                BinaryExpression    assignExp      = Expression.Assign(memberExp, valueExp);                //  ((RecordType)record).property = (PropertyType)value

                this.setValue = Expression.Lambda <Action <object, object> >(assignExp, targetExpObject, valueExpObject).Compile();
            }
コード例 #56
0
        private void InitColumns()
        {
            _colIdGeometryLabel    = Api.GetTableColumnid(Sesid, Table, ColNameGeometryLabel);
            _colIdGeomType         = Api.GetTableColumnid(Sesid, Table, ColNameGeomType);
            _colIdProductIfcTypeId = Api.GetTableColumnid(Sesid, Table, ColNameProductIfcTypeId);
            _colIdProductLabel     = Api.GetTableColumnid(Sesid, Table, ColNameProductLabel);
            _colIdSubPart          = Api.GetTableColumnid(Sesid, Table, ColNameSubPart);
            _colIdTransformMatrix  = Api.GetTableColumnid(Sesid, Table, ColNameTransformMatrix);
            _colIdShapeData        = Api.GetTableColumnid(Sesid, Table, ColNameShapeData);
            _colIdGeometryHash     = Api.GetTableColumnid(Sesid, Table, ColNameGeometryHash);
            _colIdStyleLabel       = Api.GetTableColumnid(Sesid, Table, ColNameStyleLabel);

            _colValGeometryLabel = new Int32ColumnValue {
                Columnid = _colIdGeometryLabel
            };
            _colValGeomType = new ByteColumnValue {
                Columnid = _colIdGeomType
            };
            _colValProductIfcTypeId = new Int16ColumnValue {
                Columnid = _colIdProductIfcTypeId
            };
            _colValProductLabel = new Int32ColumnValue {
                Columnid = _colIdProductLabel
            };
            _colValSubPart = new Int16ColumnValue {
                Columnid = _colIdSubPart
            };
            _colValTransformMatrix = new BytesColumnValue {
                Columnid = _colIdTransformMatrix
            };
            _colValShapeData = new BytesColumnValue {
                Columnid = _colIdShapeData
            };
            _colValGeometryHash = new Int32ColumnValue {
                Columnid = _colIdGeometryHash
            };
            _colValStyleLabel = new Int32ColumnValue {
                Columnid = _colIdStyleLabel
            };
            _colValues = new ColumnValue[] { _colValGeomType, _colValProductLabel, _colValProductIfcTypeId, _colValSubPart, _colValTransformMatrix, _colValShapeData, _colValGeometryHash, _colValStyleLabel };
        }
コード例 #57
0
        private void InitColumns()
        {
            // IDictionary<string, JET_COLUMNID> columnids = Api.GetColumnDictionary(_jetSession, _jetCursor);
            _colIdHeaderId    = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameHeaderId);
            _colIdEntityCount = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameEntityCount);
            _colIdFileVersion = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameFileVersion);
            _colIdHeaderData  = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameHeaderData);

            _colValHeaderId = new Int32ColumnValue {
                Columnid = _colIdHeaderId
            };
            _colValEntityCount = new Int64ColumnValue {
                Columnid = _colIdEntityCount
            };
            _colValFileVersion = new StringColumnValue {
                Columnid = _colIdFileVersion
            };
            _colValHeaderData = new BytesColumnValue {
                Columnid = _colIdHeaderData
            };
        }
コード例 #58
0
        /// <summary>
        /// Перечислить значения в столбце со многоими значениями.
        /// </summary>
        /// <param name="table">Таблица.</param>
        /// <param name="columnid">Идентификатор столбца.</param>
        /// <param name="factoryFunc">Фабрика создания значений для получения данных.</param>
        /// <returns>Результат.</returns>
        protected IEnumerable <ColumnValue> EnumMultivalueColumn(EsentTable table, JET_COLUMNID columnid, Func <ColumnValue> factoryFunc)
        {
            var count = GetMultiValueCount(table, columnid);

            if (count == 0)
            {
                yield break;
            }

            var a = new ColumnValue[1];

            for (var i = 1; i <= count; i++)
            {
                var col = factoryFunc();
                col.ItagSequence = i;
                col.Columnid     = columnid;
                a[0]             = col;
                Api.RetrieveColumns(table.Session, table.Table, a);
                yield return(col);
            }
        }
コード例 #59
0
ファイル: EsentStorageRaw.cs プロジェクト: pawels17/MUTDOD
        private void OpenDatabase()
        {
            if (IsNewDatabase())
            {
                Api.JetCreateDatabase(_sesid, _databaseParameters.DataFileFullPath, null, out _dbid,
                                      CreateDatabaseGrbit.None);

                Api.JetBeginTransaction(_sesid);
                Api.JetCreateTable(_sesid, _dbid, "nodes", 100, 100, out _tableid);

                var idColumn = new JET_COLUMNDEF {
                    coltyp = JET_coltyp.Binary, cp = JET_CP.None
                };
                Api.JetAddColumn(_sesid, _tableid, "id", idColumn, null, 0, out _idColumnId);

                var dataColumn = new JET_COLUMNDEF {
                    coltyp = JET_coltyp.LongBinary, cp = JET_CP.None
                };
                Api.JetAddColumn(_sesid, _tableid, "data", dataColumn, null, 0, out _dataColumnId);

                const string indexDef = "+id\0\0";
                Api.JetCreateIndex(_sesid, _tableid, "primary", CreateIndexGrbit.IndexPrimary, indexDef, indexDef.Length,
                                   100);

                Api.JetCommitTransaction(_sesid, CommitTransactionGrbit.LazyFlush);
            }
            else
            {
                Api.JetAttachDatabase(_sesid, _databaseParameters.DataFileFullPath, AttachDatabaseGrbit.None);
                Api.JetOpenDatabase(_sesid, _databaseParameters.DataFileFullPath, "", out _dbid,
                                    OpenDatabaseGrbit.Exclusive);

                Api.JetBeginTransaction(_sesid);
                Api.JetOpenTable(_sesid, _dbid, "nodes", null, 0, OpenTableGrbit.Preread, out _tableid);
                var columns = Api.GetColumnDictionary(_sesid, _tableid);
                _idColumnId   = columns["id"];
                _dataColumnId = columns["data"];
                Api.JetCommitTransaction(_sesid, CommitTransactionGrbit.LazyFlush);
            }
        }
コード例 #60
0
        public void TestJetUpdate2()
        {
            if (!EsentVersion.SupportsServer2003Features)
            {
                return;
            }

            JET_COLUMNID columnid = this.columnDict["Int32"];
            int value = Any.Int32;

            using (var trx = new Transaction(this.session))
            {
                Api.JetPrepareUpdate(this.session, this.tableid, JET_prep.Insert);
                Api.SetColumn(this.session, this.tableid, columnid, value);
                int ignored;
                Server2003Api.JetUpdate2(this.session, this.tableid, null, 0, out ignored, UpdateGrbit.None);
                trx.Commit(CommitTransactionGrbit.None);
            }

            Api.TryMoveFirst(this.session, this.tableid);
            Assert.AreEqual(value, Api.RetrieveColumnAsInt32(this.session, this.tableid, columnid));
        }