protected override DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
        {
            cacheMetaDataFactory = false;
            OleDbConnectionInternal internal2  = (OleDbConnectionInternal)internalConnection;
            OleDbConnection         connection = internal2.Connection;
            NameValueCollection     section    = (NameValueCollection)System.Configuration.PrivilegedConfigurationManager.GetSection("system.data.oledb");
            Stream xMLStream = null;
            string dataSourcePropertyValue = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 0x60) as string;

            if (section != null)
            {
                string[] values = null;
                string   name   = null;
                if (dataSourcePropertyValue != null)
                {
                    name   = dataSourcePropertyValue + ":MetaDataXml";
                    values = section.GetValues(name);
                }
                if (values == null)
                {
                    name   = "defaultMetaDataXml";
                    values = section.GetValues(name);
                }
                if (values != null)
                {
                    xMLStream = ADP.GetXmlStreamFromValues(values, name);
                }
            }
            if (xMLStream == null)
            {
                xMLStream            = Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
                cacheMetaDataFactory = true;
            }
            return(new OleDbMetaDataFactory(xMLStream, internal2.ServerVersion, internal2.ServerVersion, internal2.GetSchemaRowsetInformation()));
        }
示例#2
0
        internal void GetLiteralQuotes(string method, out string quotePrefix, out string quoteSuffix)
        {
            this.CheckStateOpen(method);
            OleDbConnectionPoolGroupProviderInfo providerInfo = this.ProviderInfo;

            if (providerInfo.HasQuoteFix)
            {
                quotePrefix = providerInfo.QuotePrefix;
                quoteSuffix = providerInfo.QuoteSuffix;
            }
            else
            {
                OleDbConnectionInternal openConnection = this.GetOpenConnection();
                quotePrefix = openConnection.GetLiteralInfo(15);
                quoteSuffix = openConnection.GetLiteralInfo(0x1c);
                if (quotePrefix == null)
                {
                    quotePrefix = "";
                }
                if (quoteSuffix == null)
                {
                    quoteSuffix = quotePrefix;
                }
                providerInfo.SetQuoteFix(quotePrefix, quoteSuffix);
            }
        }
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
        {
            Debug.Assert(internalConnection != null, "internalConnection may not be null.");
            cacheMetaDataFactory = false;


            OleDbConnectionInternal oleDbInternalConnection = (OleDbConnectionInternal)internalConnection;
            OleDbConnection         oleDbOuterConnection    = oleDbInternalConnection.Connection;

            Debug.Assert(oleDbOuterConnection != null, "outer connection may not be null.");

            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oledb");
            Stream XMLStream             = null;
            String providerFileName      = oleDbOuterConnection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, ODB.DBPROP_PROVIDERFILENAME) as string;

            if (settings != null)
            {
                string [] values      = null;
                string    metaDataXML = null;
                // first try to get the provider specific xml

                // if providerfilename is not supported we can't build the settings key needed to
                // get the provider specific XML path
                if (providerFileName != null)
                {
                    metaDataXML = providerFileName + _metaDataXml;
                    values      = settings.GetValues(metaDataXML);
                }

                // if we did not find provider specific xml see if there is new default xml
                if (values == null)
                {
                    metaDataXML = _defaultMetaDataXml;
                    values      = settings.GetValues(metaDataXML);
                }

                // If there is new XML get it
                if (values != null)
                {
                    XMLStream = ADP.GetXmlStreamFromValues(values, metaDataXML);
                }
            }

            // if the xml was not obtained from machine.config use the embedded XML resource
            if (XMLStream == null)
            {
                XMLStream            = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
                cacheMetaDataFactory = true;
            }

            Debug.Assert(XMLStream != null, "XMLstream may not be null.");

            // using the ServerVersion as the NormalizedServerVersion. Doing this for two reasons
            //  1) The Spec for DBPROP_DBMSVER normalizes the ServerVersion
            //  2) for OLE DB its the only game in town
            return(new OleDbMetaDataFactory(XMLStream,
                                            oleDbInternalConnection.ServerVersion,
                                            oleDbInternalConnection.ServerVersion,
                                            oleDbInternalConnection.GetSchemaRowsetInformation()));
        }
示例#4
0
        private DataTable GetReservedWordsTable(OleDbConnectionInternal internalConnection)
        {
            // verify the existance of the table in the data set
            DataTable reservedWordsTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.ReservedWords];

            if (null == reservedWordsTable)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
            }

            // copy the table filtering out any rows that don't apply to tho current version of the prrovider
            reservedWordsTable = CloneAndFilterCollection(DbMetaDataCollectionNames.ReservedWords, null);

            DataColumn reservedWordColumn = reservedWordsTable.Columns[DbMetaDataColumnNames.ReservedWord];

            if (null == reservedWordColumn)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
            }

            if (!internalConnection.AddInfoKeywordsToTable(reservedWordsTable, reservedWordColumn))
            {
                throw ODB.IDBInfoNotSupported();
            }

            return(reservedWordsTable);
        }
示例#5
0
        internal void GetLiteralQuotes(string method, out string quotePrefix, out string quoteSuffix)
        {
            CheckStateOpen(method);
            OleDbConnectionPoolGroupProviderInfo info = ProviderInfo;

            if (info.HasQuoteFix)
            {
                quotePrefix = info.QuotePrefix;
                quoteSuffix = info.QuoteSuffix;
            }
            else
            {
                OleDbConnectionInternal connection = GetOpenConnection();
                quotePrefix = connection.GetLiteralInfo(ODB.DBLITERAL_QUOTE_PREFIX);
                quoteSuffix = connection.GetLiteralInfo(ODB.DBLITERAL_QUOTE_SUFFIX);
                if (null == quotePrefix)
                {
                    quotePrefix = "";
                }
                if (null == quoteSuffix)
                {
                    quoteSuffix = quotePrefix;
                }
                info.SetQuoteFix(quotePrefix, quoteSuffix);
            }
        }
示例#6
0
        private Dictionary <string, OleDbPropertyInfo> GetProviderInfo(string provider)
        {
            Dictionary <string, OleDbPropertyInfo>?providerInfo = _propertyInfo;

            if (null == providerInfo)
            {
                providerInfo = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider))
                {
                    Dictionary <string, OleDbPropertyInfo>?hash = null;
                    try
                    {
                        StringBuilder builder = new StringBuilder();
                        AppendKeyValuePair(builder, DbConnectionStringKeywords.Provider, provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);

                        // load provider without calling Initialize or CreateDataSource
                        using (OleDbConnectionInternal connection = new OleDbConnectionInternal(constr, null))
                        {
                            // get all the init property information for the provider
                            hash = connection.GetPropertyInfo(new Guid[] { OleDbPropertySetGuid.DBInitAll }) !;
                            foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                            {
                                Keywords          index;
                                OleDbPropertyInfo info = entry.Value;
                                if (!s_keywords.TryGetValue(info._description !, out index))
                                {
                                    if ((OleDbPropertySetGuid.DBInit == info._propertySet) &&
                                        ((ODB.DBPROP_INIT_ASYNCH == info._propertyID) ||
                                         (ODB.DBPROP_INIT_HWND == info._propertyID) ||
                                         (ODB.DBPROP_INIT_PROMPT == info._propertyID)))
                                    {
                                        continue; // skip this keyword
                                    }
                                    providerInfo[info._description !] = info;
        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);
            }
        }
示例#8
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);
        }
示例#9
0
        internal bool HasLiveReader(OleDbCommand cmd)
        {
            bool flag = false;
            OleDbConnectionInternal openConnection = this.GetOpenConnection();

            if (openConnection != null)
            {
                flag = openConnection.HasLiveReader(cmd);
            }
            return(flag);
        }
