/// <summary>
        /// Create a ColumnInfo object from the data in the current JET_COLUMNLIST
        /// entry.
        /// </summary>
        /// <param name="columnlist">The columnlist to take the data from.</param>
        /// <returns>A ColumnInfo object containing the information from that record.</returns>
        private ColumnInfo GetColumnInfoFromColumnlist(JET_COLUMNLIST columnlist)
        {
            string name = Api.RetrieveColumnAsString(
                this.sesid,
                columnlist.tableid,
                columnlist.columnidcolumnname,
                NativeMethods.Encoding,
                RetrieveColumnGrbit.None);
            var  columnidValue = (uint)Api.RetrieveColumnAsUInt32(this.sesid, columnlist.tableid, columnlist.columnidcolumnid);
            var  coltypValue   = (uint)Api.RetrieveColumnAsUInt32(this.sesid, columnlist.tableid, columnlist.columnidcoltyp);
            uint codepageValue = (ushort)Api.RetrieveColumnAsUInt16(this.sesid, columnlist.tableid, columnlist.columnidCp);
            var  maxLength     = (uint)Api.RetrieveColumnAsUInt32(this.sesid, columnlist.tableid, columnlist.columnidcbMax);

            byte[] defaultValue = Api.RetrieveColumn(this.sesid, columnlist.tableid, columnlist.columnidDefault);
            var    grbitValue   = (uint)Api.RetrieveColumnAsUInt32(this.sesid, columnlist.tableid, columnlist.columnidgrbit);

            return(new ColumnInfo(
                       name,
                       new JET_COLUMNID()
            {
                Value = columnidValue
            },
                       (JET_coltyp)coltypValue,
                       (JET_CP)codepageValue,
                       checked ((int)maxLength),
                       defaultValue,
                       (ColumndefGrbit)grbitValue));
        }
Exemple #2
0
        /// <summary>
        /// Create a ColumnInfo object from the data in the current JET_COLUMNLIST entry.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="columnlist">The columnlist to take the data from.</param>
        /// <returns>A ColumnInfo object containing the information from that record.</returns>
        private static ColumnInfo GetColumnInfoFromColumnlist(JET_SESID sesid, JET_COLUMNLIST columnlist)
        {
            // As of Sep 2015, JetGetColumnInfoW is only called for Win8+. Even though Unicode should have
            // worked in Win7, it wasn't reliable until Win8.
            Encoding encodingOfTextColumns = EsentVersion.SupportsWindows8Features ? Encoding.Unicode : LibraryHelpers.EncodingASCII;

            string name = Api.RetrieveColumnAsString(
                sesid,
                columnlist.tableid,
                columnlist.columnidcolumnname,
                encodingOfTextColumns,
                RetrieveColumnGrbit.None);

            name = StringCache.TryToIntern(name);
            var  columnidValue = (uint)Api.RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcolumnid);
            var  coltypValue   = (uint)Api.RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcoltyp);
            uint codepageValue = (ushort)Api.RetrieveColumnAsUInt16(sesid, columnlist.tableid, columnlist.columnidCp);
            var  maxLength     = (uint)Api.RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcbMax);

            byte[] defaultValue = Api.RetrieveColumn(sesid, columnlist.tableid, columnlist.columnidDefault);
            var    grbitValue   = (uint)Api.RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidgrbit);

            return(new ColumnInfo(
                       name,
                       new JET_COLUMNID {
                Value = columnidValue
            },
                       (JET_coltyp)coltypValue,
                       (JET_CP)codepageValue,
                       unchecked ((int)maxLength),
                       defaultValue,
                       (ColumndefGrbit)grbitValue));
        }
