コード例 #1
0
        internal DataTable GetSchemaRowset(Guid schema, object[] restrictions)
        {
            DataTable table2;
            IntPtr    ptr;

            Bid.ScopeEnter(out ptr, "<oledb.OleDbConnectionInternal.GetSchemaRowset|INFO> %d#, schema=%ls, restrictions\n", base.ObjectID, schema);
            try
            {
                if (restrictions == null)
                {
                    restrictions = new object[0];
                }
                DataTable table = null;
                using (IDBSchemaRowsetWrapper wrapper = this.IDBSchemaRowset())
                {
                    System.Data.Common.UnsafeNativeMethods.IDBSchemaRowset rowset2 = wrapper.Value;
                    if (rowset2 == null)
                    {
                        throw ODB.SchemaRowsetsNotSupported(this.Provider);
                    }
                    System.Data.Common.UnsafeNativeMethods.IRowset ppRowset = null;
                    Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB> %d#\n", base.ObjectID);
                    OleDbHResult result = rowset2.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out ppRowset);
                    Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB|RET> %08X{HRESULT}\n", result);
                    if (result < OleDbHResult.S_OK)
                    {
                        this.ProcessResults(result);
                    }
                    if (ppRowset != null)
                    {
                        using (OleDbDataReader reader = new OleDbDataReader(this.Connection, null, 0, CommandBehavior.Default))
                        {
                            reader.InitializeIRowset(ppRowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
                            reader.BuildMetaInfo();
                            reader.HasRowsRead();
                            table = new DataTable {
                                Locale    = CultureInfo.InvariantCulture,
                                TableName = OleDbSchemaGuid.GetTextFromValue(schema)
                            };
                            OleDbDataAdapter.FillDataTable(reader, new DataTable[] { table });
                        }
                    }
                    return(table);
                }
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(table2);
        }
コード例 #2
0
        internal SchemaSupport[] GetSchemaRowsetInformation()
        {
            OleDbConnectionString connectionString = this.ConnectionString;

            SchemaSupport[] schemaSupport = connectionString.SchemaSupport;
            if (schemaSupport != null)
            {
                return(schemaSupport);
            }
            using (IDBSchemaRowsetWrapper wrapper = this.IDBSchemaRowset())
            {
                OleDbHResult result;
                System.Data.Common.UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value;
                if (dbSchemaRowset == null)
                {
                    return(null);
                }
                int    schemaCount        = 0;
                IntPtr ptrZero            = ADP.PtrZero;
                IntPtr schemaRestrictions = ADP.PtrZero;
                using (new DualCoTaskMem(dbSchemaRowset, out schemaCount, out ptrZero, out schemaRestrictions, out result))
                {
                    dbSchemaRowset = null;
                    if (result < OleDbHResult.S_OK)
                    {
                        this.ProcessResults(result);
                    }
                    schemaSupport = new SchemaSupport[schemaCount];
                    if (ADP.PtrZero != ptrZero)
                    {
                        int index = 0;
                        for (int i = 0; index < schemaSupport.Length; i += ODB.SizeOf_Guid)
                        {
                            IntPtr ptr = ADP.IntPtrOffset(ptrZero, index * ODB.SizeOf_Guid);
                            schemaSupport[index]._schemaRowset = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid));
                            index++;
                        }
                    }
                    if (ADP.PtrZero != schemaRestrictions)
                    {
                        for (int j = 0; j < schemaSupport.Length; j++)
                        {
                            schemaSupport[j]._restrictions = Marshal.ReadInt32(schemaRestrictions, j * 4);
                        }
                    }
                }
                connectionString.SchemaSupport = schemaSupport;
                return(schemaSupport);
            }
        }