public DataTable GetOleDbSchemaTable(Guid schema, object[] restrictions)   // MDAC 61846
        {
            OleDbConnection.ExecutePermission.Demand();

            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<oledb.OleDbConnection.GetOleDbSchemaTable|API> %d#, schema=%ls, restrictions\n", ObjectID, schema);
            try {
                CheckStateOpen(ADP.GetOleDbSchemaTable);
                OleDbConnectionInternal connection = GetOpenConnection();

                if (OleDbSchemaGuid.DbInfoLiterals == schema)
                {
                    if ((null == restrictions) || (0 == restrictions.Length))
                    {
                        return(connection.BuildInfoLiterals());
                    }
                    throw ODB.InvalidRestrictionsDbInfoLiteral("restrictions");
                }
                else if (OleDbSchemaGuid.SchemaGuids == schema)
                {
                    if ((null == restrictions) || (0 == restrictions.Length))
                    {
                        return(connection.BuildSchemaGuids());
                    }
                    throw ODB.InvalidRestrictionsSchemaGuids("restrictions");
                }
                else if (OleDbSchemaGuid.DbInfoKeywords == schema)
                {
                    if ((null == restrictions) || (0 == restrictions.Length))
                    {
                        return(connection.BuildInfoKeywords());
                    }
                    throw ODB.InvalidRestrictionsDbInfoKeywords("restrictions");
                }

                if (connection.SupportSchemaRowset(schema))
                {
                    return(connection.GetSchemaRowset(schema, restrictions));
                }
                else
                {
                    using (IDBSchemaRowsetWrapper wrapper = connection.IDBSchemaRowset()) {
                        if (null == wrapper.Value)
                        {
                            throw ODB.SchemaRowsetsNotSupported(Provider); // MDAC 72689
                        }
                    }
                    throw ODB.NotSupportedSchemaTable(schema, this); // MDAC 63279
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Esempio n. 2
0
        public DataTable GetOleDbSchemaTable(Guid schema, object[] restrictions)
        {
            DataTable table;
            IntPtr    ptr;

            ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<oledb.OleDbConnection.GetOleDbSchemaTable|API> %d#, schema=%ls, restrictions\n", this.ObjectID, schema);
            try
            {
                this.CheckStateOpen("GetOleDbSchemaTable");
                OleDbConnectionInternal openConnection = this.GetOpenConnection();
                if (OleDbSchemaGuid.DbInfoLiterals == schema)
                {
                    if ((restrictions != null) && (restrictions.Length != 0))
                    {
                        throw ODB.InvalidRestrictionsDbInfoLiteral("restrictions");
                    }
                    return(openConnection.BuildInfoLiterals());
                }
                if (OleDbSchemaGuid.SchemaGuids == schema)
                {
                    if ((restrictions != null) && (restrictions.Length != 0))
                    {
                        throw ODB.InvalidRestrictionsSchemaGuids("restrictions");
                    }
                    return(openConnection.BuildSchemaGuids());
                }
                if (OleDbSchemaGuid.DbInfoKeywords == schema)
                {
                    if ((restrictions != null) && (restrictions.Length != 0))
                    {
                        throw ODB.InvalidRestrictionsDbInfoKeywords("restrictions");
                    }
                    return(openConnection.BuildInfoKeywords());
                }
                if (openConnection.SupportSchemaRowset(schema))
                {
                    return(openConnection.GetSchemaRowset(schema, restrictions));
                }
                using (IDBSchemaRowsetWrapper wrapper = openConnection.IDBSchemaRowset())
                {
                    if (wrapper.Value == null)
                    {
                        throw ODB.SchemaRowsetsNotSupported(this.Provider);
                    }
                }
                throw ODB.NotSupportedSchemaTable(schema, this);
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(table);
        }
        internal SchemaSupport[] GetSchemaRowsetInformation()
        {
            OleDbConnectionString constr = ConnectionString;

            SchemaSupport[] supportedSchemas = constr.SchemaSupport;
            if (null != supportedSchemas)
            {
                return(supportedSchemas);
            }
            using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset())
            {
                UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value;
                if (null == dbSchemaRowset)
                {
                    return(null); // IDBSchemaRowset not supported
                }

                OleDbHResult hr;
                int          schemaCount        = 0;
                IntPtr       schemaGuids        = ADP.PtrZero;
                IntPtr       schemaRestrictions = ADP.PtrZero;

                using (DualCoTaskMem safehandle = new DualCoTaskMem(dbSchemaRowset, out schemaCount, out schemaGuids, out schemaRestrictions, out hr))
                {
                    dbSchemaRowset = null;
                    if (hr < 0)
                    { // ignore infomsg
                        ProcessResults(hr);
                    }

                    supportedSchemas = new SchemaSupport[schemaCount];
                    if (ADP.PtrZero != schemaGuids)
                    {
                        for (int i = 0, offset = 0; i < supportedSchemas.Length; ++i, offset += ODB.SizeOf_Guid)
                        {
                            IntPtr ptr = ADP.IntPtrOffset(schemaGuids, i * ODB.SizeOf_Guid);
                            supportedSchemas[i]._schemaRowset = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid));
                        }
                    }
                    if (ADP.PtrZero != schemaRestrictions)
                    {
                        for (int i = 0; i < supportedSchemas.Length; ++i)
                        {
                            supportedSchemas[i]._restrictions = Marshal.ReadInt32(schemaRestrictions, i * 4);
                        }
                    }
                }
                constr.SchemaSupport = supportedSchemas;
                return(supportedSchemas);
            }
        }
        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);
        }
        internal DataTable GetSchemaRowset(Guid schema, object[] restrictions)
        {
            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<oledb.OleDbConnectionInternal.GetSchemaRowset|INFO> %d#, schema=%ls, restrictions\n", ObjectID, schema);
            try {
                if (null == restrictions)   // MDAC 62243
                {
                    restrictions = new object[0];
                }
                DataTable dataTable = null;
                using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset()) {
                    UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value;
                    if (null == dbSchemaRowset)
                    {
                        throw ODB.SchemaRowsetsNotSupported(Provider);
                    }

                    UnsafeNativeMethods.IRowset rowset = null;
                    OleDbHResult hr;

                    Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB> %d#\n", ObjectID);
                    hr = dbSchemaRowset.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out rowset);
                    Bid.Trace("<oledb.IDBSchemaRowset.GetRowset|API|OLEDB|RET> %08X{HRESULT}\n", hr);

                    if (hr < 0)   // ignore infomsg
                    {
                        ProcessResults(hr);
                    }

                    if (null != rowset)
                    {
                        using (OleDbDataReader dataReader = new OleDbDataReader(Connection, null, 0, CommandBehavior.Default)) {
                            dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
                            dataReader.BuildMetaInfo();
                            dataReader.HasRowsRead();

                            dataTable           = new DataTable();
                            dataTable.Locale    = CultureInfo.InvariantCulture;
                            dataTable.TableName = OleDbSchemaGuid.GetTextFromValue(schema);
                            OleDbDataAdapter.FillDataTable(dataReader, dataTable);
                        }
                    }
                    return(dataTable);
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
        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);
            }
        }