Exemple #3
0
        public void ConvertColumnlistFromNative()
        {
            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 col7 = new JET_COLUMNID { Value = 7 };

            var native = new NATIVE_COLUMNLIST()
            {
                tableid = tableid.Value,
                cRecord = 100,
                columnidcolumnname = col1.Value,
                columnidcolumnid = col2.Value,
                columnidcoltyp = col3.Value,
                columnidCp = col4.Value,
                columnidcbMax = col5.Value,
                columnidgrbit = col6.Value,
                columnidDefault = col7.Value,
            };

            var columnlist = new JET_COLUMNLIST();
            columnlist.SetFromNativeColumnlist(native);

            Assert.AreEqual(tableid, columnlist.tableid);
            Assert.AreEqual(100, columnlist.cRecord);
            Assert.AreEqual(col1, columnlist.columnidcolumnname);
            Assert.AreEqual(col2, columnlist.columnidcolumnid);
            Assert.AreEqual(col3, columnlist.columnidcoltyp);
            Assert.AreEqual(col4, columnlist.columnidCp);
            Assert.AreEqual(col5, columnlist.columnidcbMax);
            Assert.AreEqual(col6, columnlist.columnidgrbit);
            Assert.AreEqual(col7, columnlist.columnidDefault);
        }
        /// <summary>
        /// Create a ColumnInfo object from the data in the current JET_COLUMNLIST
        /// entry.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="columnlist">The columnlist to take the data from.</param>
        /// <returns>A ColumnInfo object containing the information from that record.</returns>
        private static ColumnInfo GetColumnInfoFromColumnlist(JET_SESID sesid, JET_COLUMNLIST columnlist)
        {
            string name = RetrieveColumnAsString(
                sesid,
                columnlist.tableid,
                columnlist.columnidcolumnname,
                NativeMethods.Encoding,
                RetrieveColumnGrbit.None);
            var columnidValue = (uint) RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcolumnid);
            var coltypValue = (uint) RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcoltyp);
            uint codepageValue = (ushort) RetrieveColumnAsUInt16(sesid, columnlist.tableid, columnlist.columnidCp);
            var maxLength = (uint) RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidcbMax);
            byte[] defaultValue = RetrieveColumn(sesid, columnlist.tableid, columnlist.columnidDefault);
            var grbitValue = (uint) RetrieveColumnAsUInt32(sesid, columnlist.tableid, columnlist.columnidgrbit);

            return new ColumnInfo(
                name,
                new JET_COLUMNID() { Value = columnidValue },
                (JET_coltyp) coltypValue,
                (JET_CP) codepageValue,
                checked((int) maxLength),
                defaultValue,
                (ColumndefGrbit) grbitValue);
        }
 /// <summary>
 /// Iterates over the information in the JET_COLUMNLIST, returning information about each column.
 /// The table in the columnlist is closed when finished.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="columnlist">The columnlist to iterate over.</param>
 /// <returns>An iterator over ColumnInfo for each column described in the JET_COLUMNLIST.</returns>
 private static IEnumerable<ColumnInfo> EnumerateColumnInfos(JET_SESID sesid, JET_COLUMNLIST columnlist)
 {
     try
     {
         MoveBeforeFirst(sesid, columnlist.tableid);
         while (TryMoveNext(sesid, columnlist.tableid))
         {
             yield return GetColumnInfoFromColumnlist(sesid, columnlist);
         }
     }
     finally
     {
         // Close the temporary table used to return the results
         JetCloseTable(sesid, columnlist.tableid);
     }
 }
Exemple #6
0
 /// <summary>
 /// Retrieves information about all columns 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="columnName">This parameter is ignored.</param>
 /// <param name="columnlist">Filled in with information about the columns in the table.</param>
 public static void JetGetColumnInfo(
         JET_SESID sesid,
         JET_DBID dbid,
         string tablename,
         string columnName,
         out JET_COLUMNLIST columnlist)
 {
     Api.Check(Impl.JetGetColumnInfo(sesid, dbid, tablename, columnName, out columnlist));
 }
Exemple #7
0
 /// <summary>
 /// Retrieves information about all columns in the table.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table containing the column.</param>
 /// <param name="columnName">The parameter is ignored.</param>
 /// <param name="columnlist">Filled in with information about the columns in the table.</param>
 public static void JetGetTableColumnInfo(
         JET_SESID sesid,
         JET_TABLEID tableid,
         string columnName,
         out JET_COLUMNLIST columnlist)
 {
     Api.Check(Impl.JetGetTableColumnInfo(sesid, tableid, columnName, out columnlist));
 }
