Beispiel #1
0
        private IEnumerable <ColSpec> GetIndexTableDef(string tableName, string indexName)
        {
            JET_INDEXLIST indexList;

            Esent.JetGetIndexInfo(m_sesid, m_dbid, tableName, indexName, out indexList, JET_IdxInfo.List);

            // Unfortunately, Esent.GetTableColumns doesn't work on the temporary table returned by
            // JetGetIndexInfo, but the JET_INDEXLIST and the documentation have all the
            // information we need.
            var tableDef = new ColSpec[] {
                new ColSpec
                {
                    Name     = "Columns",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcColumn
                },
                new ColSpec
                {
                    Name     = "Entries",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcEntry
                },
                new ColSpec
                {
                    Name     = "UniqueKeys",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcKey
                },
                new ColSpec {
                    Name     = "Coltyp",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcoltyp
                },
                new ColSpec {
                    Name     = "ColumnId",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcolumnid
                },
                new ColSpec {
                    Name     = "ColumnName",
                    Type     = typeof(string),
                    ColumnId = indexList.columnidcolumnname
                },
                new ColSpec {
                    Name     = "CodePage",
                    Type     = typeof(Int16?),
                    ColumnId = indexList.columnidCp
                },
                new ColSpec {
                    Name     = "NumPages",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidcPage
                },
                new ColSpec {
                    Name     = "grbitColumn",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidgrbitColumn
                },
                new ColSpec {
                    Name     = "grbitIndex",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidgrbitIndex
                },
                new ColSpec {
                    Name     = "iColumn",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidiColumn
                },
                new ColSpec {
                    Name     = "IndexName",
                    Type     = typeof(string),
                    ColumnId = indexList.columnidindexname
                },
                new ColSpec {
                    Name     = "LangId",
                    Type     = typeof(Int16?),
                    ColumnId = indexList.columnidLangid
                },
                new ColSpec {
                    Name     = "LCMapFlags",
                    Type     = typeof(Int32?),
                    ColumnId = indexList.columnidLCMapFlags
                }
            };

            for (int i = 0, n = tableDef.Length; i < n; i++)
            {
                tableDef[i].Retriever = ColumnRetrievers.ForType(tableDef[i].Type);
            }

            Esent.JetCloseTable(m_sesid, indexList.tableid);

            return(tableDef);
        }
Beispiel #2
0
        private List <ColSpec> GetTableDef(JET_TABLEID table)
        {
            var columns  = new List <ColumnInfo>(Esent.GetTableColumns(m_sesid, table));
            var tableDef = new List <ColSpec>();

            foreach (var column in columns)
            {
                var colspec = new ColSpec();
                colspec.Name      = column.Name;
                colspec.ColumnId  = column.Columnid;
                colspec.Retriever = null;

                switch (column.Coltyp)
                {
                case JET_coltyp.Text:
                case JET_coltyp.LongText:
                    colspec.Type = typeof(string);
                    break;

                case JET_coltyp.Long:
                    colspec.Type = typeof(int?);
                    break;

                case JET_coltyp.Short:
                    colspec.Type = typeof(short?);
                    break;

                case JET_coltyp.UnsignedByte:
                    colspec.Type = typeof(byte?);
                    break;

                case JET_coltyp.Bit:
                    colspec.Type = typeof(bool?);
                    break;

                case JET_coltyp.DateTime:
                    colspec.Type = typeof(DateTime?);
                    break;

                case JET_coltyp.IEEEDouble:
                    colspec.Type = typeof(double?);
                    break;

                case JET_coltyp.IEEESingle:
                    colspec.Type = typeof(float?);
                    break;

                case JET_coltyp.Binary:
                case JET_coltyp.LongBinary:
                    colspec.Retriever = (s, t, c) =>
                    {
                        byte[] value = Esent.RetrieveColumn(s, t, c);
                        if (value != null)
                        {
                            return(Convert.ToBase64String(value));
                        }
                        else
                        {
                            return(value);
                        }
                    };
                    colspec.Type = typeof(string);
                    break;

                case VistaColtyp.UnsignedLong:
                    colspec.Type = typeof(UInt32?);
                    break;

                case VistaColtyp.LongLong:
                    colspec.Type = typeof(Int64?);
                    break;

                case VistaColtyp.GUID:
                    colspec.Type = typeof(Guid?);
                    break;

                case VistaColtyp.UnsignedShort:
                    colspec.Type = typeof(UInt16?);
                    break;

                default:
                    colspec.Retriever = (s, t, c) => "ERROR: unhandled type " + Enum.GetName(typeof(JET_coltyp), column.Coltyp) + "(" + (int)column.Coltyp + ")";
                    colspec.Type      = typeof(string);
                    break;
                }

                if (colspec.Retriever == null)
                {
                    colspec.Retriever = ColumnRetrievers.ForType(colspec.Type);
                }

                tableDef.Add(colspec);
            }

            return(tableDef);
        }