コード例 #1
0
        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);
            }
        }
コード例 #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);
            }
        }
 internal OleDbMetaDataFactory(Stream XMLStream, string serverVersion, string serverVersionNormalized, SchemaSupport[] schemaSupport) : base(XMLStream, serverVersion, serverVersionNormalized)
 {
     this._schemaMapping = new SchemaRowsetName[] { new SchemaRowsetName(DbMetaDataCollectionNames.DataTypes, OleDbSchemaGuid.Provider_Types), new SchemaRowsetName(OleDbMetaDataCollectionNames.Catalogs, OleDbSchemaGuid.Catalogs), new SchemaRowsetName(OleDbMetaDataCollectionNames.Collations, OleDbSchemaGuid.Collations), new SchemaRowsetName(OleDbMetaDataCollectionNames.Columns, OleDbSchemaGuid.Columns), new SchemaRowsetName(OleDbMetaDataCollectionNames.Indexes, OleDbSchemaGuid.Indexes), new SchemaRowsetName(OleDbMetaDataCollectionNames.Procedures, OleDbSchemaGuid.Procedures), new SchemaRowsetName(OleDbMetaDataCollectionNames.ProcedureColumns, OleDbSchemaGuid.Procedure_Columns), new SchemaRowsetName(OleDbMetaDataCollectionNames.ProcedureParameters, OleDbSchemaGuid.Procedure_Parameters), new SchemaRowsetName(OleDbMetaDataCollectionNames.Tables, OleDbSchemaGuid.Tables), new SchemaRowsetName(OleDbMetaDataCollectionNames.Views, OleDbSchemaGuid.Views) };
     if (base.CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections] == null)
     {
         throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.MetaDataCollections);
     }
     DataTable table2 = base.CloneAndFilterCollection(DbMetaDataCollectionNames.MetaDataCollections, null);
     DataTable table = base.CollectionDataSet.Tables[DbMetaDataCollectionNames.Restrictions];
     if (table != null)
     {
         table = base.CloneAndFilterCollection(DbMetaDataCollectionNames.Restrictions, null);
     }
     DataColumn column3 = table2.Columns["PopulationMechanism"];
     if ((column3 == null) || (typeof(string) != column3.DataType))
     {
         throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections, "PopulationMechanism");
     }
     DataColumn column2 = table2.Columns["CollectionName"];
     if ((column2 == null) || (typeof(string) != column2.DataType))
     {
         throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections, "CollectionName");
     }
     DataColumn column = null;
     if (table != null)
     {
         column = table.Columns["CollectionName"];
         if ((column == null) || (typeof(string) != column.DataType))
         {
             throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.Restrictions, "CollectionName");
         }
     }
     foreach (DataRow row in table2.Rows)
     {
         string str3 = row[column3] as string;
         if (ADP.IsEmpty(str3))
         {
             throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections, "PopulationMechanism");
         }
         string str = row[column2] as string;
         if (ADP.IsEmpty(str))
         {
             throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections, "CollectionName");
         }
         if (str3 == "PrepareCollection")
         {
             int index = -1;
             for (int i = 0; i < this._schemaMapping.Length; i++)
             {
                 if (this._schemaMapping[i]._schemaName == str)
                 {
                     index = i;
                     break;
                 }
             }
             if (index != -1)
             {
                 bool flag = false;
                 if (schemaSupport != null)
                 {
                     for (int j = 0; j < schemaSupport.Length; j++)
                     {
                         if (this._schemaMapping[index]._schemaRowset == schemaSupport[j]._schemaRowset)
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 if (!flag)
                 {
                     if (table != null)
                     {
                         foreach (DataRow row2 in table.Rows)
                         {
                             string str2 = row2[column] as string;
                             if (ADP.IsEmpty(str2))
                             {
                                 throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.Restrictions, "CollectionName");
                             }
                             if (str == str2)
                             {
                                 row2.Delete();
                             }
                         }
                         table.AcceptChanges();
                     }
                     row.Delete();
                 }
             }
         }
     }
     table2.AcceptChanges();
     base.CollectionDataSet.Tables.Remove(base.CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections]);
     base.CollectionDataSet.Tables.Add(table2);
     if (table != null)
     {
         base.CollectionDataSet.Tables.Remove(base.CollectionDataSet.Tables[DbMetaDataCollectionNames.Restrictions]);
         base.CollectionDataSet.Tables.Add(table);
     }
 }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        internal OleDbMetaDataFactory(Stream XMLStream,
                                    string serverVersion,
                                    string serverVersionNormalized,
                                    SchemaSupport[] schemaSupport):
            base(XMLStream, serverVersion, serverVersionNormalized) {

            // set up the colletion mane schema rowset guid mapping
           _schemaMapping = new SchemaRowsetName[] {

                 new SchemaRowsetName(DbMetaDataCollectionNames.DataTypes,OleDbSchemaGuid.Provider_Types),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Catalogs,OleDbSchemaGuid.Catalogs),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Collations,OleDbSchemaGuid.Collations),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Columns,OleDbSchemaGuid.Columns),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Indexes,OleDbSchemaGuid.Indexes),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Procedures,OleDbSchemaGuid.Procedures),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.ProcedureColumns,OleDbSchemaGuid.Procedure_Columns),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.ProcedureParameters,OleDbSchemaGuid.Procedure_Parameters),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Tables,OleDbSchemaGuid.Tables),
                 new SchemaRowsetName(OleDbMetaDataCollectionNames.Views,OleDbSchemaGuid.Views)};

            // verify the existance of the table in the data set
            DataTable metaDataCollectionsTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections];
            if (metaDataCollectionsTable == null){
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.MetaDataCollections);
            }

            // copy the table filtering out any rows that don't apply to the current version of the provider
            metaDataCollectionsTable = CloneAndFilterCollection(DbMetaDataCollectionNames.MetaDataCollections, null);

            // verify the existance of the table in the data set
            DataTable restrictionsTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.Restrictions];
            if (restrictionsTable != null){
                // copy the table filtering out any rows that don't apply to the current version of the provider
                restrictionsTable= CloneAndFilterCollection(DbMetaDataCollectionNames.Restrictions, null);
            }

            // need to filter out any of the collections where
            // 1) it is populated using prepare collection
            // 2) it is in the collection to schema rowset mapping above
            // 3) the provider does not support the necessary schema rowset



            DataColumn populationMechanism = metaDataCollectionsTable.Columns[_populationMechanism];
            if ((null == populationMechanism) || (typeof(System.String) != populationMechanism.DataType)) {
                throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections,_populationMechanism);
            }
            DataColumn collectionName = metaDataCollectionsTable.Columns[_collectionName];
            if ((null == collectionName) || (typeof(System.String) != collectionName.DataType)) {
                 throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections,_collectionName);
            }
            DataColumn restrictionCollectionName = null;
            if (restrictionsTable != null){
                restrictionCollectionName = restrictionsTable.Columns[_collectionName];
                if ((null == restrictionCollectionName) || (typeof(System.String) != restrictionCollectionName.DataType)) {
                    throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.Restrictions,_collectionName);
                }
            }

            foreach (DataRow collection in metaDataCollectionsTable.Rows){

                string populationMechanismValue = collection[populationMechanism] as string;
                if (ADP.IsEmpty(populationMechanismValue )) {
                    throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections,_populationMechanism);
                }
                string collectionNameValue = collection[collectionName] as string;
                if (ADP.IsEmpty(collectionNameValue)) {
                    throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections,_collectionName);
                }

                if (populationMechanismValue == _prepareCollection) {
                    // is the collection in the mapping
                    int mapping = -1;
                    for (int i = 0; i < _schemaMapping.Length; i++){
                        if (_schemaMapping[i]._schemaName == collectionNameValue){
                            mapping = i;
                            break;
                        }
                    }
                    // no go on to the next collection
                    if (mapping == -1) {
                        continue;
                    }

                    // does the provider support the necessary schema rowset
                    bool isSchemaRowsetSupported = false;
                    if (schemaSupport != null){
                        for (int i = 0; i < schemaSupport.Length; i++){
                            if (_schemaMapping[mapping]._schemaRowset == schemaSupport[i]._schemaRowset){
                                isSchemaRowsetSupported = true;
                                break;
                            }
                        }
                    }
                    // if not delete the row from the table
                    if (isSchemaRowsetSupported == false){
                        // but first delete any related restrictions
                        if (restrictionsTable != null) {
                            foreach (DataRow restriction in restrictionsTable.Rows) {
                                string restrictionCollectionNameValue = restriction[restrictionCollectionName] as string;
                                if (ADP.IsEmpty(restrictionCollectionNameValue)) {
                                    throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.Restrictions,_collectionName);
                                }
                                if (collectionNameValue == restrictionCollectionNameValue) {
                                    restriction.Delete();
                                }
                            }
                            restrictionsTable.AcceptChanges();
                        }
                        collection.Delete();
                    }

                }
            }

            // replace the original table with the updated one
            metaDataCollectionsTable.AcceptChanges();
            CollectionDataSet.Tables.Remove(CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections]);
            CollectionDataSet.Tables.Add(metaDataCollectionsTable);

            if (restrictionsTable != null) {
                CollectionDataSet.Tables.Remove(CollectionDataSet.Tables[DbMetaDataCollectionNames.Restrictions]);
                CollectionDataSet.Tables.Add(restrictionsTable);
            }

        }