示例#10
0
        internal bool HasLiveReader(OleDbCommand cmd)
        {
            bool result = false;
            OleDbConnectionInternal openConnection = GetOpenConnection();

            if (null != openConnection)
            {
                result = openConnection.HasLiveReader(cmd);
            }
            return(result);
        }
        // @devnote: should be multithread safe
        static public void ReleaseObjectPool()
        {
            (new OleDbPermission(PermissionState.Unrestricted)).Demand();

            IntPtr hscp;

            Bid.ScopeEnter(out hscp, "<oledb.OleDbConnection.ReleaseObjectPool|API>\n");
            try {
                OleDbConnectionString.ReleaseObjectPool();
                OleDbConnectionInternal.ReleaseObjectPool();
                OleDbConnectionFactory.SingletonInstance.ClearAllPools();
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
示例#12
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);
            }
        }
        private DataTable GetReservedWordsTable(OleDbConnectionInternal internalConnection)
        {
            if (base.CollectionDataSet.Tables[DbMetaDataCollectionNames.ReservedWords] == null)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
            }
            DataTable  table   = base.CloneAndFilterCollection(DbMetaDataCollectionNames.ReservedWords, null);
            DataColumn keyword = table.Columns[DbMetaDataColumnNames.ReservedWord];

            if (keyword == null)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
            }
            if (!internalConnection.AddInfoKeywordsToTable(table, keyword))
            {
                throw ODB.IDBInfoNotSupported();
            }
            return(table);
        }
示例#14
0
        protected override DataTable PrepareCollection(string collectionName, string[] restrictions, DbConnection connection)
        {
            OleDbConnection         oleDbConnection         = (OleDbConnection)connection;
            OleDbConnectionInternal oleDbInternalConnection = (OleDbConnectionInternal)(oleDbConnection.InnerConnection);
            DataTable resultTable = null;

            if (collectionName == DbMetaDataCollectionNames.DataSourceInformation)
            {
                if (ADP.IsEmptyArray(restrictions) == false)
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataSourceInformation);
                }
                resultTable = GetDataSourceInformationTable(oleDbConnection, oleDbInternalConnection);
            }
            else if (collectionName == DbMetaDataCollectionNames.DataTypes)
            {
                if (ADP.IsEmptyArray(restrictions) == false)
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataTypes);
                }
                resultTable = GetDataTypesTable(oleDbConnection);
            }
            else if (collectionName == DbMetaDataCollectionNames.ReservedWords)
            {
                if (ADP.IsEmptyArray(restrictions) == false)
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.ReservedWords);
                }
                resultTable = GetReservedWordsTable(oleDbInternalConnection);
            }
            else
            {
                for (int i = 0; i < _schemaMapping.Length; i++)
                {
                    if (_schemaMapping[i]._schemaName == collectionName)
                    {
                        // need to special case the oledb schema rowset restrictions on columns that are not
                        // string tpyes
                        object[] mungedRestrictions = restrictions;
                        ;
                        if (restrictions != null)
                        {
                            //verify that there are not too many restrictions
                            DataTable metaDataCollectionsTable     = CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections];
                            int       numberOfSupportedRestictions = -1;
                            // prepare colletion is called with the exact collection name so
                            // we can do an exact string comparision here
                            foreach (DataRow row in metaDataCollectionsTable.Rows)
                            {
                                string candidateCollectionName = ((string)row[DbMetaDataColumnNames.CollectionName, DataRowVersion.Current]);

                                if (collectionName == candidateCollectionName)
                                {
                                    numberOfSupportedRestictions = (int)row[DbMetaDataColumnNames.NumberOfRestrictions];
                                    if (numberOfSupportedRestictions < restrictions.Length)
                                    {
                                        throw ADP.TooManyRestrictions(collectionName);
                                    }
                                    break;
                                }
                            }

                            Debug.Assert(numberOfSupportedRestictions != -1, "PrepareCollection was called for an collection that is not supported.");

                            // the 4th restrictionon the indexes schema rowset(type) is an I2 - enum
                            const int indexRestrictionTypeSlot = 3;

                            if ((collectionName == OleDbMetaDataCollectionNames.Indexes) &&
                                (restrictions.Length >= indexRestrictionTypeSlot + 1) &&
                                (restrictions[indexRestrictionTypeSlot] != null))
                            {
                                mungedRestrictions = new object[restrictions.Length];
                                for (int j = 0; j < restrictions.Length; j++)
                                {
                                    mungedRestrictions[j] = restrictions[j];
                                }

                                ushort indexTypeValue;

                                if ((restrictions[indexRestrictionTypeSlot] == "DBPROPVAL_IT_BTREE") ||
                                    (restrictions[indexRestrictionTypeSlot] == "1"))
                                {
                                    indexTypeValue = 1;
                                }
                                else if ((restrictions[indexRestrictionTypeSlot] == "DBPROPVAL_IT_HASH") ||
                                         (restrictions[indexRestrictionTypeSlot] == "2"))
                                {
                                    indexTypeValue = 2;
                                }
                                else if ((restrictions[indexRestrictionTypeSlot] == "DBPROPVAL_IT_CONTENT") ||
                                         (restrictions[indexRestrictionTypeSlot] == "3"))
                                {
                                    indexTypeValue = 3;
                                }
                                else if ((restrictions[indexRestrictionTypeSlot] == "DBPROPVAL_IT_OTHER") ||
                                         (restrictions[indexRestrictionTypeSlot] == "4"))
                                {
                                    indexTypeValue = 4;
                                }
                                else
                                {
                                    throw ADP.InvalidRestrictionValue(collectionName, "TYPE", restrictions[indexRestrictionTypeSlot]);
                                }

                                mungedRestrictions[indexRestrictionTypeSlot] = indexTypeValue;
                            }

                            // the 4th restrictionon the procedures schema rowset(type) is an I2 - enum
                            const int procedureRestrictionTypeSlot = 3;

                            if ((collectionName == OleDbMetaDataCollectionNames.Procedures) &&
                                (restrictions.Length >= procedureRestrictionTypeSlot + 1) &&
                                (restrictions[procedureRestrictionTypeSlot] != null))
                            {
                                mungedRestrictions = new object[restrictions.Length];
                                for (int j = 0; j < restrictions.Length; j++)
                                {
                                    mungedRestrictions[j] = restrictions[j];
                                }

                                short procedureTypeValue;

                                if ((restrictions[procedureRestrictionTypeSlot] == "DB_PT_UNKNOWN") ||
                                    (restrictions[procedureRestrictionTypeSlot] == "1"))
                                {
                                    procedureTypeValue = 1;
                                }
                                else if ((restrictions[procedureRestrictionTypeSlot] == "DB_PT_PROCEDURE") ||
                                         (restrictions[procedureRestrictionTypeSlot] == "2"))
                                {
                                    procedureTypeValue = 2;
                                }
                                else if ((restrictions[procedureRestrictionTypeSlot] == "DB_PT_FUNCTION") ||
                                         (restrictions[procedureRestrictionTypeSlot] == "3"))
                                {
                                    procedureTypeValue = 3;
                                }
                                else
                                {
                                    throw ADP.InvalidRestrictionValue(collectionName, "PROCEDURE_TYPE", restrictions[procedureRestrictionTypeSlot]);
                                }

                                mungedRestrictions[procedureRestrictionTypeSlot] = procedureTypeValue;
                            }
                        }

                        resultTable = oleDbConnection.GetOleDbSchemaTable((System.Guid)_schemaMapping[i]._schemaRowset, mungedRestrictions);
                        break;
                    }
                }
            }

            if (resultTable == null)
            {
                throw ADP.UnableToBuildCollection(collectionName);
            }

            return(resultTable);
        }
