Information about one Esent column. This is not an interop class, but is used by the meta-data helper methods.
示例#1
0
 private static object GetvalueFromTable(Session session, Table table, ColumnInfo col)
 {
     switch (col.Coltyp)
     {
         case JET_coltyp.Long:
             return Api.RetrieveColumnAsInt32(session, table, col.Columnid);
         case JET_coltyp.DateTime:
             return Api.RetrieveColumnAsDateTime(session, table, col.Columnid);
         case JET_coltyp.Binary:
             var bytes = Api.RetrieveColumn(session, table, col.Columnid);
             if (bytes == null)
                 return null;
             if (bytes.Length == 16)
                 return new Guid(bytes);
             return Convert.ToBase64String(bytes);
         case JET_coltyp.LongText:
         case JET_coltyp.Text:
             var str = Api.RetrieveColumnAsString(session, table, col.Columnid);
             if (str == null)
                 return null;
             if (str.Contains("\""))
                 return "\"" + str.Replace("\"", "\"\"") + "\"";
             return str;
         case JET_coltyp.LongBinary:
             return "long binary val";
         default:
             throw new ArgumentOutOfRangeException("don't know how to handle coltype: " + col.Coltyp);
     }
 }
示例#2
0
 /// <summary>
 /// Create a ColumnMetaData from an Interop.ColumnInfo
 /// </summary>
 /// <param name="info">The columninfo.</param>
 /// <returns>A ColumnMetaData created from the ColumnInfo</returns>
 public ColumnMetaData CreateColumnMetaDataFromColumnInfo(ColumnInfo info)
 {
     var metadata = new ColumnMetaData
     {
         Name = info.Name,
         Type = this.ColumnTypeFromColumnInfo(info),
         IsAutoincrement =
            IsColumndefOptionSet(info.Grbit, ColumndefGrbit.ColumnAutoincrement),
         IsNotNull = IsColumndefOptionSet(info.Grbit, ColumndefGrbit.ColumnNotNULL),
         IsVersion = IsColumndefOptionSet(info.Grbit, ColumndefGrbit.ColumnVersion),
         IsEscrowUpdate =
            IsColumndefOptionSet(info.Grbit, ColumndefGrbit.ColumnEscrowUpdate),
         MaxSize = info.MaxLength,
         DefaultValue = info.DefaultValue,
         Columnid = info.Columnid
     };
     return metadata;
 }
        public void TestCreateColumnMetaDataFromColumnInfoWithAsciiColumn()
        {
            var info = new ColumnInfo(
                "ascii",
                this.columnid,
                JET_coltyp.LongText,
                JET_CP.ASCII,
                0,
                null,
                ColumndefGrbit.None);

            var expected = new ColumnMetaData
                               {
                                   Name = "ascii",
                                   Type = ColumnType.AsciiText,
                                   Columnid = this.columnid,
                               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
        public void TestCreateColumnMetaDataFromColumnInfoWithAutoinc()
        {
            var info = new ColumnInfo(
                "autoinc",
                this.columnid,
                JET_coltyp.Long,
                JET_CP.None,
                0,
                null,
                ColumndefGrbit.ColumnAutoincrement);

            var expected = new ColumnMetaData
                               {
                                   Name = "autoinc",
                                   Type = ColumnType.Int32,
                                   Columnid = this.columnid,
                                   IsAutoincrement = true,
                               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
示例#5
0
        /// <summary>
        /// Return the column type of the given column info.
        /// </summary>
        /// <param name="info">The column info object.</param>
        /// <returns>The Esent column type that the Esent column has.</returns>
        private ColumnType ColumnTypeFromColumnInfo(ColumnInfo info)
        {
            if (JET_coltyp.Text == info.Coltyp || JET_coltyp.LongText == info.Coltyp)
            {
                if (JET_CP.ASCII == info.Cp)
                {
                    return ColumnType.AsciiText;
                }

                return ColumnType.Text;
            }

            return this.coltypToColumnTypeMapping[info.Coltyp];
        }
示例#6
0
        /// <summary>
        /// Extracts the column data as the correct data type and formats appropriately
        /// </summary>
        /// <param name="session"></param>
        /// <param name="table"></param>
        /// <param name="columnInfo"></param>
        /// <returns></returns>
        public static string GetFormattedColumnData(Session session,
                                                    JET_TABLEID table,
                                                    ColumnInfo columnInfo)
        {
            try
            {
                string temp = "";

                switch (columnInfo.Coltyp)
                {
                    case JET_coltyp.Bit:
                        temp = string.Format("{0}", Api.RetrieveColumnAsBoolean(session, table, columnInfo.Columnid));
                        break;
                    case VistaColtyp.LongLong:
                    case JET_coltyp.Currency:
                        temp = string.Format("{0}", Api.RetrieveColumnAsInt64(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.IEEEDouble:
                        temp = string.Format("{0}", Api.RetrieveColumnAsDouble(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.IEEESingle:
                       temp =  string.Format("{0}", Api.RetrieveColumnAsFloat(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.Long:
                        temp = string.Format("{0}", Api.RetrieveColumnAsInt32(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.Text:
                    case JET_coltyp.LongText:
                        Encoding encoding = (columnInfo.Cp == JET_CP.Unicode) ? Encoding.Unicode : Encoding.ASCII;
                        temp = string.Format("{0}", Api.RetrieveColumnAsString(session, table, columnInfo.Columnid, encoding));
                        break;
                    case JET_coltyp.Short:
                        temp = string.Format("{0}", Api.RetrieveColumnAsInt16(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.UnsignedByte:
                        temp = string.Format("{0}", Api.RetrieveColumnAsByte(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.DateTime:
                        temp = string.Format("{0}", Api.RetrieveColumnAsDateTime(session, table, columnInfo.Columnid));
                        break;
                    case VistaColtyp.UnsignedShort:
                        temp = string.Format("{0}", Api.RetrieveColumnAsUInt16(session, table, columnInfo.Columnid));
                        break;
                    case VistaColtyp.UnsignedLong:
                        temp = string.Format("{0}", Api.RetrieveColumnAsUInt32(session, table, columnInfo.Columnid));
                        break;
                    case VistaColtyp.GUID:
                        temp = string.Format("{0}", Api.RetrieveColumnAsGuid(session, table, columnInfo.Columnid));
                        break;
                    case JET_coltyp.Binary:
                    case JET_coltyp.LongBinary:
                    default:
                        temp = FormatBytes(Api.RetrieveColumn(session, table, columnInfo.Columnid));
                        break;
                }

                if (temp == null) {
                    return "";
                }

                return temp;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error formatting data: " + ex.ToString());
                return string.Empty;
            }
        }
        public void TestCreateColumnMetaDataFromColumnInfoWithVersionColumn()
        {
            var info = new ColumnInfo(
                "version",
                this.columnid,
                JET_coltyp.Long,
                JET_CP.None,
                0,
                null,
                ColumndefGrbit.ColumnVersion);

            var expected = new ColumnMetaData
                               {
                                   Name = "version",
                                   Type = ColumnType.Int32,
                                   Columnid = this.columnid,
                                   IsVersion = true,
                               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
        /// <summary>
        /// Verify that CreateColumnMetaDataFromColumnInfo sets the specified ColumnType.
        /// </summary>
        /// <param name="jetColtyp">The coltyp for the ColumnInfo.</param>
        /// <param name="type">The expected ColumnType in the ColumnMetaData.</param>
        private void VerifyCreateColumnMetaDataSetsType(JET_coltyp jetColtyp, ColumnType type)
        {
            var info = new ColumnInfo(
                "test",
                this.columnid,
                jetColtyp,
                JET_CP.None,
                0,
                null,
                ColumndefGrbit.None);

            var expected = new ColumnMetaData
                               {
                                   Name = "test",
                                   Type = type,
                                   Columnid = this.columnid,
                               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
        public void TestCreateColumnMetaDataFromColumnInfoWithUnicodeColumn()
        {
            var info = new ColumnInfo(
                "unicode",
                this.columnid,
                JET_coltyp.Text,
                JET_CP.Unicode,
                0,
                null,
                ColumndefGrbit.None);

            var expected = new ColumnMetaData
                               {
                                   Name = "unicode",
                                   Type = ColumnType.Text,
                                   Columnid = this.columnid,
                               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
示例#10
0
        public void TestCreateColumnMetaDataFromColumnInfoWithEscrowUpdate()
        {
            var info = new ColumnInfo(
                "escrow_update",
                this.columnid,
                JET_coltyp.Long,
                JET_CP.None,
                0,
                null,
                ColumndefGrbit.ColumnEscrowUpdate);

            var expected = new ColumnMetaData
               {
                   Name = "escrow_update",
                   Type = ColumnType.Int32,
                   Columnid = this.columnid,
                   IsEscrowUpdate = true,
               };

            AssertColumnMetaDataAreEqual(expected, this.converter.CreateColumnMetaDataFromColumnInfo(info));
        }
示例#11
0
        private void RefreshTableInfo()
        {
            columnInfos = new List<ColumnInfo>();
            foreach (var ci in Api.GetTableColumns(connection.session, connection.dbid, name)) {
                if ((ci.Grbit & ColumndefGrbit.ColumnAutoincrement) > 0) {
                    autoIncrementColumn = ci;
                    hasAutoIncrementColumn = true;
                }
                columnInfos.Add(ci);
            }

            indexes = Api.GetTableIndexes(connection.session, connection.dbid, name);
            foreach (var index in indexes) {
                // primary key is only on one column
                if ((index.Grbit & CreateIndexGrbit.IndexPrimary) > 0) {
                    primaryKeyColumn = index.IndexSegments[0].ColumnName;
                }
            }
        }
示例#12
0
 // separated LV columns should always be set and should be forced to be separate
 private bool IsColumnSeparatedLV(ColumnInfo columnInfo)
 {
     return columnInfo.Name.StartsWith("separated");
 }
示例#13
0
        /// <summary>
        /// Create a ColumnMetaData object from a ColumnInfo.
        /// </summary>
        /// <param name="columninfo">The ColumnInfo for the column.</param>
        /// <returns>A ColumnMetaData object for the column.</returns>
        private static ColumnMetaData GetMetadata(ColumnInfo columninfo)
        {
            var converter = Dependencies.Container.Resolve<InteropConversion>();
            var dataConversion = Dependencies.Container.Resolve<DataConversion>();

            ColumnMetaData metadata = converter.CreateColumnMetaDataFromColumnInfo(columninfo);

            metadata.ObjectConverter = dataConversion.ConvertToObject[metadata.Type];
            metadata.ObjectToBytesConverter = dataConversion.ConvertObjectToBytes[metadata.Type];
            metadata.BytesToObjectConverter = dataConversion.ConvertBytesToObject[metadata.Type];

            metadata.SetColumn = (cursor, obj) =>
            {
                byte[] data = metadata.ObjectToBytesConverter(metadata.ObjectConverter(obj));
                cursor.SetColumn(metadata.Columnid, data, SetColumnGrbit.None);
            };

            metadata.MakeKey = (cursor, obj, grbit) =>
            {
                byte[] data = metadata.ObjectToBytesConverter(metadata.ObjectConverter(obj));
                cursor.MakeKey(data, grbit);
            };

            metadata.RetrieveColumn = MakeRetrieveColumnFunction(metadata);

            return metadata;
        }