Exemple #8
0
 /// <summary>
 /// Iterates over the information in the JET_COLUMNLIST, returning information about each column.
 /// The table in the columnlist is closed when finished.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="columnlist">The columnlist to iterate over.</param>
 /// <returns>An iterator over ColumnInfo for each column described in the JET_COLUMNLIST.</returns>
 private static IEnumerable <ColumnInfo> EnumerateColumnInfos(JET_SESID sesid, JET_COLUMNLIST columnlist)
 {
     try
     {
         if (Api.TryMoveFirst(sesid, columnlist.tableid))
         {
             do
             {
                 yield return(GetColumnInfoFromColumnlist(sesid, columnlist));
             }while (Api.TryMoveNext(sesid, columnlist.tableid));
         }
     }
     finally
     {
         // Close the temporary table used to return the results
         JetCloseTable(sesid, columnlist.tableid);
     }
 }
        /// <summary>
        /// Creates a <see cref="ColumnDefinition"/> object representing the column passed in by <paramref name="columnList"/>.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="columnList">The <see cref="JET_COLUMNLIST"/> object that represents the row in
        /// the temptable for this particular column.</param>
        /// <returns>
        /// A <see cref="ColumnDefinition"/> object based on the current row in the temptable
        /// represented by <paramref name="columnList"/>.
        /// </returns>
        internal static ColumnDefinition Load(IsamDatabase database, string tableName, JET_COLUMNLIST columnList)
        {
            lock (database.IsamSession)
            {
                using (IsamTransaction trx = new IsamTransaction(database.IsamSession))
                {
                    // load info for the column
                    ColumnDefinition columnDefinition = new ColumnDefinition();

                    JET_SESID sesid = database.IsamSession.Sesid;

                    // If we use the wide API (Vista+), then the temp table will be in UTF-16.
                    // Technically, this should have worked in Vista. But there was a bug, and
                    // it was fixed after Windows 7.
                    Encoding encodingOfTextColumns = EsentVersion.SupportsWindows8Features
                                                         ? Encoding.Unicode
                                                         : Encoding.ASCII;

                    string columnName = Api.RetrieveColumnAsString(
                        database.IsamSession.Sesid,
                        columnList.tableid,
                        columnList.columnidcolumnname,
                        encodingOfTextColumns);
                    JET_COLUMNBASE columnbase;
                    Api.JetGetColumnInfo(database.IsamSession.Sesid, database.Dbid, tableName, columnName, out columnbase);
                    columnDefinition.columnid = new Columnid(columnbase);
                    columnDefinition.name = columnDefinition.columnid.Name;
                    columnDefinition.type = columnDefinition.columnid.Type;

                    ColumndefGrbit grbitColumn = (ColumndefGrbit)Api.RetrieveColumnAsUInt32(sesid, columnList.tableid, columnList.columnidgrbit).GetValueOrDefault();
                    columnDefinition.flags = ColumnFlagsFromGrbits(grbitColumn);

                    columnDefinition.maxLength = Api.RetrieveColumnAsInt32(sesid, columnList.tableid, columnList.columnidcbMax).GetValueOrDefault();

                    columnDefinition.IsAscii = columnbase.cp == JET_CP.ASCII;
                    byte[] defaultValueBytes = Api.RetrieveColumn(sesid, columnList.tableid, columnList.columnidDefault);

                    Columnid isamColumnid = columnDefinition.columnid;
                    columnDefinition.defaultValue = Converter.ObjectFromBytes(
                        isamColumnid.Coltyp,
                        columnDefinition.IsAscii,
                        defaultValueBytes);

                    columnDefinition.ReadOnly = true;

                    return columnDefinition;
                }
            }
        }
Exemple #10
0
 public void JetColumnlistToString()
 {
     var value = new JET_COLUMNLIST { cRecord = 3, tableid = new JET_TABLEID { Value = (IntPtr)0x1a } };
     Assert.AreEqual("JET_COLUMNLIST(0x1a,3 records)", value.ToString());
 }