示例#15
0
        private DataTable GetReservedWordsTable(OleDbConnectionInternal internalConnection){

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

            // copy the table filtering out any rows that don't apply to tho current version of the prrovider
            reservedWordsTable = CloneAndFilterCollection(DbMetaDataCollectionNames.ReservedWords, null);

            DataColumn reservedWordColumn = reservedWordsTable.Columns[DbMetaDataColumnNames.ReservedWord];
            if (null == reservedWordColumn){
                    throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
            }

            if (!internalConnection.AddInfoKeywordsToTable(reservedWordsTable, reservedWordColumn)){
                    throw ODB.IDBInfoNotSupported();
            }

            return  reservedWordsTable;
        }
        private DataTable GetDataSourceInformationTable(OleDbConnection connection, OleDbConnectionInternal internalConnection)
        {
            string str3;
            string str4;
            if (base.CollectionDataSet.Tables[DbMetaDataCollectionNames.DataSourceInformation] == null)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.DataSourceInformation);
            }
            DataTable table = base.CloneAndFilterCollection(DbMetaDataCollectionNames.DataSourceInformation, null);
            if (table.Rows.Count != 1)
            {
                throw ADP.IncorrectNumberOfDataSourceInformationRows();
            }
            DataRow row = table.Rows[0];
            string literalInfo = internalConnection.GetLiteralInfo(3);
            string unescapedString = internalConnection.GetLiteralInfo(0x1b);
            if (literalInfo != null)
            {
                StringBuilder builder3 = new StringBuilder();
                StringBuilder escapedString = new StringBuilder();
                ADP.EscapeSpecialCharacters(literalInfo, escapedString);
                builder3.Append(escapedString.ToString());
                if ((unescapedString != null) && (unescapedString != literalInfo))
                {
                    builder3.Append("|");
                    escapedString.Length = 0;
                    ADP.EscapeSpecialCharacters(unescapedString, escapedString);
                    builder3.Append(escapedString.ToString());
                }
                row[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = builder3.ToString();
            }
            else if (unescapedString != null)
            {
                StringBuilder builder4 = new StringBuilder();
                ADP.EscapeSpecialCharacters(unescapedString, builder4);
                row[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = builder4.ToString();
            }
            object dataSourcePropertyValue = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 40);
            if (dataSourcePropertyValue != null)
            {
                row[DbMetaDataColumnNames.DataSourceProductName] = (string) dataSourcePropertyValue;
            }
            row[DbMetaDataColumnNames.DataSourceProductVersion] = base.ServerVersion;
            row[DbMetaDataColumnNames.DataSourceProductVersionNormalized] = base.ServerVersionNormalized;
            row[DbMetaDataColumnNames.ParameterMarkerFormat] = "?";
            row[DbMetaDataColumnNames.ParameterMarkerPattern] = @"\?";
            row[DbMetaDataColumnNames.ParameterNameMaxLength] = 0;
            dataSourcePropertyValue = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 0x2c);
            GroupByBehavior unknown = GroupByBehavior.Unknown;
            if (dataSourcePropertyValue != null)
            {
                switch (((int) dataSourcePropertyValue))
                {
                    case 1:
                        unknown = GroupByBehavior.NotSupported;
                        break;

                    case 2:
                        unknown = GroupByBehavior.ExactMatch;
                        break;

                    case 4:
                        unknown = GroupByBehavior.MustContainAll;
                        break;

                    case 8:
                        unknown = GroupByBehavior.Unrelated;
                        break;
                }
            }
            row[DbMetaDataColumnNames.GroupByBehavior] = unknown;
            this.SetIdentifierCase(DbMetaDataColumnNames.IdentifierCase, 0x2e, row, connection);
            this.SetIdentifierCase(DbMetaDataColumnNames.QuotedIdentifierCase, 100, row, connection);
            dataSourcePropertyValue = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 0x55);
            if (dataSourcePropertyValue != null)
            {
                row[DbMetaDataColumnNames.OrderByColumnsInSelect] = (bool) dataSourcePropertyValue;
            }
            DataTable table2 = internalConnection.BuildInfoLiterals();
            if (table2 != null)
            {
                DataRow[] rowArray = table2.Select("Literal = " + 0x11.ToString(CultureInfo.InvariantCulture));
                if (rowArray != null)
                {
                    object obj4 = rowArray[0]["InvalidChars"];
                    if (obj4.GetType() == typeof(string))
                    {
                        string str6;
                        string invalidChars = (string) obj4;
                        object obj3 = rowArray[0]["InvalidStartingChars"];
                        if (obj3.GetType() == typeof(string))
                        {
                            str6 = (string) obj3;
                        }
                        else
                        {
                            str6 = invalidChars;
                        }
                        row[DbMetaDataColumnNames.IdentifierPattern] = this.BuildRegularExpression(invalidChars, str6);
                    }
                }
            }
            connection.GetLiteralQuotes("GetSchema", out str4, out str3);
            if (str4 != null)
            {
                if (str3 == null)
                {
                    str3 = str4;
                }
                if (str3.Length == 1)
                {
                    StringBuilder builder = new StringBuilder();
                    ADP.EscapeSpecialCharacters(str3, builder);
                    string str2 = builder.ToString();
                    builder.Length = 0;
                    ADP.EscapeSpecialCharacters(str4, builder);
                    builder.Append("(([^");
                    builder.Append(str2);
                    builder.Append("]|");
                    builder.Append(str2);
                    builder.Append(str2);
                    builder.Append(")*)");
                    builder.Append(str2);
                    row[DbMetaDataColumnNames.QuotedIdentifierPattern] = builder.ToString();
                }
            }
            table.AcceptChanges();
            return table;
        }