Esempio n. 7
0
        public DataTable GetOleDbSchemaTable(Guid schema, object[] restrictions)
        {
            CheckStateOpen(ADP.GetOleDbSchemaTable);
            OleDbConnectionInternal connection = GetOpenConnection();

            if (OleDbSchemaGuid.DbInfoLiterals == schema)
            {
                if ((null == restrictions) || (0 == restrictions.Length))
                {
                    return(connection.BuildInfoLiterals());
                }
                throw ODB.InvalidRestrictionsDbInfoLiteral("restrictions");
            }
            else if (OleDbSchemaGuid.SchemaGuids == schema)
            {
                if ((null == restrictions) || (0 == restrictions.Length))
                {
                    return(connection.BuildSchemaGuids());
                }
                throw ODB.InvalidRestrictionsSchemaGuids("restrictions");
            }
            else if (OleDbSchemaGuid.DbInfoKeywords == schema)
            {
                if ((null == restrictions) || (0 == restrictions.Length))
                {
                    return(connection.BuildInfoKeywords());
                }
                throw ODB.InvalidRestrictionsDbInfoKeywords("restrictions");
            }

            if (connection.SupportSchemaRowset(schema))
            {
                return(connection.GetSchemaRowset(schema, restrictions));
            }
            else
            {
                using (IDBSchemaRowsetWrapper wrapper = connection.IDBSchemaRowset())
                {
                    if (null == wrapper.Value)
                    {
                        throw ODB.SchemaRowsetsNotSupported(Provider);
                    }
                }
                throw ODB.NotSupportedSchemaTable(schema, this);
            }
        }
        internal DataTable GetSchemaRowset(Guid schema, object[] restrictions)
        {
            if (null == restrictions)
            {
                restrictions = Array.Empty <object>();
            }
            DataTable dataTable = null;

            using (IDBSchemaRowsetWrapper wrapper = IDBSchemaRowset())
            {
                UnsafeNativeMethods.IDBSchemaRowset dbSchemaRowset = wrapper.Value;
                if (null == dbSchemaRowset)
                {
                    throw ODB.SchemaRowsetsNotSupported(Provider);
                }

                UnsafeNativeMethods.IRowset rowset = null;
                OleDbHResult hr;
                hr = dbSchemaRowset.GetRowset(ADP.PtrZero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, ADP.PtrZero, out rowset);

                if (hr < 0)
                { // ignore infomsg
                    ProcessResults(hr);
                }

                if (null != rowset)
                {
                    using (OleDbDataReader dataReader = new OleDbDataReader(Connection, null, 0, CommandBehavior.Default))
                    {
                        dataReader.InitializeIRowset(rowset, ChapterHandle.DB_NULL_HCHAPTER, IntPtr.Zero);
                        dataReader.BuildMetaInfo();
                        dataReader.HasRowsRead();

                        dataTable           = new DataTable();
                        dataTable.Locale    = CultureInfo.InvariantCulture;
                        dataTable.TableName = OleDbSchemaGuid.GetTextFromValue(schema);
                        OleDbDataAdapter.FillDataTable(dataReader, dataTable);
                    }
                }
                return(dataTable);
            }
        }