示例#17
0
        private DataTable GetDataSourceInformationTable(OleDbConnection connection, OleDbConnectionInternal internalConnection){

            // verify that the data source information table is in the data set
            DataTable dataSourceInformationTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.DataSourceInformation];
            if (dataSourceInformationTable == null){
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.DataSourceInformation);
            }

            // copy the table filtering out any rows that don't apply to tho current version of the prrovider
            dataSourceInformationTable = CloneAndFilterCollection(DbMetaDataCollectionNames.DataSourceInformation, null);

            // after filtering there better be just one row
            if (dataSourceInformationTable.Rows.Count != 1){
                throw ADP.IncorrectNumberOfDataSourceInformationRows();
            }
            DataRow dataSourceInformation = dataSourceInformationTable.Rows[0];

            // update the identifier separator
            string catalogSeparatorPattern = internalConnection.GetLiteralInfo(ODB.DBLITERAL_CATALOG_SEPARATOR);
            string schemaSeparatorPattern = internalConnection.GetLiteralInfo(ODB.DBLITERAL_SCHEMA_SEPARATOR);

            if (catalogSeparatorPattern != null) {
                StringBuilder compositeSeparatorPattern = new StringBuilder();
                StringBuilder patternEscaped = new StringBuilder();
                ADP.EscapeSpecialCharacters(catalogSeparatorPattern,patternEscaped);
                compositeSeparatorPattern.Append(patternEscaped.ToString());
                if ((schemaSeparatorPattern != null) && (schemaSeparatorPattern != catalogSeparatorPattern)) {
                    compositeSeparatorPattern.Append("|");
                    patternEscaped.Length = 0;
                    ADP.EscapeSpecialCharacters(schemaSeparatorPattern,patternEscaped);
                    compositeSeparatorPattern.Append(patternEscaped.ToString());
                }
                    dataSourceInformation[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = compositeSeparatorPattern.ToString();
            }
            else if (schemaSeparatorPattern != null){
                StringBuilder patternEscaped = new StringBuilder();
                ADP.EscapeSpecialCharacters(schemaSeparatorPattern, patternEscaped);
                dataSourceInformation[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = patternEscaped.ToString();;
            }

            // update the DataSourceProductName
            object property;
            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo,ODB.DBPROP_DBMSNAME);
            if (property != null) {
                dataSourceInformation[DbMetaDataColumnNames.DataSourceProductName] = (string) property;
            }

            // update the server version strings
            dataSourceInformation[DbMetaDataColumnNames.DataSourceProductVersion] = ServerVersion;
            dataSourceInformation[DbMetaDataColumnNames.DataSourceProductVersionNormalized] = ServerVersionNormalized;


                // values that are the same for all OLE DB Providers. See SQLBU 308529
                dataSourceInformation[DbMetaDataColumnNames.ParameterMarkerFormat] =  "?";
                dataSourceInformation[DbMetaDataColumnNames.ParameterMarkerPattern] =  "\\?";
                dataSourceInformation[DbMetaDataColumnNames.ParameterNameMaxLength] = 0;


            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo,ODB.DBPROP_GROUPBY);
            GroupByBehavior groupByBehavior = GroupByBehavior.Unknown;
            if (property != null) {
                switch ((int)property) {

                    case ODB.DBPROPVAL_GB_CONTAINS_SELECT:
                        groupByBehavior = GroupByBehavior.MustContainAll;
                        break;

                    case ODB.DBPROPVAL_GB_EQUALS_SELECT:
                        groupByBehavior = GroupByBehavior.ExactMatch;
                        break;

                    case ODB.DBPROPVAL_GB_NO_RELATION:
                        groupByBehavior = GroupByBehavior.Unrelated;
                        break;

                    case ODB.DBPROPVAL_GB_NOT_SUPPORTED:
                        groupByBehavior = GroupByBehavior.NotSupported;
                        break;
                }
            }
            dataSourceInformation[DbMetaDataColumnNames.GroupByBehavior] = groupByBehavior;

            SetIdentifierCase(DbMetaDataColumnNames.IdentifierCase,ODB.DBPROP_IDENTIFIERCASE,dataSourceInformation, connection);
            SetIdentifierCase(DbMetaDataColumnNames.QuotedIdentifierCase,ODB.DBPROP_QUOTEDIDENTIFIERCASE,dataSourceInformation, connection);

            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo,ODB.DBPROP_ORDERBYCOLUNSINSELECT);
            if (property != null) {
                dataSourceInformation[DbMetaDataColumnNames.OrderByColumnsInSelect] = (bool) property;
            }

            DataTable infoLiterals = internalConnection.BuildInfoLiterals();
            if (infoLiterals != null){
                DataRow[] tableNameRow = infoLiterals.Select("Literal = " + ODB.DBLITERAL_TABLE_NAME.ToString(CultureInfo.InvariantCulture));
                if (tableNameRow != null) {
                    object invalidCharsObject = tableNameRow[0]["InvalidChars"];
                    if (invalidCharsObject.GetType() == typeof(string)) {
                        string invalidChars = (string)invalidCharsObject;
                        object invalidStartingCharsObject = tableNameRow[0]["InvalidStartingChars"];
                        string invalidStartingChars;
                        if (invalidStartingCharsObject.GetType() == typeof(string)) {
                            invalidStartingChars = (string)invalidStartingCharsObject;
                        }
                        else {
                            invalidStartingChars = invalidChars;
                        }
                        dataSourceInformation[DbMetaDataColumnNames.IdentifierPattern] =
                                                    BuildRegularExpression(invalidChars,invalidStartingChars);
                    }
                }
            }

            // build the QuotedIdentifierPattern using the quote prefix and suffix from the provider and
            // assuming that the quote suffix is escaped via repetion (i.e " becomes "")
            string quotePrefix;
            string quoteSuffix;
            connection.GetLiteralQuotes(ADP.GetSchema, out quotePrefix, out quoteSuffix);

            if (quotePrefix != null){

                // if the quote suffix is null assume that it is the same as the prefix (See OLEDB spec
                // IDBInfo::GetLiteralInfo DBLITERAL_QUOTE_SUFFIX.)
                if (quoteSuffix == null) {
                    quoteSuffix = quotePrefix;
                }

                // only know how to build the parttern if the suffix is 1 character
                // in all other cases just leave the field null
                if (quoteSuffix.Length == 1) {
                    StringBuilder scratchStringBuilder = new StringBuilder();
                    ADP.EscapeSpecialCharacters(quoteSuffix,scratchStringBuilder );
                    string escapedQuoteSuffixString = scratchStringBuilder.ToString();
                    scratchStringBuilder.Length = 0;

                    ADP.EscapeSpecialCharacters(quotePrefix, scratchStringBuilder);
                    scratchStringBuilder.Append("(([^");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append("]|");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append(")*)");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    dataSourceInformation[DbMetaDataColumnNames.QuotedIdentifierPattern] = scratchStringBuilder.ToString();
                }
            }

            dataSourceInformationTable.AcceptChanges();

            return dataSourceInformationTable;
        }
示例#18
0
        private Dictionary <string, OleDbPropertyInfo> GetProviderInfo(string provider)
        {
            Dictionary <string, OleDbPropertyInfo> providerInfo = _propertyInfo;

            if (null == providerInfo)
            {
                providerInfo = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider))
                {
                    Dictionary <string, OleDbPropertyInfo> hash = null;
                    try
                    {
                        StringBuilder builder = new StringBuilder();
                        AppendKeyValuePair(builder, DbConnectionStringKeywords.Provider, provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);

                        // load provider without calling Initialize or CreateDataSource
                        using (OleDbConnectionInternal connection = new OleDbConnectionInternal(constr, (OleDbConnection)null))
                        {
                            // get all the init property information for the provider
                            hash = connection.GetPropertyInfo(new Guid[] { OleDbPropertySetGuid.DBInitAll });
                            foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                            {
                                Keywords          index;
                                OleDbPropertyInfo info = entry.Value;
                                if (!s_keywords.TryGetValue(info._description, out index))
                                {
                                    if ((OleDbPropertySetGuid.DBInit == info._propertySet) &&
                                        ((ODB.DBPROP_INIT_ASYNCH == info._propertyID) ||
                                         (ODB.DBPROP_INIT_HWND == info._propertyID) ||
                                         (ODB.DBPROP_INIT_PROMPT == info._propertyID)))
                                    {
                                        continue; // skip this keyword
                                    }
                                    providerInfo[info._description] = info;
                                }
                            }

                            // what are the unique propertysets?
                            List <Guid> listPropertySets = new List <Guid>();
                            foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                            {
                                OleDbPropertyInfo info = entry.Value;
                                if (!listPropertySets.Contains(info._propertySet))
                                {
                                    listPropertySets.Add(info._propertySet);
                                }
                            }
                            Guid[] arrayPropertySets = new Guid[listPropertySets.Count];
                            listPropertySets.CopyTo(arrayPropertySets, 0);

                            // get all the init property values for the provider
                            using (PropertyIDSet propidset = new PropertyIDSet(arrayPropertySets))
                            {
                                using (IDBPropertiesWrapper idbProperties = connection.IDBProperties())
                                {
                                    OleDbHResult hr;
                                    using (DBPropSet propset = new DBPropSet(idbProperties.Value, propidset, out hr))
                                    {
                                        // OleDbConnectionStringBuilder is ignoring/hiding potential errors of OLEDB provider when reading its properties information
                                        if (0 <= (int)hr)
                                        {
                                            int count = propset.PropertySetCount;
                                            for (int i = 0; i < count; ++i)
                                            {
                                                Guid        propertyset;
                                                tagDBPROP[] props = propset.GetPropertySet(i, out propertyset);

                                                // attach the default property value to the property info
                                                foreach (tagDBPROP prop in props)
                                                {
                                                    foreach (KeyValuePair <string, OleDbPropertyInfo> entry in hash)
                                                    {
                                                        OleDbPropertyInfo info = entry.Value;
                                                        if ((info._propertyID == prop.dwPropertyID) && (info._propertySet == propertyset))
                                                        {
                                                            info._defaultValue = prop.vValue;

                                                            if (null == info._defaultValue)
                                                            {
                                                                if (typeof(string) == info._type)
                                                                {
                                                                    info._defaultValue = "";
                                                                }
                                                                else if (typeof(int) == info._type)
                                                                {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(bool) == info._type)
                                                                {
                                                                    info._defaultValue = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (System.InvalidOperationException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch (System.Data.OleDb.OleDbException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch (System.Security.SecurityException e)
                    {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                }
                _propertyInfo = providerInfo;
            }
            return(providerInfo);
        }
示例#19
0
 internal IOpenRowsetWrapper IOpenRowset(OleDbConnectionInternal connection)
 {
     return(new IOpenRowsetWrapper(ComWrapper()));
 }
示例#20
0
 internal IDBPropertiesWrapper IDBProperties(OleDbConnectionInternal connection)
 {
     return(new IDBPropertiesWrapper(ComWrapper()));
 }
        internal OleDbConnectionInternal(OleDbConnectionString constr, OleDbConnection connection) : base()
        {
            Debug.Assert((null != constr) && !constr.IsEmpty, "empty connectionstring");
            ConnectionString = constr;

            if (constr.PossiblePrompt && !System.Environment.UserInteractive)
            {
                throw ODB.PossiblePromptNotUserInteractive();
            }

            try
            {
                // this is the native DataLinks object which pools the native datasource/session
                OleDbServicesWrapper wrapper = OleDbConnectionInternal.GetObjectPool();
                _datasrcwrp = new DataSourceWrapper();

                // DataLinks wrapper will call IDataInitialize::GetDataSource to create the DataSource
                // uses constr.ActualConnectionString, no InfoMessageEvent checking
                wrapper.GetDataSource(constr, ref _datasrcwrp);
                Debug.Assert(!_datasrcwrp.IsInvalid, "bad DataSource");

                // initialization is delayed because of OleDbConnectionStringBuilder only wants
                // pre-Initialize IDBPropertyInfo & IDBProperties on the data source
                if (null != connection)
                {
                    _sessionwrp = new SessionWrapper();

                    // From the DataSource object, will call IDBInitialize.Initialize & IDBCreateSession.CreateSession
                    // We always need both called so we use a single call for a single DangerousAddRef/DangerousRelease pair.
                    OleDbHResult hr = _datasrcwrp.InitializeAndCreateSession(constr, ref _sessionwrp);

                    // process the HResult here instead of from the SafeHandle because the possibility
                    // of an InfoMessageEvent.
                    if ((0 <= hr) && !_sessionwrp.IsInvalid)
                    { // process infonessage events
                        OleDbConnection.ProcessResults(hr, connection, connection);
                    }
                    else
                    {
                        Exception e = OleDbConnection.ProcessResults(hr, null, null);
                        Debug.Assert(null != e, "CreateSessionError");
                        throw e;
                    }
                    Debug.Assert(!_sessionwrp.IsInvalid, "bad Session");
                }
            }
            catch
            {
                if (null != _sessionwrp)
                {
                    _sessionwrp.Dispose();
                    _sessionwrp = null;
                }
                if (null != _datasrcwrp)
                {
                    _datasrcwrp.Dispose();
                    _datasrcwrp = null;
                }
                throw;
            }
        }
 private Dictionary<string, OleDbPropertyInfo> GetProviderInfo(string provider)
 {
     Dictionary<string, OleDbPropertyInfo> dictionary = this._propertyInfo;
     if (dictionary == null)
     {
         dictionary = new Dictionary<string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
         if (!ADP.IsEmpty(provider))
         {
             Dictionary<string, OleDbPropertyInfo> propertyInfo = null;
             try
             {
                 StringBuilder builder = new StringBuilder();
                 DbConnectionStringBuilder.AppendKeyValuePair(builder, "Provider", provider);
                 OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);
                 constr.CreatePermissionSet().Demand();
                 using (OleDbConnectionInternal internal2 = new OleDbConnectionInternal(constr, null))
                 {
                     Guid[] propertySets = new Guid[] { OleDbPropertySetGuid.DBInitAll };
                     propertyInfo = internal2.GetPropertyInfo(propertySets);
                     foreach (KeyValuePair<string, OleDbPropertyInfo> pair3 in propertyInfo)
                     {
                         Keywords keywords;
                         OleDbPropertyInfo info2 = pair3.Value;
                         if (!_keywords.TryGetValue(info2._description, out keywords) && ((OleDbPropertySetGuid.DBInit != info2._propertySet) || (((200 != info2._propertyID) && (60 != info2._propertyID)) && (0x40 != info2._propertyID))))
                         {
                             dictionary[info2._description] = info2;
                         }
                     }
                     List<Guid> list = new List<Guid>();
                     foreach (KeyValuePair<string, OleDbPropertyInfo> pair2 in propertyInfo)
                     {
                         OleDbPropertyInfo info3 = pair2.Value;
                         if (!list.Contains(info3._propertySet))
                         {
                             list.Add(info3._propertySet);
                         }
                     }
                     Guid[] array = new Guid[list.Count];
                     list.CopyTo(array, 0);
                     using (PropertyIDSet set2 = new PropertyIDSet(array))
                     {
                         using (IDBPropertiesWrapper wrapper = internal2.IDBProperties())
                         {
                             OleDbHResult result;
                             using (DBPropSet set = new DBPropSet(wrapper.Value, set2, out result))
                             {
                                 if (OleDbHResult.S_OK <= result)
                                 {
                                     int propertySetCount = set.PropertySetCount;
                                     for (int i = 0; i < propertySetCount; i++)
                                     {
                                         Guid guid;
                                         foreach (tagDBPROP gdbprop in set.GetPropertySet(i, out guid))
                                         {
                                             foreach (KeyValuePair<string, OleDbPropertyInfo> pair in propertyInfo)
                                             {
                                                 OleDbPropertyInfo info = pair.Value;
                                                 if ((info._propertyID == gdbprop.dwPropertyID) && (info._propertySet == guid))
                                                 {
                                                     info._defaultValue = gdbprop.vValue;
                                                     if (info._defaultValue == null)
                                                     {
                                                         if (typeof(string) == info._type)
                                                         {
                                                             info._defaultValue = "";
                                                         }
                                                         else if (typeof(int) == info._type)
                                                         {
                                                             info._defaultValue = 0;
                                                         }
                                                         else if (typeof(bool) == info._type)
                                                         {
                                                             info._defaultValue = false;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             catch (InvalidOperationException exception3)
             {
                 ADP.TraceExceptionWithoutRethrow(exception3);
             }
             catch (OleDbException exception2)
             {
                 ADP.TraceExceptionWithoutRethrow(exception2);
             }
             catch (SecurityException exception)
             {
                 ADP.TraceExceptionWithoutRethrow(exception);
             }
         }
         this._propertyInfo = dictionary;
     }
     return dictionary;
 }
        private Dictionary<string,OleDbPropertyInfo> GetProviderInfo(string provider) {
            Dictionary<string,OleDbPropertyInfo> providerInfo = _propertyInfo;
            if (null == providerInfo) {
                providerInfo = new Dictionary<string,OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider)) {
                    Dictionary<string,OleDbPropertyInfo> hash = null;
                    try {
                        StringBuilder builder = new StringBuilder();
                        AppendKeyValuePair(builder, DbConnectionStringKeywords.Provider, provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);
                        constr.CreatePermissionSet().Demand();

                        // load provider without calling Initialize or CreateDataSource
                        using(OleDbConnectionInternal connection = new OleDbConnectionInternal(constr, (OleDbConnection)null)) {

                            // get all the init property information for the provider
                            hash = connection.GetPropertyInfo(new Guid[] { OleDbPropertySetGuid.DBInitAll });
                            foreach(KeyValuePair<string,OleDbPropertyInfo> entry in hash) {
                                Keywords index;
                                OleDbPropertyInfo info = entry.Value;
                                if (!_keywords.TryGetValue(info._description, out index)) {
                                    if ((OleDbPropertySetGuid.DBInit == info._propertySet) &&
                                            ((ODB.DBPROP_INIT_ASYNCH == info._propertyID) ||
                                             (ODB.DBPROP_INIT_HWND == info._propertyID) ||
                                             (ODB.DBPROP_INIT_PROMPT == info._propertyID))) {
                                        continue; // skip this keyword
                                    }
                                    providerInfo[info._description] = info;
                                }
                            }

                            // what are the unique propertysets?
                            List<Guid> listPropertySets= new List<Guid>();
                            foreach(KeyValuePair<string,OleDbPropertyInfo> entry in hash) {
                                OleDbPropertyInfo info = entry.Value;
                                if (!listPropertySets.Contains(info._propertySet)) {
                                    listPropertySets.Add(info._propertySet);
                                }
                            }
                            Guid[] arrayPropertySets = new Guid[listPropertySets.Count];
                            listPropertySets.CopyTo(arrayPropertySets, 0);

                            // get all the init property values for the provider
                            using(PropertyIDSet propidset = new PropertyIDSet(arrayPropertySets)) {
                                using(IDBPropertiesWrapper idbProperties = connection.IDBProperties()) {

                                    OleDbHResult hr;
                                    using(DBPropSet propset = new DBPropSet(idbProperties.Value, propidset, out hr)) {
                                        // VSDD 671375: OleDbConnectionStringBuilder is ignoring/hiding potential errors of OLEDB provider when reading its properties information
                                        if (0 <= (int)hr) {
                                            int count = propset.PropertySetCount;
                                            for(int i = 0; i < count; ++i) {
                                                Guid propertyset;
                                                tagDBPROP[] props = propset.GetPropertySet(i, out propertyset);

                                                // attach the default property value to the property info
                                                foreach(tagDBPROP prop in props) {

                                                    foreach(KeyValuePair<string,OleDbPropertyInfo> entry in hash) {
                                                        OleDbPropertyInfo info = entry.Value;
                                                        if ((info._propertyID == prop.dwPropertyID) && (info._propertySet == propertyset)) {
                                                            info._defaultValue = prop.vValue;

                                                            if (null == info._defaultValue) {
                                                                if (typeof(string) == info._type) {
                                                                    info._defaultValue = "";
                                                                }
                                                                else if (typeof(Int32) == info._type) {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(Boolean) == info._type) {
                                                                    info._defaultValue = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch(System.InvalidOperationException e) {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch(System.Data.OleDb.OleDbException e) {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                    catch(System.Security.SecurityException e) {
                        ADP.TraceExceptionWithoutRethrow(e);
                    }
                }
                _propertyInfo = providerInfo;
            }
            return providerInfo;
        }
        protected override DataTable PrepareCollection(string collectionName, string[] restrictions, DbConnection connection)
        {
            OleDbConnection         connection2     = (OleDbConnection)connection;
            OleDbConnectionInternal innerConnection = (OleDbConnectionInternal)connection2.InnerConnection;
            DataTable dataSourceInformationTable    = null;

            if (collectionName == DbMetaDataCollectionNames.DataSourceInformation)
            {
                if (!ADP.IsEmptyArray(restrictions))
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataSourceInformation);
                }
                dataSourceInformationTable = this.GetDataSourceInformationTable(connection2, innerConnection);
            }
            else if (collectionName == DbMetaDataCollectionNames.DataTypes)
            {
                if (!ADP.IsEmptyArray(restrictions))
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.DataTypes);
                }
                dataSourceInformationTable = this.GetDataTypesTable(connection2);
            }
            else if (collectionName == DbMetaDataCollectionNames.ReservedWords)
            {
                if (!ADP.IsEmptyArray(restrictions))
                {
                    throw ADP.TooManyRestrictions(DbMetaDataCollectionNames.ReservedWords);
                }
                dataSourceInformationTable = this.GetReservedWordsTable(innerConnection);
            }
            else
            {
                for (int i = 0; i < this._schemaMapping.Length; i++)
                {
                    if (!(this._schemaMapping[i]._schemaName == collectionName))
                    {
                        continue;
                    }
                    object[] objArray = restrictions;
                    if (restrictions != null)
                    {
                        DataTable table2 = base.CollectionDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections];
                        int       num6   = -1;
                        foreach (DataRow row in table2.Rows)
                        {
                            string str = (string)row[DbMetaDataColumnNames.CollectionName, DataRowVersion.Current];
                            if (collectionName == str)
                            {
                                num6 = (int)row[DbMetaDataColumnNames.NumberOfRestrictions];
                                if (num6 < restrictions.Length)
                                {
                                    throw ADP.TooManyRestrictions(collectionName);
                                }
                                break;
                            }
                        }
                        if (((collectionName == OleDbMetaDataCollectionNames.Indexes) && (restrictions.Length >= 4)) && (restrictions[3] != null))
                        {
                            ushort num4;
                            objArray = new object[restrictions.Length];
                            for (int j = 0; j < restrictions.Length; j++)
                            {
                                objArray[j] = restrictions[j];
                            }
                            if ((restrictions[3] == "DBPROPVAL_IT_BTREE") || (restrictions[3] == "1"))
                            {
                                num4 = 1;
                            }
                            else if ((restrictions[3] == "DBPROPVAL_IT_HASH") || (restrictions[3] == "2"))
                            {
                                num4 = 2;
                            }
                            else if ((restrictions[3] == "DBPROPVAL_IT_CONTENT") || (restrictions[3] == "3"))
                            {
                                num4 = 3;
                            }
                            else
                            {
                                if (!(restrictions[3] == "DBPROPVAL_IT_OTHER") && !(restrictions[3] == "4"))
                                {
                                    throw ADP.InvalidRestrictionValue(collectionName, "TYPE", restrictions[3]);
                                }
                                num4 = 4;
                            }
                            objArray[3] = num4;
                        }
                        if (((collectionName == OleDbMetaDataCollectionNames.Procedures) && (restrictions.Length >= 4)) && (restrictions[3] != null))
                        {
                            short num5;
                            objArray = new object[restrictions.Length];
                            for (int k = 0; k < restrictions.Length; k++)
                            {
                                objArray[k] = restrictions[k];
                            }
                            if ((restrictions[3] == "DB_PT_UNKNOWN") || (restrictions[3] == "1"))
                            {
                                num5 = 1;
                            }
                            else if ((restrictions[3] == "DB_PT_PROCEDURE") || (restrictions[3] == "2"))
                            {
                                num5 = 2;
                            }
                            else
                            {
                                if (!(restrictions[3] == "DB_PT_FUNCTION") && !(restrictions[3] == "3"))
                                {
                                    throw ADP.InvalidRestrictionValue(collectionName, "PROCEDURE_TYPE", restrictions[3]);
                                }
                                num5 = 3;
                            }
                            objArray[3] = num5;
                        }
                    }
                    dataSourceInformationTable = connection2.GetOleDbSchemaTable(this._schemaMapping[i]._schemaRowset, objArray);
                    break;
                }
            }
            if (dataSourceInformationTable == null)
            {
                throw ADP.UnableToBuildCollection(collectionName);
            }
            return(dataSourceInformationTable);
        }
 private DataTable GetReservedWordsTable(OleDbConnectionInternal internalConnection)
 {
     if (base.CollectionDataSet.Tables[DbMetaDataCollectionNames.ReservedWords] == null)
     {
         throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
     }
     DataTable table = base.CloneAndFilterCollection(DbMetaDataCollectionNames.ReservedWords, null);
     DataColumn keyword = table.Columns[DbMetaDataColumnNames.ReservedWord];
     if (keyword == null)
     {
         throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.ReservedWords);
     }
     if (!internalConnection.AddInfoKeywordsToTable(table, keyword))
     {
         throw ODB.IDBInfoNotSupported();
     }
     return table;
 }
        protected override DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
        {
            DbConnectionInternal result = new OleDbConnectionInternal((OleDbConnectionString)options, (OleDbConnection)owningObject);

            return(result);
        }
 internal IDBInfoWrapper IDBInfo(OleDbConnectionInternal connection)
 {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|datasource> %d#, IDBInfo\n", connection.ObjectID);
     return new IDBInfoWrapper(base.ComWrapper());
 }
示例#28
0
 internal IDBInfoWrapper IDBInfo(OleDbConnectionInternal connection)
 {
     return(new IDBInfoWrapper(ComWrapper()));
 }
示例#29
0
 internal IDBPropertiesWrapper IDBProperties(OleDbConnectionInternal connection) {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|datasource> %d#, IDBProperties\n", connection.ObjectID);
     return new IDBPropertiesWrapper(ComWrapper());
 }
示例#30
0
 internal IDBSchemaRowsetWrapper IDBSchemaRowset(OleDbConnectionInternal connection)
 {
     return(new IDBSchemaRowsetWrapper(ComWrapper()));
 }
示例#31
0
 internal IOpenRowsetWrapper IOpenRowset(OleDbConnectionInternal connection) {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|session> %d#, IOpenRowset\n", connection.ObjectID);
     return new IOpenRowsetWrapper(ComWrapper());
 }
示例#32
0
 internal ITransactionJoinWrapper ITransactionJoin(OleDbConnectionInternal connection)
 {
     return(new ITransactionJoinWrapper(ComWrapper()));
 }
示例#33
0
 internal ITransactionJoinWrapper ITransactionJoin(OleDbConnectionInternal connection) {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|session> %d#, ITransactionJoin\n", connection.ObjectID);
     return new ITransactionJoinWrapper(ComWrapper());
 }
示例#34
0
        internal object GetDataSourcePropertyValue(Guid propertySet, int propertyID)
        {
            OleDbConnectionInternal connection = GetOpenConnection();

            return(connection.GetDataSourcePropertyValue(propertySet, propertyID));
        }
示例#35
0
        private DataTable GetDataSourceInformationTable(OleDbConnection connection, OleDbConnectionInternal internalConnection)
        {
            // verify that the data source information table is in the data set
            DataTable dataSourceInformationTable = CollectionDataSet.Tables[DbMetaDataCollectionNames.DataSourceInformation];

            if (dataSourceInformationTable == null)
            {
                throw ADP.UnableToBuildCollection(DbMetaDataCollectionNames.DataSourceInformation);
            }

            // copy the table filtering out any rows that don't apply to tho current version of the prrovider
            dataSourceInformationTable = CloneAndFilterCollection(DbMetaDataCollectionNames.DataSourceInformation, null);

            // after filtering there better be just one row
            if (dataSourceInformationTable.Rows.Count != 1)
            {
                throw ADP.IncorrectNumberOfDataSourceInformationRows();
            }
            DataRow dataSourceInformation = dataSourceInformationTable.Rows[0];

            // update the identifier separator
            string catalogSeparatorPattern = internalConnection.GetLiteralInfo(ODB.DBLITERAL_CATALOG_SEPARATOR);
            string schemaSeparatorPattern  = internalConnection.GetLiteralInfo(ODB.DBLITERAL_SCHEMA_SEPARATOR);

            if (catalogSeparatorPattern != null)
            {
                StringBuilder compositeSeparatorPattern = new StringBuilder();
                StringBuilder patternEscaped            = new StringBuilder();
                ADP.EscapeSpecialCharacters(catalogSeparatorPattern, patternEscaped);
                compositeSeparatorPattern.Append(patternEscaped.ToString());
                if ((schemaSeparatorPattern != null) && (schemaSeparatorPattern != catalogSeparatorPattern))
                {
                    compositeSeparatorPattern.Append("|");
                    patternEscaped.Length = 0;
                    ADP.EscapeSpecialCharacters(schemaSeparatorPattern, patternEscaped);
                    compositeSeparatorPattern.Append(patternEscaped.ToString());
                }
                dataSourceInformation[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = compositeSeparatorPattern.ToString();
            }
            else if (schemaSeparatorPattern != null)
            {
                StringBuilder patternEscaped = new StringBuilder();
                ADP.EscapeSpecialCharacters(schemaSeparatorPattern, patternEscaped);
                dataSourceInformation[DbMetaDataColumnNames.CompositeIdentifierSeparatorPattern] = patternEscaped.ToString();
                ;
            }

            // update the DataSourceProductName
            object property;

            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, ODB.DBPROP_DBMSNAME);
            if (property != null)
            {
                dataSourceInformation[DbMetaDataColumnNames.DataSourceProductName] = (string)property;
            }

            // update the server version strings
            dataSourceInformation[DbMetaDataColumnNames.DataSourceProductVersion]           = ServerVersion;
            dataSourceInformation[DbMetaDataColumnNames.DataSourceProductVersionNormalized] = ServerVersionNormalized;

            // values that are the same for all OLE DB Providers.
            dataSourceInformation[DbMetaDataColumnNames.ParameterMarkerFormat]  = "?";
            dataSourceInformation[DbMetaDataColumnNames.ParameterMarkerPattern] = "\\?";
            dataSourceInformation[DbMetaDataColumnNames.ParameterNameMaxLength] = 0;

            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, ODB.DBPROP_GROUPBY);
            GroupByBehavior groupByBehavior = GroupByBehavior.Unknown;

            if (property != null)
            {
                switch ((int)property)
                {
                case ODB.DBPROPVAL_GB_CONTAINS_SELECT:
                    groupByBehavior = GroupByBehavior.MustContainAll;
                    break;

                case ODB.DBPROPVAL_GB_EQUALS_SELECT:
                    groupByBehavior = GroupByBehavior.ExactMatch;
                    break;

                case ODB.DBPROPVAL_GB_NO_RELATION:
                    groupByBehavior = GroupByBehavior.Unrelated;
                    break;

                case ODB.DBPROPVAL_GB_NOT_SUPPORTED:
                    groupByBehavior = GroupByBehavior.NotSupported;
                    break;
                }
            }
            dataSourceInformation[DbMetaDataColumnNames.GroupByBehavior] = groupByBehavior;

            SetIdentifierCase(DbMetaDataColumnNames.IdentifierCase, ODB.DBPROP_IDENTIFIERCASE, dataSourceInformation, connection);
            SetIdentifierCase(DbMetaDataColumnNames.QuotedIdentifierCase, ODB.DBPROP_QUOTEDIDENTIFIERCASE, dataSourceInformation, connection);

            property = connection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, ODB.DBPROP_ORDERBYCOLUNSINSELECT);
            if (property != null)
            {
                dataSourceInformation[DbMetaDataColumnNames.OrderByColumnsInSelect] = (bool)property;
            }

            DataTable infoLiterals = internalConnection.BuildInfoLiterals();

            if (infoLiterals != null)
            {
                DataRow[] tableNameRow = infoLiterals.Select("Literal = " + ODB.DBLITERAL_TABLE_NAME.ToString(CultureInfo.InvariantCulture));
                if (tableNameRow != null)
                {
                    object invalidCharsObject = tableNameRow[0]["InvalidChars"];
                    if (invalidCharsObject.GetType() == typeof(string))
                    {
                        string invalidChars = (string)invalidCharsObject;
                        object invalidStartingCharsObject = tableNameRow[0]["InvalidStartingChars"];
                        string invalidStartingChars;
                        if (invalidStartingCharsObject.GetType() == typeof(string))
                        {
                            invalidStartingChars = (string)invalidStartingCharsObject;
                        }
                        else
                        {
                            invalidStartingChars = invalidChars;
                        }
                        dataSourceInformation[DbMetaDataColumnNames.IdentifierPattern] =
                            BuildRegularExpression(invalidChars, invalidStartingChars);
                    }
                }
            }

            // build the QuotedIdentifierPattern using the quote prefix and suffix from the provider and
            // assuming that the quote suffix is escaped via repetion (i.e " becomes "")
            string quotePrefix;
            string quoteSuffix;

            connection.GetLiteralQuotes(ADP.GetSchema, out quotePrefix, out quoteSuffix);

            if (quotePrefix != null)
            {
                // if the quote suffix is null assume that it is the same as the prefix (See OLEDB spec
                // IDBInfo::GetLiteralInfo DBLITERAL_QUOTE_SUFFIX.)
                if (quoteSuffix == null)
                {
                    quoteSuffix = quotePrefix;
                }

                // only know how to build the parttern if the suffix is 1 character
                // in all other cases just leave the field null
                if (quoteSuffix.Length == 1)
                {
                    StringBuilder scratchStringBuilder = new StringBuilder();
                    ADP.EscapeSpecialCharacters(quoteSuffix, scratchStringBuilder);
                    string escapedQuoteSuffixString = scratchStringBuilder.ToString();
                    scratchStringBuilder.Length = 0;

                    ADP.EscapeSpecialCharacters(quotePrefix, scratchStringBuilder);
                    scratchStringBuilder.Append("(([^");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append("]|");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    scratchStringBuilder.Append(")*)");
                    scratchStringBuilder.Append(escapedQuoteSuffixString);
                    dataSourceInformation[DbMetaDataColumnNames.QuotedIdentifierPattern] = scratchStringBuilder.ToString();
                }
            }

            dataSourceInformationTable.AcceptChanges();

            return(dataSourceInformationTable);
        }
 internal IDBPropertiesWrapper IDBProperties(OleDbConnectionInternal connection)
 {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|datasource> %d#, IDBProperties\n", connection.ObjectID);
     return(new IDBPropertiesWrapper(ComWrapper()));
 }
        private Dictionary <string, OleDbPropertyInfo> GetProviderInfo(string provider)
        {
            Dictionary <string, OleDbPropertyInfo> dictionary = this._propertyInfo;

            if (dictionary == null)
            {
                dictionary = new Dictionary <string, OleDbPropertyInfo>(StringComparer.OrdinalIgnoreCase);
                if (!ADP.IsEmpty(provider))
                {
                    Dictionary <string, OleDbPropertyInfo> propertyInfo = null;
                    try
                    {
                        StringBuilder builder = new StringBuilder();
                        DbConnectionStringBuilder.AppendKeyValuePair(builder, "Provider", provider);
                        OleDbConnectionString constr = new OleDbConnectionString(builder.ToString(), true);
                        constr.CreatePermissionSet().Demand();
                        using (OleDbConnectionInternal internal2 = new OleDbConnectionInternal(constr, null))
                        {
                            Guid[] propertySets = new Guid[] { OleDbPropertySetGuid.DBInitAll };
                            propertyInfo = internal2.GetPropertyInfo(propertySets);
                            foreach (KeyValuePair <string, OleDbPropertyInfo> pair3 in propertyInfo)
                            {
                                Keywords          keywords;
                                OleDbPropertyInfo info2 = pair3.Value;
                                if (!_keywords.TryGetValue(info2._description, out keywords) && ((OleDbPropertySetGuid.DBInit != info2._propertySet) || (((200 != info2._propertyID) && (60 != info2._propertyID)) && (0x40 != info2._propertyID))))
                                {
                                    dictionary[info2._description] = info2;
                                }
                            }
                            List <Guid> list = new List <Guid>();
                            foreach (KeyValuePair <string, OleDbPropertyInfo> pair2 in propertyInfo)
                            {
                                OleDbPropertyInfo info3 = pair2.Value;
                                if (!list.Contains(info3._propertySet))
                                {
                                    list.Add(info3._propertySet);
                                }
                            }
                            Guid[] array = new Guid[list.Count];
                            list.CopyTo(array, 0);
                            using (PropertyIDSet set2 = new PropertyIDSet(array))
                            {
                                using (IDBPropertiesWrapper wrapper = internal2.IDBProperties())
                                {
                                    OleDbHResult result;
                                    using (DBPropSet set = new DBPropSet(wrapper.Value, set2, out result))
                                    {
                                        if (OleDbHResult.S_OK <= result)
                                        {
                                            int propertySetCount = set.PropertySetCount;
                                            for (int i = 0; i < propertySetCount; i++)
                                            {
                                                Guid guid;
                                                foreach (tagDBPROP gdbprop in set.GetPropertySet(i, out guid))
                                                {
                                                    foreach (KeyValuePair <string, OleDbPropertyInfo> pair in propertyInfo)
                                                    {
                                                        OleDbPropertyInfo info = pair.Value;
                                                        if ((info._propertyID == gdbprop.dwPropertyID) && (info._propertySet == guid))
                                                        {
                                                            info._defaultValue = gdbprop.vValue;
                                                            if (info._defaultValue == null)
                                                            {
                                                                if (typeof(string) == info._type)
                                                                {
                                                                    info._defaultValue = "";
                                                                }
                                                                else if (typeof(int) == info._type)
                                                                {
                                                                    info._defaultValue = 0;
                                                                }
                                                                else if (typeof(bool) == info._type)
                                                                {
                                                                    info._defaultValue = false;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (InvalidOperationException exception3)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception3);
                    }
                    catch (OleDbException exception2)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception2);
                    }
                    catch (SecurityException exception)
                    {
                        ADP.TraceExceptionWithoutRethrow(exception);
                    }
                }
                this._propertyInfo = dictionary;
            }
            return(dictionary);
        }
示例#38
0
 // @devnote: should be multithread safe
 static public void ReleaseObjectPool()
 {
     OleDbConnectionString.ReleaseObjectPool();
     OleDbConnectionInternal.ReleaseObjectPool();
     OleDbConnectionFactory.SingletonInstance.ClearAllPools();
 }
 internal IOpenRowsetWrapper IOpenRowset(OleDbConnectionInternal connection)
 {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|session> %d#, IOpenRowset\n", connection.ObjectID);
     return(new IOpenRowsetWrapper(ComWrapper()));
 }
 internal ITransactionJoinWrapper ITransactionJoin(OleDbConnectionInternal connection)
 {
     Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|session> %d#, ITransactionJoin\n", connection.ObjectID);
     return(new ITransactionJoinWrapper(ComWrapper()));
 }
 override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) {
     DbConnectionInternal result = new OleDbConnectionInternal((OleDbConnectionString)options, (OleDbConnection)owningObject);
     return result;
 }